Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify compose files by inverting ci into development (docker-compose.yml is the production mode base file) #22878

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/run-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
compose_file:
description: 'The docker-compose file to use'
required: false
default: 'docker-compose.yml:docker-compose.ci.yml'
default: 'docker-compose.yml'
logs:
description: 'Show logs'
required: false
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ jobs:
-
name: Needs Locale Compilation
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: |
make compile_locales
make test_needs_locales_compilation
-
name: Static Assets
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: make test_static_assets
-
name: Internal Routes
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: make test_internal_routes_allowed
-
name: Elastic Search
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: make test_es_tests
-
name: Codestyle
services: web
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: make lint-codestyle
-
name: Manage Check
services: web nginx
compose_file: docker-compose.yml:docker-compose.ci.yml
compose_file: docker-compose.yml
run: make check
data_backup_skip: true
steps:
Expand Down
19 changes: 0 additions & 19 deletions docker-compose.ci.yml

This file was deleted.

21 changes: 21 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
worker:
environment:
- HOST_UID
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

web:
extends:
service: worker
volumes:
- ./package.json:/deps/package.json
- ./package-lock.json:/deps/package-lock.json

nginx:
volumes:
- .:/srv
14 changes: 5 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ x-env-mapping: &env
- HISTIGNORE=ls:exit:"cd .."
- HISTCONTROL=erasedups
- CIRCLECI
- HOST_UID
- HOST_UID=9500
- DEBUG
- DATA_BACKUP_SKIP

Expand Down Expand Up @@ -52,13 +52,7 @@ services:
"celery -A olympia.amo.celery:app worker -E -c 2 --loglevel=INFO",
]
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
- storage:/data/olympia/storage
extra_hosts:
- "olympia.test:127.0.0.1"
restart: on-failure:5
Expand Down Expand Up @@ -98,7 +92,7 @@ services:
image: nginx
volumes:
- ./docker/nginx/addons.conf:/etc/nginx/conf.d/addons.conf
- .:/srv
- storage:/srv/storage
ports:
- "80:80"
networks:
Expand Down Expand Up @@ -188,3 +182,5 @@ volumes:
# External volumes must be manually created/destroyed
name: addons-server_data_mysqld
external: true
storage:

12 changes: 6 additions & 6 deletions docs/topics/development/building_and_running_services.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ The Dockerfile for the **addons-server** project uses a multi-stage build to opt
- **Mounting Dependencies**: The volume `./deps:/deps` mounts the dependencies directory, enabling better caching across builds and providing visibility for debugging directly on the host.

4. **Environment Variables for OLYMPIA_USER**:
- **Development Setup**: The `HOST_UID` environment variable is set to the host user ID, ensuring that the container runs with the correct permissions.
- **CI Setup**: In CI environments, such as defined in `docker-compose.ci.yml`, the user ID is reset to the default 9500, and the Olympia mount is removed. This makes the container a closed system, mimicking production behavior closely.
- **HOST_UID**: The `HOST_UID` environment variable is set to the host user ID, ensuring that the container runs with the correct permissions. By default it is hard
coded to 9500 which is the user id used in production. the `docker-compose.development.yml` file overrides this to allow running the container as the host user.

### Best Practices for the Dockerfile

Expand Down Expand Up @@ -146,7 +146,7 @@ We use docker compose under the hood to orchestrate container both locally and i
The `docker-compose.yml` file defines the services, volumes, and networks required for the project.

Our docker compose project is split into a root [docker-compose.yml](../../../docker-compose.yml) file and additional files for specific environments,
such as [docker-compose.ci.yml](../../../docker-compose.ci.yml) for CI environments.
such as [docker-compose.development.yml](../../../docker-compose.development.yml) for local dev environments.

### Healthchecks

Expand All @@ -155,15 +155,15 @@ The health checks ensure the django wsgi server and celery worker node are runni

### Environment specific compose files

- **Local Development**: The `docker-compose.yml` file is used for local development. It defines services like `web`, `db`, `redis`, and `elasticsearch`.
- **CI Environment**: The `docker-compose.ci.yml` file is used for CI environments. It overrides the HOST_UID as well as removing volumes to make the container more production like.
- **Production**: The `docker-compose.yml` file is used for CI/ production-like environments defines the base services and volumes always required to run the proejct.
- **Development**: The `docker-compose.development.yml` file is used for local development. It defines a volume mount for the local repository to allow live code changes.
- **Private**: This file includes the customs service that is not open source and should therefore not be included by default.
- **Override**: This file allows modifying the default configuration without changing the main `docker-compose.yml` file. This file is larglely obsolete and should not be used.

To mount with a specific set of docker compose files you can add the COMPOSE_FILE argument to make up. This will persist your setting to .env.

```sh
make up COMPOSE_FILE=docker-compose.yml:docker-compose.ci.yml
make up COMPOSE_FILE=docker-compose.yml:docker-compose.development.yml
```

Files should be separated with a colon.
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/development/setup_and_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Though it is **highly recommended to use the make commands** instead of directly
### Docker Compose Files

- **[docker-compose.yml][docker-compose]**: The primary Docker Compose file defining services, networks, and volumes for local and CI environments.
- **[docker-compose.ci.yml][docker-compose-ci]**: Overrides certain configurations for CI-specific needs, ensuring the environment is optimized for automated testing and builds.
- **[docker-compose.development.yml][docker-compose-dev]**: Adds a volume mount for the local repository to allow live code changes.
- **[docker-compose.private.yml][docker-compose-private]**: Runs addons-server with the _customs_ service that is only available to Mozilla employees

Our docker compose files rely on substituted values, all of which are included in our .env file for direct CLI compatibility.
Expand Down Expand Up @@ -317,7 +317,7 @@ and docker-comose.yml file locally.
To fix this error `rm -f .env` to remove your .env and `make up` to restart the containers.

[docker-compose]: ../../../docker-compose.yml
[docker-compose-ci]: ../../../docker-compose.ci.yml
[docker-compose-dev]: ../../../docker-compose.development.yml
[docker-compose-private]: ../../../docker-compose.private.yml
[docker-image-digest]: https://github.com/opencontainers/.github/blob/main/docs/docs/introduction/digests.md
[addons-server-tags]: https://hub.docker.com/r/mozilla/addons-server/tags
Expand Down
Loading