diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2ffd3eb..d328fb6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,11 +12,14 @@ concurrency: jobs: docker: - name: 🔨 Docker build + name: 🚢 Docker build runs-on: ubuntu-latest steps: - name: ⬇️ Checkout repo uses: actions/checkout@v4 - - name: ⎔ Docker build - run: ./scripts/build \ No newline at end of file + - name: 🔨 Docker build + run: ./scripts/build + + - name: 🔥 Smoke test + run: ./scripts/smoke-test \ No newline at end of file diff --git a/scripts/common b/scripts/common index 1b7002c..f4db3a2 100644 --- a/scripts/common +++ b/scripts/common @@ -2,12 +2,16 @@ NAME=epikinetics-app ORG=seroanalytics PACKAGE_ROOT="${HERE}/.." -if [ -z "$GITHUB_REF" ]; then - GIT_BRANCH=$(git -C "$PACKAGE_ROOT" symbolic-ref --short HEAD) - GIT_ID=$(git -C "$PACKAGE_ROOT" rev-parse --short=7 HEAD) +if [[ -v "GITHUB_SHA" ]]; then + GIT_ID=${GITHUB_SHA:0:7} else - GIT_BRANCH=$GITHUB_REF - GIT_ID=$(echo $GITHUB_SHA | cut -c1-7) + GIT_ID=$(git rev-parse --short=7 HEAD) +fi + +if [[ -v "BRANCH_NAME" ]]; then + GIT_BRANCH=${BRANCH_NAME} +else + GIT_BRANCH=$(git symbolic-ref --short HEAD) fi DOCKER_COMMIT_TAG=$ORG/$NAME:$GIT_ID diff --git a/scripts/smoke-test b/scripts/smoke-test new file mode 100755 index 0000000..d43f475 --- /dev/null +++ b/scripts/smoke-test @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +HERE=$(realpath "$(dirname $0)") +. $HERE/common + +wait_for() +{ + echo "waiting up to $TIMEOUT seconds for app" + start_ts=$(date +%s) + for i in $(seq $TIMEOUT); do + result="$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:3000 2>/dev/null)" + if [[ $result -eq "200" ]]; then + end_ts=$(date +%s) + echo "App available after $((end_ts - start_ts)) seconds" + break + fi + sleep 1 + echo "...still waiting" + done + return $result +} + +docker run -d -p 3000:3000 $DOCKER_COMMIT_TAG + +# The variable expansion below is 60s by default, or the argument provided +# to this script +TIMEOUT="${1:-60}" +wait_for +RESULT=$? +if [[ $RESULT -ne 200 ]]; then + echo "App did not become available in time" + exit 1 +fi +exit 0 diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..75ada6b --- /dev/null +++ b/scripts/test @@ -0,0 +1,7 @@ +check=$(curl -s -vv -I http://localhost:3000 2>/dev/null | grep "HTTP/2 200") +#echo $check +if [[ -z $check ]] ; then + echo "Cnxn failed" + else + echo "Cnxn successful" +fi