From b616988f7eb0c20c63e578e153069068e91d6e21 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Thu, 15 Jul 2021 17:05:52 +1000 Subject: [PATCH] Fix ci healthcheck --- backend/embed/acme.sh | 5 ++--- .../api_docs/components/HealthObject.json | 16 +++++++------- docker/Dockerfile | 8 ++++--- docker/dev/Dockerfile | 2 +- docker/rootfs/bin/healthcheck.sh | 7 +++++++ scripts/wait-healthy | 21 +++++++++---------- 6 files changed, 33 insertions(+), 26 deletions(-) create mode 100755 docker/rootfs/bin/healthcheck.sh diff --git a/backend/embed/acme.sh b/backend/embed/acme.sh index f0ff098f..2a261ecb 100755 --- a/backend/embed/acme.sh +++ b/backend/embed/acme.sh @@ -1,6 +1,5 @@ -#!/usr/bin/bash - -VER=0.0.0 +#!/usr/bin/env bash +set -euf -o pipefail echo "Given Args: ${*}" echo diff --git a/backend/embed/api_docs/components/HealthObject.json b/backend/embed/api_docs/components/HealthObject.json index c75274a7..c58261a7 100644 --- a/backend/embed/api_docs/components/HealthObject.json +++ b/backend/embed/api_docs/components/HealthObject.json @@ -2,13 +2,7 @@ "type": "object", "description": "HealthObject", "additionalProperties": false, - "required": [ - "version", - "commit", - "healthy", - "setup", - "error_reporting" - ], + "required": ["version", "commit", "healthy", "setup", "error_reporting"], "properties": { "version": { "type": "string", @@ -36,6 +30,12 @@ "type": "boolean", "description": "Will the application send any error reporting?", "example": true + }, + "acme.sh": { + "type": "string", + "description": "Acme.sh version", + "example": "v3.0.0", + "minLength": 1 } } -} \ No newline at end of file +} diff --git a/docker/Dockerfile b/docker/Dockerfile index d016681a..dfe046b5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -35,12 +35,14 @@ RUN mkdir -p /dist \ # Final image #=============== -FROM jc21/nginx-full:github-acme.sh AS final +FROM jc21/nginx-full:github-no-acme AS final COPY --from=gobuild /dist/server /app/bin/server -ENV SUPPRESS_NO_CONFIG_WARNING=1 -ENV S6_FIX_ATTRS_HIDDEN=1 +ENV SUPPRESS_NO_CONFIG_WARNING=1 \ + S6_FIX_ATTRS_HIDDEN=1 \ + CERT_HOME=/data/acme/ + RUN echo "fs.file-max = 65535" > /etc/sysctl.conf # s6 overlay diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 8aa1aa8f..2f0f0cfe 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -1,4 +1,4 @@ -FROM jc21/nginx-full:github-acme.sh-golang +FROM jc21/nginx-full:github-no-acme-golang LABEL maintainer="Jamie Curnow " SHELL ["/bin/bash", "-o", "pipefail", "-c"] diff --git a/docker/rootfs/bin/healthcheck.sh b/docker/rootfs/bin/healthcheck.sh new file mode 100755 index 00000000..63312086 --- /dev/null +++ b/docker/rootfs/bin/healthcheck.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +HEALTHY="$(curl --silent "http://127.0.0.1:3000/api" | jq --raw-output '.result.healthy')" + +echo "Healthy: ${HEALTHY}" +[ "$HEALTHY" = 'true' ] || exit 1 diff --git a/scripts/wait-healthy b/scripts/wait-healthy index b8da5d69..a07da007 100755 --- a/scripts/wait-healthy +++ b/scripts/wait-healthy @@ -5,29 +5,28 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [ "$1" == "" ]; then echo "Waits for a docker container to be healthy." - echo "Usage: $0 docker-container" + echo "Usage: $0 docker-container 30" exit 1 fi SERVICE=$1 -LOOPCOUNT=0 -HEALTHY= LIMIT=${2:-90} echo -e "${BLUE}❯ ${CYAN}Waiting for healthy: ${YELLOW}${SERVICE}${RESET}" -until [ "${HEALTHY}" = "healthy" ]; do - echo -n "." - sleep 1 - HEALTHY="$(docker inspect -f '{{.State.Health.Status}}' $SERVICE)" - ((LOOPCOUNT++)) +is_up() { + docker exec "$SERVICE" /bin/healthcheck.sh +} - if [ "$LOOPCOUNT" == "$LIMIT" ]; then - echo "" - echo "" +i=0 +while ! is_up; do + i=$((i + 1)) + if [ "$i" == "$LIMIT" ]; then echo -e "${BLUE}❯ ${RED}Timed out waiting for healthy${RESET}" + docker logs --tail 50 "$SERVICE" exit 1 fi + sleep 1 done echo ""