646: Add error message for webapp startup hang (#647)
This fixes three issues: 1. #644 (build output) 2. #646 (error on startup) 3. automatic env quote handling (related to 2) For the build output we now have: ``` ################################################################# Built host container for /home/telackey/tmp/iglootools-home with tag: cerc/iglootools-home:local To test locally run: docker run -p 3000:3000 cerc/iglootools-home:local ``` For the startup error, it was hung waiting for the "success" message from the next generate output (itself a workaround for a nextjs bug fixed by this PR we submitted: https://github.com/vercel/next.js/pull/58276). I added a timeout which will cause it to wait up to a maximum _n_ seconds before issuing: ``` ERROR: 'npm run cerc_generate' exceeded CERC_MAX_GENERATE_TIME. ``` On the quoting itself, I plan on adding a new run-webapp command, but I realized I had a decent spot to do effect the quote replacement on-the-fly after all when I am already escaping the values for insertion/replacement into JS. The "dequoting" can be disabled with `CERC_RETAIN_ENV_QUOTES=true`.
This commit is contained in:
		
							parent
							
								
									f1f618c57a
								
							
						
					
					
						commit
						9687d84468
					
				@ -39,4 +39,4 @@ EXPOSE 3000
 | 
				
			|||||||
COPY /scripts /scripts
 | 
					COPY /scripts /scripts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Default command sleeps forever so docker doesn't kill it
 | 
					# Default command sleeps forever so docker doesn't kill it
 | 
				
			||||||
CMD ["/scripts/start-serving-app.sh"]
 | 
					ENTRYPOINT ["/scripts/start-serving-app.sh"]
 | 
				
			||||||
 | 
				
			|||||||
@ -11,3 +11,19 @@ CERC_CONTAINER_BUILD_DOCKERFILE=${CERC_CONTAINER_BUILD_DOCKERFILE:-$SCRIPT_DIR/D
 | 
				
			|||||||
CERC_CONTAINER_BUILD_TAG=${CERC_CONTAINER_BUILD_TAG:-cerc/nextjs-base:local}
 | 
					CERC_CONTAINER_BUILD_TAG=${CERC_CONTAINER_BUILD_TAG:-cerc/nextjs-base:local}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
docker build -t $CERC_CONTAINER_BUILD_TAG ${build_command_args} -f $CERC_CONTAINER_BUILD_DOCKERFILE $CERC_CONTAINER_BUILD_WORK_DIR
 | 
					docker build -t $CERC_CONTAINER_BUILD_TAG ${build_command_args} -f $CERC_CONTAINER_BUILD_DOCKERFILE $CERC_CONTAINER_BUILD_WORK_DIR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ $? -eq 0 ] && [ "$CERC_CONTAINER_BUILD_TAG" != "cerc/nextjs-base:local" ]; then
 | 
				
			||||||
 | 
					  cat <<EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#################################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Built host container for $CERC_CONTAINER_BUILD_WORK_DIR with tag:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $CERC_CONTAINER_BUILD_TAG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To test locally run:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    docker run -p 3000:3000 --env-file /path/to/environment.env $CERC_CONTAINER_BUILD_TAG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
				
			|||||||
@ -38,6 +38,9 @@ for f in $(find "$TRG_DIR" -regex ".*.[tj]sx?$" -type f | grep -v 'node_modules'
 | 
				
			|||||||
    orig_name=$(echo -n "${e}" | sed 's/"//g')
 | 
					    orig_name=$(echo -n "${e}" | sed 's/"//g')
 | 
				
			||||||
    cur_name=$(echo -n "${orig_name}" | sed 's/CERC_RUNTIME_ENV_//g')
 | 
					    cur_name=$(echo -n "${orig_name}" | sed 's/CERC_RUNTIME_ENV_//g')
 | 
				
			||||||
    cur_val=$(echo -n "\$${cur_name}" | envsubst)
 | 
					    cur_val=$(echo -n "\$${cur_name}" | envsubst)
 | 
				
			||||||
 | 
					    if [ "$CERC_RETAIN_ENV_QUOTES" != "true" ]; then
 | 
				
			||||||
 | 
					      cur_val=$(sed "s/^[\"']//" <<< "$cur_val" | sed "s/[\"']//")
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
    esc_val=$(sed 's/[&/\]/\\&/g' <<< "$cur_val")
 | 
					    esc_val=$(sed 's/[&/\]/\\&/g' <<< "$cur_val")
 | 
				
			||||||
    echo "$f: $cur_name=$cur_val"
 | 
					    echo "$f: $cur_name=$cur_val"
 | 
				
			||||||
    sed -i "s/$orig_name/$esc_val/g" $f
 | 
					    sed -i "s/$orig_name/$esc_val/g" $f
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,16 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
 | 
				
			|||||||
    set -x
 | 
					    set -x
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 | 
					SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 | 
				
			||||||
 | 
					CERC_MAX_GENERATE_TIME=${CERC_MAX_GENERATE_TIME:-60}
 | 
				
			||||||
 | 
					tpid=""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ctrl_c() {
 | 
				
			||||||
 | 
					    kill $tpid $(ps -ef | grep node | grep next | awk '{print $2}') 2>/dev/null
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					trap ctrl_c INT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CERC_BUILD_TOOL="${CERC_BUILD_TOOL}"
 | 
					CERC_BUILD_TOOL="${CERC_BUILD_TOOL}"
 | 
				
			||||||
if [ -z "$CERC_BUILD_TOOL" ]; then
 | 
					if [ -z "$CERC_BUILD_TOOL" ]; then
 | 
				
			||||||
@ -25,18 +34,32 @@ if [ "$CERC_NEXTJS_SKIP_GENERATE" != "true" ]; then
 | 
				
			|||||||
  jq -e '.scripts.cerc_generate' package.json >/dev/null
 | 
					  jq -e '.scripts.cerc_generate' package.json >/dev/null
 | 
				
			||||||
  if [ $? -eq 0 ]; then
 | 
					  if [ $? -eq 0 ]; then
 | 
				
			||||||
    npm run cerc_generate > gen.out 2>&1 &
 | 
					    npm run cerc_generate > gen.out 2>&1 &
 | 
				
			||||||
    tail -n0 -f gen.out | sed '/rendered as static HTML/ q'
 | 
					    tail -f gen.out &
 | 
				
			||||||
 | 
					    tpid=$!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    count=0
 | 
					    count=0
 | 
				
			||||||
    while [ $count -lt 10 ]; do
 | 
					    generate_done="false"
 | 
				
			||||||
 | 
					    while [ $count -lt $CERC_MAX_GENERATE_TIME ]; do
 | 
				
			||||||
      sleep 1
 | 
					      sleep 1
 | 
				
			||||||
      ps -ef | grep 'node' | grep 'next' | grep 'generate' >/dev/null
 | 
					      grep 'rendered as static HTML' gen.out > /dev/null
 | 
				
			||||||
      if [ $? -ne 0 ]; then 
 | 
					      if [ $? -eq 0 ]; then
 | 
				
			||||||
        break
 | 
					        generate_done="true"
 | 
				
			||||||
 | 
					        ps -ef | grep 'node' | grep 'next' | grep 'generate' >/dev/null
 | 
				
			||||||
 | 
					        if [ $? -ne 0 ]; then
 | 
				
			||||||
 | 
					          break
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        count=$((count + 1))
 | 
					        count=$((count + 1))
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
    done
 | 
					    done
 | 
				
			||||||
    kill $(ps -ef |grep node | grep next | grep generate | awk '{print $2}') 2>/dev/null
 | 
					
 | 
				
			||||||
 | 
					    if [ $generate_done != "true" ]; then
 | 
				
			||||||
 | 
					      echo "ERROR: 'npm run cerc_generate' not successful within CERC_MAX_GENERATE_TIME" 1>&2
 | 
				
			||||||
 | 
					      exit 1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    kill $tpid $(ps -ef | grep node | grep next | grep generate | awk '{print $2}') 2>/dev/null
 | 
				
			||||||
 | 
					    tpid=""
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user