From 8de9485b1a30f721aff07fe651e9817b69240659 Mon Sep 17 00:00:00 2001 From: Tejas Mehta Date: Thu, 29 Aug 2024 13:31:50 -0400 Subject: [PATCH] Add gateway health check and run yaml getter in release (#87) --- .github/workflows/create-sdk-on-release.yml | 4 ++++ docker-compose-dev.yml | 5 +++++ docker/wait-for-healthy-gateway.sh | 16 ++++++++++++++++ package.json | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 docker/wait-for-healthy-gateway.sh diff --git a/.github/workflows/create-sdk-on-release.yml b/.github/workflows/create-sdk-on-release.yml index 0ec85e17..d0addf7f 100644 --- a/.github/workflows/create-sdk-on-release.yml +++ b/.github/workflows/create-sdk-on-release.yml @@ -23,6 +23,10 @@ jobs: version: '27.x' - name: Install Dependencies run: yarn install + - name: Start Docker Container + run: yarn run:dev + - name: Get SDK YAML + run: ./docker/wait-for-healthy-gateway.sh - name: Generate SDK run: yarn gen-client-sdk - name: Create Tarball diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 276afc8d..76b9e8f3 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -17,6 +17,11 @@ services: depends_on: auth-service: condition: service_healthy + healthcheck: + test: ['CMD-SHELL', 'curl http://api-gateway:3000/ || exit 1'] + interval: 2s + timeout: 10s + retries: 10 auth-service: build: diff --git a/docker/wait-for-healthy-gateway.sh b/docker/wait-for-healthy-gateway.sh new file mode 100755 index 00000000..727e9e16 --- /dev/null +++ b/docker/wait-for-healthy-gateway.sh @@ -0,0 +1,16 @@ +_wait() { + [[ $# -lt 2 ]] && { + echo "Usage: ${FUNCNAME} "; return 1 + } + timeout=$(($(date +%s) + ${1})) + until [[ $2 ]] || [[ $(date +%s) -gt $timeout ]]; do + : + done + [[ $(date +%s) -gt $timeout ]] && return 1 || return 0 +} + +cmd='[ $(docker ps -f health=healthy -f name=juno-api-gateway -q | wc -l) -eq 1 ]' # script that only checks health +_wait 300 $cmd # maximum time to wait 300s +[[ $? -eq 0 ]] && { + wget $(docker port juno-api-gateway-1 3000)/docs-yaml +} || exit 1 diff --git a/package.json b/package.json index 184b863e..9dc7edcc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "lint": "nx run-many --target=lint --no-cloud", "sync-protos": "node syncJunoProtos.js", "gen-proto": "yarn workspace juno-proto install && yarn workspace juno-proto build && yarn sync-protos", - "gen-client-sdk": "yarn openapi-generator-cli generate -g typescript-node -i ./packages/api-gateway/sdk.yaml -o ./juno-client-sdk", + "gen-client-sdk": "yarn openapi-generator-cli generate -g typescript-node -i ./docs-yaml -o ./juno-client-sdk", "preinstall": "yarn gen-proto", "test:e2e:api-gateway-live": "GATEWAY_COMMAND=test:e2e:watch RUN_MODE=test yarn start:dev:live-all --exit-code-from api-gateway", "test:e2e:auth-service-live": "AUTH_COMMAND=test:e2e:watch RUN_MODE=test yarn start:dev:live-all --exit-code-from auth-service auth-service",