Browse Source

Merge pull request #256 from rangerz/start

Add checker for docker-compose up
Mark Shust 4 years ago
parent
commit
843de6ca46
2 changed files with 43 additions and 1 deletions
  1. 2 1
      compose/bin/setup
  2. 41 0
      compose/bin/start

+ 2 - 1
compose/bin/setup

@@ -4,7 +4,8 @@ BASE_URL=${1:-magento2.test}
 bin/stop
 
 docker-compose -f docker-compose.yml up -d
-sleep 1 #Ensure containers are started...
+[ $? != 0 ] && echo "Failed to start Docker services" && exit
+sleep 5 #Ensure containers are started...
 
 echo "Copying all files from host to container..."
 rm -rf src/vendor #Clear for step below

+ 41 - 0
compose/bin/start

@@ -1,4 +1,45 @@
 #!/bin/bash
+function parseYaml {
+  local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
+  sed -ne "s|,$s\]$s\$|]|" \
+      -e ":1;s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s,$s\(.*\)$s\]|\1\2: [\3]\n\1  - \4|;t1" \
+      -e "s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s\]|\1\2:\n\1  - \3|;p" $1 | \
+  sed -ne "s|,$s}$s\$|}|" \
+      -e ":1;s|^\($s\)-$s{$s\(.*\)$s,$s\($w\)$s:$s\(.*\)$s}|\1- {\2}\n\1  \3: \4|;t1" \
+      -e    "s|^\($s\)-$s{$s\(.*\)$s}|\1-\n\1  \2|;p" | \
+  sed -ne "s|^\($s\):|\1|" \
+      -e "s|^\($s\)-$s[\"']\(.*\)[\"']$s\$|\1$fs$fs\2|p" \
+      -e "s|^\($s\)-$s\(.*\)$s\$|\1$fs$fs\2|p" \
+      -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
+      -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" | \
+  awk -F$fs '{
+    indent = length($1)/2;
+    vname[indent] = $2;
+    for (i in vname) {if (i > indent) {delete vname[i]; idx[i]=0}}
+    if (length($2) == 0) {vname[indent] = ++idx[indent] };
+    if (length($3) > 0) {
+      vn=""; for (i=0; i<indent; i++) {vn = (vn)(vname[i])("_")}
+      if ("'$2'_" == vn) {
+         print substr($3 ,0 , match($3,":")-1)
+      }
+    }
+  }'
+}
+
+# Check if volume files exist to avoid creating an empty folder
+VOLUME_LIST=`parseYaml docker-compose.dev.yml services_app_volumes`
+IGNORE_LIST="./src/app/code ./src/m2-hotfixes ./src/patches ./src/var/log ./src/var/report ./src"
+IS_VALID=true
+# Loop through all files missing from the docker-compose.dev.yml file
+for file in $VOLUME_LIST; do
+  if [ ! -e $file ] && [[ ! " $IGNORE_LIST " =~ " $file " ]]; then
+    echo "$file: No such file or directory"
+    IS_VALID=false
+  fi
+done
+# Wait to exit until all missing files have been outputted to the user
+[ $IS_VALID = false ] && echo "Failed to start docker for missing volume files" && exit
+
 docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans
 
 ## Blackfire support