From 205504a6549f07d8c07e6eef4a56f6c796b7ee12 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 | 9 ++++++--- Dockerfile | 2 ++ integration-tests/docker-compose.yml | 7 +++++++ server/package.json | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-vue3.yml b/.github/workflows/docker-vue3.yml index 5231f27f..25e634f8 100644 --- a/.github/workflows/docker-vue3.yml +++ b/.github/workflows/docker-vue3.yml @@ -44,9 +44,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",