lots of docker nitpicks

- changed all service names to not include "forget", let docker-compose
  generate container names

- gave the image a single name

- listen on 127.0.0.1 by default, provide documented override file that
  reverses it

- docs: on that note: don't tell folks to edit docker-compose.yml directly

- docs: explicitly say "run docker-compose build" because docker-compose
  is janky and it can be surprising that downloading a new version of
  the code and running `docker-compose up` doesn't do anything
This commit is contained in:
codl 2022-08-05 00:21:40 +02:00
parent fddcbbe8a0
commit 30b7b24e68
8 changed files with 102 additions and 62 deletions

View File

@ -18,8 +18,5 @@ config.example.py
config.docker.py config.docker.py
forget.example.service forget.example.service
requirements-dev.txt requirements-dev.txt
data
redis
postgres
celery
config.py config.py

8
.gitignore vendored
View File

@ -9,7 +9,7 @@ static/*
.coverage .coverage
.pytest_cache .pytest_cache
# docker stuff data/*
/redis !data/.keep
/postgres
/celery docker-compose.override.yml

View File

@ -29,4 +29,6 @@ FROM deps
COPY --from=layer-cake / ./ COPY --from=layer-cake / ./
RUN doit RUN doit
ENV FLASK_APP=forget.py
VOLUME ["/var/run/celery"] VOLUME ["/var/run/celery"]

View File

@ -120,30 +120,21 @@ server will be started and shut down automatically by the test suite.
This project is also able to be deployed through Docker. This project is also able to be deployed through Docker.
1. Copy `docker-compose.yml` and `config.docker.py` into your preferred 1. Copy `config.docker.py` to `config.py` and add additional configurations to
directory.
1. Rename `config.docker.py` to `config.py` and add additional configurations to
your liking. your liking.
1. By default, the webapp container will be listening on `127.0.0.1:42157`,
which you can point a reverse proxy at.
* If your reverse proxy is in another docker network then you'll need a
`docker-compose.override.yml` file to attach the `www` service to the
right network and not publish any ports. An example override file is
provided. The web app will be listening on `http://forget-www-1:42157`.
1. By default, the `docker-compose.yml` creates relative mounts `./redis`, 1. By default, the `docker-compose.yml` creates relative mounts `./redis`,
`./postgres`, and `./celery` relative to the `docker-compose.yml` location. `./postgres`, and `./celery` relative to the `docker-compose.yml` location.
Feel free to change these if you'd like. An example `docker-compose.override.yml` file is provided that shows how to
change this.
1. Run `docker-compose build` to build the image.
1. Run `docker-compose up` to start or `docker-compose up -d` to start in the 1. Run `docker-compose up` to start or `docker-compose up -d` to start in the
background, and use `docker-compose down` to stop. background, and use `docker-compose down` to stop.
1. If you have a reverse proxy on a Docker network already, simply add the
Docker network details to `docker-compose.yml` and Forget should be available
at `http://forget:42157` in the Docker network. Otherwise, you'll need to add
something like the following to bind the Docker container to a port:
```
services:
forget:
...lots of stuff...
ports:
- "127.0.0.1:42157:42157"
...other stuff...
```
This will bind the container's port `42157` to `127.0.0.1:42157` on your
local machine, which you can then reverse proxy. Make sure to never expose
this publically, as it is http and not secure!
## Contact ## Contact

View File

@ -14,7 +14,7 @@ determines where to connect to the database
see <http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls> for syntax see <http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls> for syntax
only postgresql with psycopg2 driver is officially supported only postgresql with psycopg2 driver is officially supported
""" """
SQLALCHEMY_DATABASE_URI='postgresql+psycopg2://postgres:postgres@forget-db/forget' SQLALCHEMY_DATABASE_URI='postgresql+psycopg2://postgres:postgres@db/forget'
""" """
REDIS URI REDIS URI
@ -22,7 +22,7 @@ REDIS URI
see <https://redis-py.readthedocs.io/en/latest/#redis.ConnectionPool.from_url> see <https://redis-py.readthedocs.io/en/latest/#redis.ConnectionPool.from_url>
for syntax reference for syntax reference
""" """
REDIS_URI='redis://forget-redis' REDIS_URI='redis://redis'
""" """
SERVER ADDRESS SERVER ADDRESS

0
data/.keep Normal file
View File

View File

@ -0,0 +1,33 @@
## uncomment below and change network name to use a reverse proxy on an
## existing network
#networks:
# mycoolreverseproxynetwork:
# external: true
services:
www:
## uncomment below to stop listening on 127.0.0.1
# ports: []
networks:
- forget
## uncomment below and change network name to use a reverse proxy on an
## existing network
# - mycoolreverseproxynetwork
## if you wish to change where postgres, redis, and celery persistent data is
## stored, uncomment below and change the first part of each volume (before the `:`)
# redis:
# volumes:
# - /my/cool/redis/path:/data
# db:
# volumes:
# - /my/cool/postgres/path:/var/lib/postgresql/data
# worker:
# volumes:
# - /my/cool/celery/path:/var/run/celery
# beat:
# volumes:
# - /my/cool/celery/path:/var/run/celery

View File

@ -1,40 +1,48 @@
version: "3"
services: services:
forget: www:
build: build:
context: ./ context: ./
container_name: forget image: codl/forget
pull_policy: build
restart: always restart: always
environment:
- FLASK_APP=forget.py
volumes: volumes:
- ./config.py:/usr/src/app/config.py - type: bind
source: ./config.py
target: /usr/src/app/config.py
read_only: true
depends_on: depends_on:
- forget-redis - redis
- forget-db - db
- forget-worker - worker
- forget-beat - beat
command: bash -c " command: bash -c "
flask db upgrade && flask db upgrade &&
gunicorn -w 9 -t 3600 -b 0.0.0.0:42157 forget:app gunicorn -w 9 -t 3600 -b 0.0.0.0:42157 forget:app
" "
networks:
- forget
expose: expose:
- 42157 - 42157
ports:
- "127.0.0.1:42157:42157"
forget-worker: worker:
build: build:
context: ./ context: ./
container_name: forget-worker image: codl/forget
pull_policy: build
restart: always restart: always
environment:
- FLASK_APP=forget.py
volumes: volumes:
- ./config.py:/usr/src/app/config.py - type: bind
- ./celery/run:/var/run/celery source: ./config.py
target: /usr/src/app/config.py
read_only: true
- ./data/celery/run:/var/run/celery
depends_on: depends_on:
- forget-redis - redis
- forget-db - db
networks:
- forget
command: bash -c " command: bash -c "
mkdir -p /var/run/celery && mkdir -p /var/run/celery &&
chown -R nobody:nogroup /var/run/celery && chown -R nobody:nogroup /var/run/celery &&
@ -45,19 +53,23 @@ services:
--uid=nobody --gid=nogroup --uid=nobody --gid=nogroup
" "
forget-beat: beat:
build: build:
context: ./ context: ./
container_name: forget-beat image: codl/forget
pull_policy: build
restart: always restart: always
environment:
- FLASK_APP=forget.py
volumes: volumes:
- ./config.py:/usr/src/app/config.py - type: bind
- ./celery/run:/var/run/celery source: ./config.py
target: /usr/src/app/config.py
read_only: true
- ./data/celery/run:/var/run/celery
depends_on: depends_on:
- forget-redis - redis
- forget-db - db
networks:
- forget
command: bash -c " command: bash -c "
mkdir -p /var/run/celery && mkdir -p /var/run/celery &&
chown -R nobody:nogroup /var/run/celery && chown -R nobody:nogroup /var/run/celery &&
@ -67,20 +79,25 @@ services:
--uid=nobody --gid=nogroup --uid=nobody --gid=nogroup
" "
forget-redis: redis:
container_name: forget-redis
image: redis:4.0-alpine image: redis:4.0-alpine
restart: always restart: always
volumes: volumes:
- ./redis:/data - ./data/redis:/data
networks:
- forget
forget-db: db:
image: postgres:14-alpine image: postgres:14-alpine
container_name: forget-db
restart: always restart: always
environment: environment:
- POSTGRES_USER=postgres - POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres - POSTGRES_PASSWORD=postgres
- POSTGRES_DB=forget - POSTGRES_DB=forget
volumes: volumes:
- ./postgres:/var/lib/postgresql/data - ./data/postgres:/var/lib/postgresql/data
networks:
- forget
networks:
forget: