Switch to docker compose v2 (plugin) instead of v1 (docker-compose pip package) (#20755)

This commit is contained in:
Mathieu Pillard 2023-05-26 14:05:21 +02:00 коммит произвёл GitHub
Родитель 9b6d7b3bdc
Коммит 3ef358c672
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 50 добавлений и 49 удалений

Просмотреть файл

@ -16,18 +16,18 @@ help_submake:
.PHONY: update_docker .PHONY: update_docker
update_docker: ## update all the docker images update_docker: ## update all the docker images
docker-compose exec --user olympia worker make update_deps docker compose exec --user olympia worker make update_deps
docker-compose exec --user olympia web make update docker compose exec --user olympia web make update
docker-compose restart web docker compose restart web
docker-compose restart worker docker compose restart worker
.PHONY: shell .PHONY: shell
shell: ## connect to a running addons-server docker shell shell: ## connect to a running addons-server docker shell
docker-compose exec --user olympia web bash docker compose exec --user olympia web bash
.PHONY: rootshell .PHONY: rootshell
rootshell: ## connect to a running addons-server docker shell with root user rootshell: ## connect to a running addons-server docker shell with root user
docker-compose exec --user root web bash docker compose exec --user root web bash
.PHONY: create_env_file .PHONY: create_env_file
create_env_file: create_env_file:
@ -39,7 +39,7 @@ initialize_docker: create_env_file
# shared via a volume in docker-compose.yml, this installs deps for both web # shared via a volume in docker-compose.yml, this installs deps for both web
# and worker containers, and does so without requiring the containers to be up. # and worker containers, and does so without requiring the containers to be up.
# We just create dummy empty package.json and package-lock.json in deps/ so # We just create dummy empty package.json and package-lock.json in deps/ so
# that docker-compose doesn't create dummy ones itself, as they would be owned # that docker compose doesn't create dummy ones itself, as they would be owned
# by root. They don't matter: the ones at the root directory are mounted # by root. They don't matter: the ones at the root directory are mounted
# instead. # instead.
touch deps/package.json touch deps/package.json
@ -48,12 +48,12 @@ initialize_docker: create_env_file
# would be uid 9500 regardless of host at this point (this is only fixed when # would be uid 9500 regardless of host at this point (this is only fixed when
# the container is up, through the command defined in docker-compose.yml), # the container is up, through the command defined in docker-compose.yml),
# which is wrong for local development. # which is wrong for local development.
docker-compose run --rm --user ${UID}:${GID} web make update_deps docker compose run --rm --user ${UID}:${GID} web make update_deps
docker-compose up -d docker compose up -d
docker-compose exec --user olympia web make initialize docker compose exec --user olympia web make initialize
%: ## This directs any other recipe (command) to the web container's make. %: ## This directs any other recipe (command) to the web container's make.
docker-compose exec --user olympia web make $(MAKECMDGOALS) ARGS=$(ARGS) docker compose exec --user olympia web make $(MAKECMDGOALS) ARGS=$(ARGS)
# You probably want to put new commands in Makefile-docker, unless they operate # You probably want to put new commands in Makefile-docker, unless they operate
# on multiple containers or are host-os specific. # on multiple containers or are host-os specific.

Просмотреть файл

@ -20,7 +20,7 @@ x-env-mapping: &env
- HISTSIZE=50000 - HISTSIZE=50000
- HISTIGNORE=ls:exit:"cd .." - HISTIGNORE=ls:exit:"cd .."
- HISTCONTROL=erasedups - HISTCONTROL=erasedups
# Note: docker-compose uses the values exported from .env for GID/UID if # Note: docker compose uses the values exported from .env for GID/UID if
# they exist. ./docker/fix_olympia_user.sh uses those variables to fix # they exist. ./docker/fix_olympia_user.sh uses those variables to fix
# the uid/gid of the user to match the host if necessary. # the uid/gid of the user to match the host if necessary.
- UID=${UID:-9500} - UID=${UID:-9500}

Просмотреть файл

@ -4,7 +4,7 @@ Building Docs
To simply build the docs:: To simply build the docs::
docker-compose run web make docs docker compose run web make docs
If you're working on the docs, use ``make loop`` to keep your built pages If you're working on the docs, use ``make loop`` to keep your built pages
up-to-date:: up-to-date::

Просмотреть файл

@ -9,7 +9,7 @@ the vm *after* you have started the VPN connection.
To do this simply stop the containers:: To do this simply stop the containers::
docker-compose stop docker compose stop
Stop the docker-machine vm:: Stop the docker-machine vm::
@ -22,4 +22,4 @@ Then connect to your VPN and restart the docker vm::
and fire up the env containers again:: and fire up the env containers again::
docker-compose up -d docker compose up -d

Просмотреть файл

@ -13,7 +13,7 @@ virtualbox as the driver::
docker-machine create --driver=virtualbox addons-dev docker-machine create --driver=virtualbox addons-dev
Then you can export the variables so that docker-compose can talk to Then you can export the variables so that ``docker compose`` can talk to
the docker service. This command will tell you how to do that:: the docker service. This command will tell you how to do that::
docker-machine env addons-dev docker-machine env addons-dev

Просмотреть файл

@ -10,6 +10,13 @@ development environment.
First you'll need to install Docker_. Please read their docs for First you'll need to install Docker_. Please read their docs for
the installation steps specific to your operating system. the installation steps specific to your operating system.
.. note::
If you're running Linux, make sure the ``compose`` package is installed.
The best way to do this is to follow the `official docker installation docs
<https://docs.docker.com/desktop/install/linux-install/#generic-installation-steps>`_
and use the official docker package repository instead of your distribution's
package.
There are two options for running docker depending on the platform There are two options for running docker depending on the platform
you are running. you are running.
@ -38,12 +45,6 @@ vm here :ref:`creating-the-docker-vm`
Setting up the containers Setting up the containers
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
.. note::
docker-toolbox, docker-for-mac and docker-for-windows will install ``docker-compose``
for you. If you're on Linux and you need it, you can install it manually with::
pip install docker-compose
.. note:: .. note::
On Windows, ensure that Docker Desktop is running as Linux Container. On Windows, ensure that Docker Desktop is running as Linux Container.
You can double-check this by ensuring you see "Switch to Windows containers..." You can double-check this by ensuring you see "Switch to Windows containers..."
@ -67,12 +68,12 @@ on your host machine::
git clone https://github.com/mozilla/addons-server.git git clone https://github.com/mozilla/addons-server.git
cd addons-server cd addons-server
# Download the containers # Download the containers
docker-compose pull # Can take a while depending on your internet bandwidth. docker compose pull # Can take a while depending on your internet bandwidth.
make initialize_docker # Answer yes, and create your superuser when asked. make initialize_docker # Answer yes, and create your superuser when asked.
# On Windows you can substitute `make initialize_docker` by the following commands: # On Windows you can substitute `make initialize_docker` by the following commands:
docker-compose run --rm --user olympia web make update_deps docker compose run --rm --user olympia web make update_deps
docker-compose up -d docker compose up -d
docker-compose exec --user olympia web make initialize docker compose exec --user olympia web make initialize
.. note:: .. note::
@ -81,7 +82,7 @@ on your host machine::
Because the containers need to match the user/group permissions from your Because the containers need to match the user/group permissions from your
host machine, on Mac and Linux machines make sure to run ``make initialize_docker`` host machine, on Mac and Linux machines make sure to run ``make initialize_docker``
once before running ``docker-compose up -d`` for the first time. That will once before running ``docker compose up -d`` for the first time. That will
create a ``.env`` file containing the user and group id the container needs create a ``.env`` file containing the user and group id the container needs
to use to match your host permissions, and ensure dependencies are set up to use to match your host permissions, and ensure dependencies are set up
properly. properly.
@ -90,7 +91,7 @@ on your host machine::
Accessing the web server Accessing the web server
~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
By default our docker-compose config exposes the web-server on port 80 of localhost. By default our ``docker-compose.yml`` config exposes the web-server on port 80 of localhost.
We use ``olympia.test`` as the default hostname to access your container server (e.g. for We use ``olympia.test`` as the default hostname to access your container server (e.g. for
Firefox Accounts). To be able access the development environment using ``http://olympia.test`` Firefox Accounts). To be able access the development environment using ``http://olympia.test``
@ -108,9 +109,9 @@ By default we configure `OLYMPIA_SITE_URL` to point to `http://olympia.test`.
If you choose a different hostname you'll need to set that environment variable If you choose a different hostname you'll need to set that environment variable
and restart the Docker containers:: and restart the Docker containers::
docker-compose stop # only needed if running docker compose stop # only needed if running
export OLYMPIA_SITE_URL=http://[YOUR_HOSTNAME} export OLYMPIA_SITE_URL=http://[YOUR_HOSTNAME}
docker-compose up -d docker compose up -d
Running common commands Running common commands
@ -120,13 +121,13 @@ Run the tests using ``make``, *outside* of the Docker container::
make test make test
# or # or
docker-compose exec --user olympia web pytest src/olympia/ docker compose exec --user olympia web pytest src/olympia/
You can run commands inside the Docker container by ``ssh``\ing into it using:: You can run commands inside the Docker container by ``ssh``\ing into it using::
make shell make shell
# or # or
docker-compose exec --user olympia web bash docker compose exec --user olympia web bash
Then to run the tests inside the Docker container you can run:: Then to run the tests inside the Docker container you can run::
@ -152,15 +153,15 @@ Any time you update addons-server (e.g., by running ``git pull``), you should ma
sure to update your Docker image and database with any new requirements or sure to update your Docker image and database with any new requirements or
migrations:: migrations::
docker-compose stop docker compose stop
docker-compose pull docker compose pull
docker-compose up -d docker compose up -d
make update_docker # Runs database migrations and rebuilds assets. make update_docker # Runs database migrations and rebuilds assets.
# On Windows you can substitute `make update_docker` for the following commands: # On Windows you can substitute `make update_docker` for the following commands:
docker-compose exec --user olympia worker make update_deps docker compose exec --user olympia worker make update_deps
docker-compose exec --user olympia web make update docker compose exec --user olympia web make update
docker-compose restart web docker compose restart web
docker-compose restart worker docker compose restart worker
Gotchas! Gotchas!
~~~~~~~~ ~~~~~~~~
@ -173,10 +174,10 @@ Can't access the web server?
Check you've created a hosts file entry pointing ``olympia.test`` to the Check you've created a hosts file entry pointing ``olympia.test`` to the
relevant IP address. relevant IP address.
If containers are failing to start use ``docker-compose ps`` to check their If containers are failing to start use ``docker compose ps`` to check their
running status. running status.
Another way to find out what's wrong is to run ``docker-compose logs``. Another way to find out what's wrong is to run ``docker compose logs``.
Getting "Programming error [table] doesn't exist"? Getting "Programming error [table] doesn't exist"?
-------------------------------------------------- --------------------------------------------------
@ -188,7 +189,7 @@ the initial setup instructions.
ConnectionError during initialize (elasticsearch container fails to start) ConnectionError during initialize (elasticsearch container fails to start)
--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------
When running ``make initialize_docker`` without a working elasticsearch container, When running ``make initialize_docker`` without a working elasticsearch container,
you'll get a ConnectionError. Check the logs with ``docker-compose logs``. you'll get a ConnectionError. Check the logs with ``docker compose logs``.
If elasticsearch is complaining about ``vm.max_map_count``, run this command on your computer If elasticsearch is complaining about ``vm.max_map_count``, run this command on your computer
or your docker-machine VM: or your docker-machine VM:
@ -200,9 +201,9 @@ This allows processes to allocate more `memory map areas`_.
Connection to elasticsearch timed out (elasticsearch container exits with code 137) Connection to elasticsearch timed out (elasticsearch container exits with code 137)
------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------
``docker-compose up -d`` brings up all containers, but running ``docker compose up -d`` brings up all containers, but running
``make initialize_docker`` causes the elasticsearch container to go down. Running ``make initialize_docker`` causes the elasticsearch container to go down. Running
``docker-compose ps`` shows ``Exited (137)`` against it. ``docker compose ps`` shows ``Exited (137)`` against it.
Update default settings in Docker Desktop - we suggest increasing RAM limit to at least 4 GB in the Resources/Advanced section and click on "Apply and Restart". Update default settings in Docker Desktop - we suggest increasing RAM limit to at least 4 GB in the Resources/Advanced section and click on "Apply and Restart".
@ -241,8 +242,8 @@ For example if you create a file called ``docker-compose-ports.yml``::
Next you would stop and start the containers with the following:: Next you would stop and start the containers with the following::
docker-compose stop # only needed if running docker compose stop # only needed if running
docker-compose -f docker-compose.yml -f docker-compose-ports.yml up -d docker compose -f docker-compose.yml -f docker-compose-ports.yml up -d
Now the container ``nginx`` is listening on 8880 on the host. You can now proxy Now the container ``nginx`` is listening on 8880 on the host. You can now proxy
to the container ``nginx`` from the host ``nginx`` with the following ``nginx`` config:: to the container ``nginx`` from the host ``nginx`` with the following ``nginx`` config::
@ -279,7 +280,7 @@ to start again using::
You'll then need to :ref:`export the variables <creating-the-docker-vm>` again, You'll then need to :ref:`export the variables <creating-the-docker-vm>` again,
and start the services:: and start the services::
docker-compose up -d docker compose up -d
Hacking on the Docker image Hacking on the Docker image
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -290,7 +291,7 @@ such as this to build a new image::
cd addons-server cd addons-server
docker build -t addons/addons-server . docker build -t addons/addons-server .
docker-compose up -d docker compose up -d
After you test your new image, commit to master and the image will be published After you test your new image, commit to master and the image will be published
to Docker Hub for other developers to use after they pull image changes. to Docker Hub for other developers to use after they pull image changes.