From b8a0aa4b0d4eb76e1bf4334d0ba0de8e8076a255 Mon Sep 17 00:00:00 2001 From: Kevin Meinhardt Date: Mon, 9 Dec 2024 20:12:05 +0100 Subject: [PATCH] Remove race conditions in docker volumes during build/runtime (#22912) * Prevent race conditions in docker volume mounts - Renamed 'worker' service to 'olympia' in docker-compose.ci.yml and docker-compose.yml for clarity. - Introduced a new 'olympia' service with a persistent volume for site static files. - Updated 'worker' service to extend from 'olympia' and adjusted volume mappings accordingly. - Added dependency for 'nginx' service on 'olympia' to ensure proper startup order. - Changed base image for pip development stage in Dockerfile to improve build consistency. This commit enhances the organization of Docker services and improves the overall structure of the Docker setup. --- Dockerfile | 2 +- docker-compose.ci.yml | 12 +++++++++--- docker-compose.yml | 34 ++++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 63e27e9585d3..4d06ab992915 100644 --- a/Dockerfile +++ b/Dockerfile @@ -119,7 +119,7 @@ ${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r require npm ci ${NPM_ARGS} --include=prod EOF -FROM base AS pip_development +FROM pip_production AS pip_development RUN \ # Files required to install pip dependencies diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index fb093e2576e8..42a1b3604cbb 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -1,19 +1,25 @@ services: - worker: + olympia_volumes: environment: - HOST_UID=9500 volumes: + - storage:/data/olympia/storage - /data/olympia + worker: + extends: + service: olympia_volumes + depends_on: + - olympia_volumes web: extends: service: worker - volumes: - - storage:/data/olympia/storage nginx: volumes: - storage:/srv/storage + depends_on: + - olympia_volumes volumes: storage: diff --git a/docker-compose.yml b/docker-compose.yml index 480e955add3e..8579fe183f70 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,9 @@ x-env-mapping: &env - DEBUG - DATA_BACKUP_SKIP +x-site-static-mount: &site-static-mount + data_site_static:/data/olympia/site-static + x-olympia: &olympia <<: *env image: ${DOCKER_TAG:-} @@ -39,6 +42,14 @@ x-olympia: &olympia entrypoint: ["/data/olympia/docker/entrypoint.sh"] services: + olympia_volumes: + <<: *olympia + # We could let this container exit 0, but docker compose --wait + # interprets this as a failure, even with a passing healtcheck. + # so we just sleep indefinitely instead. + command: ["sleep", "infinity"] + volumes: + - *site-static-mount worker: <<: *olympia command: [ @@ -53,12 +64,7 @@ services: ] volumes: - .:/data/olympia - # Don't mount generated files. They only exist in the container - # and would otherwiser be deleted by mounting the cwd volume above - - /data/olympia/static-build - - /data/olympia/site-static - - ./package.json:/deps/package.json - - ./package-lock.json:/deps/package-lock.json + extra_hosts: - "olympia.test:127.0.0.1" restart: on-failure:5 @@ -93,12 +99,22 @@ services: start_period: 120s command: - uwsgi --ini /data/olympia/docker/uwsgi.ini + volumes: + # Don't mount generated files. They only exist in the container + # and would otherwiser be deleted by mounting the cwd volume above + - /data/olympia/static-build + - *site-static-mount + - ./package.json:/deps/package.json + - ./package-lock.json:/deps/package-lock.json + depends_on: + - olympia_volumes nginx: image: nginx volumes: - ./docker/nginx/addons.conf:/etc/nginx/conf.d/addons.conf - .:/srv + - *site-static-mount ports: - "80:80" networks: @@ -106,8 +122,7 @@ services: aliases: - olympia.test depends_on: - - web - - addons-frontend + - olympia_volumes memcached: image: memcached:1.4 @@ -183,6 +198,9 @@ networks: default: volumes: + # Volumes for static files that should not be + # mounted from the host. + data_site_static: data_mysqld: # Keep this value in sync with Makefile-os # External volumes must be manually created/destroyed