Skip to content

Commit

Permalink
Remove race conditions in docker volumes during build/runtime (#22912)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
KevinMind authored Dec 9, 2024
1 parent 1be011d commit b8a0aa4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -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:
34 changes: 26 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:-}
Expand All @@ -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: [
Expand All @@ -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
Expand Down Expand Up @@ -93,21 +99,30 @@ 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:
default:
aliases:
- olympia.test
depends_on:
- web
- addons-frontend
- olympia_volumes

memcached:
image: memcached:1.4
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8a0aa4

Please sign in to comment.