From 0dc8b4556cfc4d9194d291fd5c7e69fdef72fa75 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 14 Feb 2025 12:42:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(docker)=20remove=20usage=20o?= =?UTF-8?q?f=20dockerize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We remove dockerize and use healthcheck on docker compose services instead. --- .github/workflows/impress-frontend.yml | 22 --------- Makefile | 5 -- docker-compose.yml | 68 ++++++++++++++++++++------ 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/.github/workflows/impress-frontend.yml b/.github/workflows/impress-frontend.yml index f869517d..ab7fcce9 100644 --- a/.github/workflows/impress-frontend.yml +++ b/.github/workflows/impress-frontend.yml @@ -88,28 +88,6 @@ jobs: - name: Start Docker services run: make bootstrap FLUSH_ARGS='--no-input' cache= - # Tool to wait for a service to be ready - - name: Install Dockerize - run: | - curl -sSL https://github.com/jwilder/dockerize/releases/download/v0.8.0/dockerize-linux-amd64-v0.8.0.tar.gz | sudo tar -C /usr/local/bin -xzv - - - name: Wait for services to be ready - run: | - printf "Minio check...\n" - dockerize -wait tcp://localhost:9000 -timeout 20s - printf "Keyclock check...\n" - dockerize -wait tcp://localhost:8080 -timeout 20s - printf "Server collaboration check...\n" - dockerize -wait tcp://localhost:4444 -timeout 20s - printf "Ngnix check...\n" - dockerize -wait tcp://localhost:8083 -timeout 20s - printf "DRF check...\n" - dockerize -wait tcp://localhost:8071 -timeout 20s - printf "Postgres Keyclock check...\n" - dockerize -wait tcp://localhost:5433 -timeout 20s - printf "Postgres back check...\n" - dockerize -wait tcp://localhost:15432 -timeout 20s - - name: Run e2e tests run: cd src/frontend/ && yarn e2e:test --project='chromium' diff --git a/Makefile b/Makefile index 0e81087b..99666246 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,6 @@ COMPOSE_EXEC_APP = $(COMPOSE_EXEC) app-dev COMPOSE_RUN = $(COMPOSE) run --rm COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev COMPOSE_RUN_CROWDIN = $(COMPOSE_RUN) crowdin crowdin -WAIT_DB = @$(COMPOSE_RUN) dockerize -wait tcp://$(DB_HOST):$(DB_PORT) -timeout 60s # -- Backend MANAGE = $(COMPOSE_RUN_APP) python manage.py @@ -124,8 +123,6 @@ run: ## start the wsgi (production) and development server @$(COMPOSE) up --force-recreate -d celery-dev @$(COMPOSE) up --force-recreate -d y-provider @$(COMPOSE) up --force-recreate -d nginx - @echo "Wait for postgresql to be up..." - @$(WAIT_DB) .PHONY: run run-with-frontend: ## Start all the containers needed (backend to frontend) @@ -188,14 +185,12 @@ test-back-parallel: ## run all back-end tests in parallel makemigrations: ## run django makemigrations for the impress project. @echo "$(BOLD)Running makemigrations$(RESET)" @$(COMPOSE) up -d postgresql - @$(WAIT_DB) @$(MANAGE) makemigrations .PHONY: makemigrations migrate: ## run django migrations for the impress project. @echo "$(BOLD)Running migrations$(RESET)" @$(COMPOSE) up -d postgresql - @$(WAIT_DB) @$(MANAGE) migrate .PHONY: migrate diff --git a/docker-compose.yml b/docker-compose.yml index e10221b9..7de86335 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,11 @@ services: postgresql: image: postgres:16 + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 1s + timeout: 2s + retries: 300 env_file: - env.d/development/postgresql ports: @@ -15,7 +20,7 @@ services: - "1081:1080" minio: - # user: ${DOCKER_USER:-1000} + user: ${DOCKER_USER:-1000} image: minio/minio environment: - MINIO_ROOT_USER=impress @@ -23,6 +28,11 @@ services: ports: - '9000:9000' - '9001:9001' + healthcheck: + test: ["CMD", "mc", "ready", "local"] + interval: 1s + timeout: 20s + retries: 300 entrypoint: "" command: minio server --console-address :9001 /data volumes: @@ -31,7 +41,9 @@ services: createbuckets: image: minio/mc depends_on: - - minio + minio: + condition: service_healthy + restart: true entrypoint: > sh -c " /usr/bin/mc alias set impress http://minio:9000 impress password && \ @@ -59,10 +71,15 @@ services: - ./src/backend:/app - ./data/static:/data/static depends_on: - - postgresql - - mailcatcher - - redis - - createbuckets + postgresql: + condition: service_healthy + restart: true + mailcatcher: + condition: service_started + redis: + condition: service_started + createbuckets: + condition: service_started celery-dev: user: ${DOCKER_USER:-1000} @@ -93,9 +110,13 @@ services: - env.d/development/common - env.d/development/postgresql depends_on: - - postgresql - - redis - - minio + postgresql: + condition: service_healthy + restart: true + redis: + condition: service_started + minio: + condition: service_started celery: user: ${DOCKER_USER:-1000} @@ -116,9 +137,13 @@ services: volumes: - ./docker/files/etc/nginx/conf.d:/etc/nginx/conf.d:ro depends_on: - - keycloak - - app-dev - - y-provider + app-dev: + condition: service_started + y-provider: + condition: service_started + keycloak: + condition: service_healthy + restart: true frontend-dev: user: "${DOCKER_USER:-1000}" @@ -135,9 +160,6 @@ services: ports: - "3000:3000" - dockerize: - image: jwilder/dockerize - crowdin: image: crowdin/cli:3.16.0 volumes: @@ -169,6 +191,11 @@ services: kc_postgresql: image: postgres:14.3 + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 1s + timeout: 2s + retries: 300 ports: - "5433:5432" env_file: @@ -187,6 +214,13 @@ services: - --hostname-admin-url=http://localhost:8083/ - --hostname-strict=false - --hostname-strict-https=false + - --health-enabled=true + - --metrics-enabled=true + healthcheck: + test: ["CMD", "curl", "--head", "-fsS", "http://localhost:8080/health/ready"] + interval: 1s + timeout: 2s + retries: 300 environment: KEYCLOAK_ADMIN: admin KEYCLOAK_ADMIN_PASSWORD: admin @@ -200,4 +234,6 @@ services: ports: - "8080:8080" depends_on: - - kc_postgresql + kc_postgresql: + condition: service_healthy + restart: true