diff --git a/.dockerignore b/.dockerignore index 788d930..ea07a93 100644 --- a/.dockerignore +++ b/.dockerignore @@ -18,8 +18,5 @@ config.example.py config.docker.py forget.example.service requirements-dev.txt - -redis -postgres -celery +data config.py diff --git a/.gitignore b/.gitignore index 5145303..25346dd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ static/* .coverage .pytest_cache -# docker stuff -/redis -/postgres -/celery +data/* +!data/.keep + +docker-compose.override.yml diff --git a/Dockerfile b/Dockerfile index 365b87a..38e6515 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,4 +29,6 @@ FROM deps COPY --from=layer-cake / ./ RUN doit +ENV FLASK_APP=forget.py + VOLUME ["/var/run/celery"] diff --git a/README.markdown b/README.markdown index aecd5c7..7c93a42 100644 --- a/README.markdown +++ b/README.markdown @@ -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. -1. Copy `docker-compose.yml` and `config.docker.py` into your preferred - directory. -1. Rename `config.docker.py` to `config.py` and add additional configurations to +1. Copy `config.docker.py` to `config.py` and add additional configurations to 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`, `./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 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 diff --git a/config.docker.py b/config.docker.py index ec241c0..a6ce111 100644 --- a/config.docker.py +++ b/config.docker.py @@ -14,7 +14,7 @@ determines where to connect to the database see for syntax 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 @@ -22,7 +22,7 @@ REDIS URI see for syntax reference """ -REDIS_URI='redis://forget-redis' +REDIS_URI='redis://redis' """ SERVER ADDRESS diff --git a/data/.keep b/data/.keep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml new file mode 100644 index 0000000..2863aaa --- /dev/null +++ b/docker-compose.override.example.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 4883b63..ba5e325 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,40 +1,48 @@ -version: "3" - services: - forget: + www: build: context: ./ - container_name: forget + image: codl/forget + pull_policy: build restart: always - environment: - - FLASK_APP=forget.py volumes: - - ./config.py:/usr/src/app/config.py + - type: bind + source: ./config.py + target: /usr/src/app/config.py + read_only: true depends_on: - - forget-redis - - forget-db - - forget-worker - - forget-beat + - redis + - db + - worker + - beat command: bash -c " flask db upgrade && gunicorn -w 9 -t 3600 -b 0.0.0.0:42157 forget:app " + networks: + - forget expose: - 42157 + ports: + - "127.0.0.1:42157:42157" - forget-worker: + worker: build: context: ./ - container_name: forget-worker + image: codl/forget + pull_policy: build restart: always - environment: - - FLASK_APP=forget.py volumes: - - ./config.py:/usr/src/app/config.py - - ./celery/run:/var/run/celery + - type: bind + source: ./config.py + target: /usr/src/app/config.py + read_only: true + - ./data/celery/run:/var/run/celery depends_on: - - forget-redis - - forget-db + - redis + - db + networks: + - forget command: bash -c " mkdir -p /var/run/celery && chown -R nobody:nogroup /var/run/celery && @@ -45,19 +53,23 @@ services: --uid=nobody --gid=nogroup " - forget-beat: + beat: build: context: ./ - container_name: forget-beat + image: codl/forget + pull_policy: build restart: always - environment: - - FLASK_APP=forget.py volumes: - - ./config.py:/usr/src/app/config.py - - ./celery/run:/var/run/celery + - type: bind + source: ./config.py + target: /usr/src/app/config.py + read_only: true + - ./data/celery/run:/var/run/celery depends_on: - - forget-redis - - forget-db + - redis + - db + networks: + - forget command: bash -c " mkdir -p /var/run/celery && chown -R nobody:nogroup /var/run/celery && @@ -67,20 +79,25 @@ services: --uid=nobody --gid=nogroup " - forget-redis: - container_name: forget-redis + redis: image: redis:4.0-alpine restart: always volumes: - - ./redis:/data + - ./data/redis:/data + networks: + - forget - forget-db: + db: image: postgres:14-alpine - container_name: forget-db restart: always environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=forget volumes: - - ./postgres:/var/lib/postgresql/data + - ./data/postgres:/var/lib/postgresql/data + networks: + - forget + +networks: + forget: