From c65da3547087080817c2c9219faf6da7a82027cc Mon Sep 17 00:00:00 2001 From: Kerkesni Date: Mon, 10 Feb 2025 14:04:09 +0100 Subject: [PATCH] use healthchecks to wait for containers to be up Issue: BB-496 --- .github/dockerfiles/cloudserver/Dockerfile | 7 +++++ .../config.json} | 0 .github/dockerfiles/e2e/docker-compose.yaml | 24 +++++++++++++--- .github/scripts/wait_for_local_port.bash | 28 ------------------- .github/workflows/tests.yaml | 3 +- 5 files changed, 28 insertions(+), 34 deletions(-) create mode 100644 .github/dockerfiles/cloudserver/Dockerfile rename .github/dockerfiles/{e2e/cloudserver-config.json => cloudserver/config.json} (100%) delete mode 100644 .github/scripts/wait_for_local_port.bash diff --git a/.github/dockerfiles/cloudserver/Dockerfile b/.github/dockerfiles/cloudserver/Dockerfile new file mode 100644 index 000000000..1c706fbb7 --- /dev/null +++ b/.github/dockerfiles/cloudserver/Dockerfile @@ -0,0 +1,7 @@ +ARG CLOUDSERVER_IMAGE=ghcr.io/scality/cloudserver:7.70.47 + +FROM ${CLOUDSERVER_IMAGE} + +ADD ./config.json /conf/config.json + +RUN apt update && apt install -y curl diff --git a/.github/dockerfiles/e2e/cloudserver-config.json b/.github/dockerfiles/cloudserver/config.json similarity index 100% rename from .github/dockerfiles/e2e/cloudserver-config.json rename to .github/dockerfiles/cloudserver/config.json diff --git a/.github/dockerfiles/e2e/docker-compose.yaml b/.github/dockerfiles/e2e/docker-compose.yaml index 80a023b8f..18722ada7 100644 --- a/.github/dockerfiles/e2e/docker-compose.yaml +++ b/.github/dockerfiles/e2e/docker-compose.yaml @@ -7,6 +7,12 @@ services: - 8181 user: 0:0 privileged: true + healthcheck: + test: curl http://localhost:8181 || exit 1 + interval: 10s + timeout: 30s + retries: 12 + start_period: 10s metadata: profiles: ['s3c'] image: ${METADATA_IMAGE} @@ -17,10 +23,16 @@ services: SPROXYD: sproxyd:8181 volumes: - ./metadata-config.json:/mnt/standalone_workdir/config.json:ro + healthcheck: + test: curl http://localhost:9000 || exit 1 + interval: 10s + timeout: 30s + retries: 12 + start_period: 10s cloudserver: profiles: ['s3c'] - image: ${CLOUDSERVER_IMAGE} - network_mode: host + build: + context: ../cloudserver depends_on: - metadata environment: @@ -31,8 +43,12 @@ services: S3_CONFIG_FILE: /conf/config.json REMOTE_MANAGEMENT_DISABLE: 1 command: yarn start - volumes: - - ./cloudserver-config.json:/conf/config.json:ro + healthcheck: + test: curl http://localhost:8000 || exit 1 + interval: 10s + timeout: 30s + retries: 12 + start_period: 10s redis: profiles: ['s3c'] image: ${REDIS_IMAGE} diff --git a/.github/scripts/wait_for_local_port.bash b/.github/scripts/wait_for_local_port.bash deleted file mode 100644 index 2885428a4..000000000 --- a/.github/scripts/wait_for_local_port.bash +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -wait_for_local_port() { - local port=$1 - local timeout=$2 - local count=0 - local ret=1 - echo "waiting for localhost:$port" - while [[ "$ret" -eq "1" && "$count" -lt "$timeout" ]] ; do - nc -z -w 1 localhost $port - ret=$? - if [ ! "$ret" -eq "0" ]; then - echo -n . - sleep 1 - count=$(($count+1)) - fi - done - - echo "" - - if [[ "$count" -eq "$timeout" ]]; then - echo "Server did not start in less than $timeout seconds. Exiting..." - exit 1 - fi - - echo "Server got ready in ~${count} seconds. Starting test now..." -} - -wait_for_local_port $1 $2 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bd7797ac6..03fbb9e32 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -237,8 +237,7 @@ jobs: CLOUDSERVER_IMAGE: ghcr.io/scality/cloudserver:${{ matrix.cloudserver_tag }} run: |- set -e -o pipefail; - docker compose --profile ${{ matrix.profile }} up -d --quiet-pull - bash ../../scripts/wait_for_local_port.bash 8000 120 + docker compose --profile ${{ matrix.profile }} up -d --quiet-pull --wait working-directory: .github/dockerfiles/e2e - name: Create Zookeeper paths for tests with metadata run: |-