From 1a12e6abea32b12ad88f55e58ae77734dde8519f Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Tue, 23 Jan 2024 03:27:01 +0100 Subject: [PATCH] Add healthcheck to docker image and wait for it before running integration tests --- .github/workflows/docker-vue3.yml | 13 ++++++++++--- Dockerfile | 2 ++ integration-tests/docker-compose.yml | 7 +++++++ server/package.json | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-vue3.yml b/.github/workflows/docker-vue3.yml index 5231f27f..b4d02274 100644 --- a/.github/workflows/docker-vue3.yml +++ b/.github/workflows/docker-vue3.yml @@ -32,6 +32,10 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Start integration test components in background + run: docker compose -f ./integration-tests/docker-compose.yml up -d --quiet-pull mysql postgres & + - name: Build docker image uses: docker/build-push-action@v5 @@ -44,9 +48,12 @@ jobs: - name: Start integration test components - uses: isbang/compose-action@v1.5.1 - with: - compose-file: ./integration-tests/docker-compose.yml + run: | + if ! docker compose -f ./integration-tests/docker-compose.yml up --wait; then + status="$?" + docker compose -f ./integration-tests/docker-compose.yml logs + exit "$status" + fi - name: Run integration tests diff --git a/Dockerfile b/Dockerfile index 4857f6fa..3f96b2b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,8 @@ MAINTAINER Candid Dauth CMD yarn run prod-server EXPOSE 8080 ENV CACHE_DIR=/opt/facilmap/cache +HEALTHCHECK --start-period=60s --start-interval=3s --timeout=5s --retries=1 \ + CMD wget -O/dev/null 'http://127.0.0.1:8080/socket.io/?EIO=4&transport=polling' || exit 1 RUN apk add --no-cache yarn diff --git a/integration-tests/docker-compose.yml b/integration-tests/docker-compose.yml index 2aaa4f46..6d9cbeae 100644 --- a/integration-tests/docker-compose.yml +++ b/integration-tests/docker-compose.yml @@ -3,6 +3,9 @@ services: image: facilmap-ci links: - mysql + depends_on: + mysql: + condition: service_healthy ports: - "8080:8080" environment: @@ -19,6 +22,8 @@ services: MYSQL_USER: facilmap MYSQL_PASSWORD: facilmap MYSQL_RANDOM_ROOT_PASSWORD: "true" + healthcheck: + test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD facilmap-postgres: @@ -40,3 +45,5 @@ services: POSTGRES_USER: facilmap POSTGRES_PASSWORD: facilmap POSTGRES_DB: facilmap + healthcheck: + test: pg_isready -d $$POSTGRES_DB diff --git a/server/package.json b/server/package.json index 6d8a4c62..1d221323 100644 --- a/server/package.json +++ b/server/package.json @@ -59,6 +59,7 @@ "mysql2": "^3.6.5", "node-cron": "^3.0.3", "p-throttle": "^6.1.0", + "pg": "^8.11.3", "sequelize": "^6.35.2", "socket.io": "^4.7.2", "string-similarity": "^4.0.4", @@ -79,7 +80,6 @@ "@types/string-similarity": "^4.0.2", "cpy-cli": "^5.0.0", "debug": "^4.3.4", - "pg": "^8.11.3", "rimraf": "^5.0.5", "tsx": "^4.7.0", "typescript": "^5.3.3",