-
Notifications
You must be signed in to change notification settings - Fork 1
Docker
The Flask project is easiest run within docker and very easiest with docker-compose
, as described in the Quick Start section and the docker installation guide.
Most important is that the docker-compose.yml
is not altered unless you know what you're doing. This might seem strange and comes from the fact that the app spins up containers to generate the routing graphs in-code. That makes supporting host-native installations as well as docker installations pretty painful.
The default environment file is ./.docker_env
which is referenced in the docker-compose.yml
of this project. It already comes with a preconfigured set of variables, but can be altered/extended as you like.
Generally, the same list applies here as in the general Configuration list. The only important thing for docker is that the database hosts are named the exact same as the corresponding service in docker-compose.yml
.
Two notable exceptions are:
-
COMPOSE_PROJECT_NAME
: determines the internaldocker-compose
project name (usually defaults to the project's parent directory name). This is specified in.env
and is important fordocker-compose
to generate a docker volume with the correct name (s. below). -
DATA_DIR
: needs to be set by both, the.env
and.docker_env
files. The.env
file will telldocker-compose
whatDATA_DIR
maps to when creating the docker volume (see below) and the.docker_env
file will configure the containers.
All containers need access to the ./.docker_env
environment file.
The container running the app only needs one volume which maps the host's DATA_DIR
directory to the container's /app/data
directory.
However, that volume needs to have the name routing-packager_packages
because this volume will also need to be fetched by the app in-code. It's autogenerated by docker-compose
from the COMPOSE_PROJECT_NAME
and the volume name in docker-compose.yml
and mapped to the DATA_DIR
directory found in .env
.
If that is failing for some reason, you can always generate the volume manually:
docker volume create routing-packager_packages \
--driver local \
--opt type=none \
--opt device=/my/absolute/path
--opt o=bind
You'll also notice that the containers running this image map the /var/run/docker.sock
socket to the container's docker socket. This is important to be able to use docker-in-docker.
The worker container running the graph generation and graph updates, needs the same volume(s) mapped as the app
container.
Additionally, it needs access to the .docker_env
file within the container and must map to /app/.env
. The reason is, that the worker container will fire up a flask process to update the graph packages and flask will only look .flaskenv
and .env
files. When you change .docker_env
variables the changes will be propagated to the container only if it's mapped from the host into the container.
This project needs 2 containers from this image:
-
app
: runs the HTTP API, i.e. Flask app. Also is responsible for updating the OSM PBF files withcron
. -
worker
: runs the RQ worker instance, which works off jobs from the queue. Also is responsible for updating the graph packages withcron
.
The ENTRYPOINT
for the image is ./docker-entrypoint.sh
and the CMD
can be:
-
app
(default): runs the Flask app -
worker
: runs the RQ worker instance