addons-server icon indicating copy to clipboard operation
addons-server copied to clipboard

Use docker compose for building and running container (local and CI) (github action and circleCI)

Open KevinMind opened this issue 9 months ago • 0 comments

Relates to: https://mozilla-hub.atlassian.net/browse/ADDSRV-720 Partially fulfills: https://github.com/mozilla/addons-server/pull/22182

Description

This PR aligns the way we build and run our docker image/container in local and CI environments. This reduces the amount of configuration needed and streamlines execution of CI.

This is primarily achieved through using buildx bake to build the docker image, allowing much of our build configuration to be expressed in a docker-compose.yml file.

Secondly, we are now executing our run commands in CI using docker compose, simplifying the run config (same reasons as above) and ensuring we run locally and in CI the same way.

Context

This PR enables follow up PRs to expand on docker compose in CI allowing us to run dependent services and expand coverage with tests etc.

To allow environment specific execution of a particular version, the docker version is now expressed via an environment variable, instead of hard coded to latest.

DOCKER_VERSION

Local dev

The default values for these are correct for running a local build of the image

mozilla/addons-server:local

This build is now heavily cached and arguably faster and more bandwidth efficient over time than downloading the image periodically.

It is also infinitely more reliable in determine if your local code will actually run in CI or production because you develop with a locally built image.

CI

Now in CI we follow the same workflow for both building and running the image. we can specify the DOCKER_VERSION to build and run the image in CI allowing tight control over the specific version we are testing (pr-<PR_NUMBER>)

Using docker compose to run the image is both necessary for future migration of our CI to github action but also convenient now so we can infer the image tag via .env already.

Testing

You can test these changes locally and in CI.

Local

Build the image

make build_docker_image

Build the image with a custom tag

make build_docker_image DOCKER_VERSION=banana

CI

Current workflows are using the new approach so green means good.

KevinMind avatar May 03 '24 10:05 KevinMind