Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: move initial setup into docker startup to simplify deployment #2467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

osresearch
Copy link
Contributor

This patch makes it easier to perform non-development installations with docker-compose by performing the initial setup in the web container on first startup (while the celery and flower containers wait for it to complete).

The production docker-compose.yml also needs an update to pull from an official image (I'm testing it with my OIDC patches in #2464 here):

version: '3'

services:
  nginx:
    image: nginx:latest
    restart: unless-stopped
    ports:
      - "1333:80"
    depends_on:
      - web
    networks:
      - main
    volumes:
      - ./nginx:/etc/nginx/conf.d:ro
      - ./data/static_volume:/app/static:ro
      - ./data/media_volume:/app/images:ro
      - ./data/cache:/cache

  db:
    image: postgres
    env_file: .env
    volumes:
      - ./data/pgdata:/var/lib/postgresql/data
    networks:
      - main

  redis_activity:
    image: redis
    command: redis-server --requirepass ${REDIS_ACTIVITY_PASSWORD} --appendonly yes --port ${REDIS_ACTIVITY_PORT}
    volumes:
      - ./redis.conf:/etc/redis/redis.conf
      - ./data/redis_activity_data:/data
    env_file: .env
    networks:
      - main
    restart: on-failure

  redis_broker:
    image: redis
    command: redis-server --requirepass ${REDIS_BROKER_PASSWORD} --appendonly yes --port ${REDIS_BROKER_PORT}
    volumes:
      - ./redis.conf:/etc/redis/redis.conf
      - ./data/redis_broker_data:/data
    env_file: .env
    networks:
      - main
    restart: on-failure

  web:
    image: osresearch/bookwyrm:oidc
    command: python manage.py runserver 0.0.0.0:8000
    env_file: .env
    volumes:
      - ./data/static_volume:/app/static
      - ./data/media_volume:/app/images
    environment:
      - DB_INIT=True
    depends_on:
      - db
      - celery_worker
      - redis_activity
    networks:
      - main
    ports:
      - "8000"

  celery_worker:
    image: osresearch/bookwyrm:oidc
    command: celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority
    env_file: .env
    volumes:
      - ./data/static_volume:/app/static
      - ./data/media_volume:/app/images
    depends_on:
      - db
      - redis_broker
    restart: on-failure
    networks:
      - main

  celery_beat:
    image: osresearch/bookwyrm:oidc
    command: celery -A celerywyrm beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
    env_file: .env
    volumes:
      - ./data/static_volume:/app/static
      - ./data/media_volume:/app/images
    depends_on:
      - celery_worker
    restart: on-failure
    networks:
      - main

  flower:
    image: osresearch/bookwyrm:oidc
    command: celery -A celerywyrm flower --basic_auth=${FLOWER_USER}:${FLOWER_PASSWORD}
    env_file: .env
    ports:
      - ${FLOWER_PORT}:${FLOWER_PORT}
    volumes:
      - ./data/static_volume:/app/static
      - ./data/media_volume:/app/images
    depends_on:
      - db
      - redis_broker
    restart: on-failure
    networks:
      - main

  dev-tools:
    build: dev-tools
    env_file: .env
    volumes:
      - .:/app

networks:
  main:

@osresearch
Copy link
Contributor Author

An example docker-compose deployment as part of the SSO v.st environment: https://git.v.st/vst/env/commit/b627e976871a93ed490c70695a54d4d7d5e99fdb

@mouse-reeve
Copy link
Member

Thank you for these PRs! I should be able to review them tomorrow or early next week

@mouse-reeve
Copy link
Member

I played around with this a little and wasn't really sure how to use it and get the entrypoint to run the setup scrip -- can you step me through how the install process works differently with this change? I appreciate your patience, I have like two braincells right now due to life business

@osresearch
Copy link
Contributor Author

The idea is that a non-developer admin shouldn't need to invoke the setup script -- the web container detects that database init has not been done on first launch, so it runs all of the migrations and collects the static files, etc. The other containers wait for the .dbinit_done file to exist before they try to startup as well.

If that didn't happen when you ran docker-compose up with the docker-compose.yml file above, then I must have broken something...

@mouse-reeve
Copy link
Member

mouse-reeve commented Dec 19, 2022

Ah, I think the piece I was missing was how to change the docker-compose file. Is that something you can include in the PR (minus the oidc changes)?

@hughrun
Copy link
Contributor

hughrun commented Jan 26, 2023

@osresearch This is a nice addition. If you're happy to add the updated docker-compose.yml file as outlined above to be part of this PR, we should be able to pull it in.

Copy link
Contributor

@dato dato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment

if [ -z "$DB_INIT" ]; then
while [ ! -r "$CANARY" ]; do
info "**** Waiting for database and migrations to finish"
sleep 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would:

Suggested change
sleep 10
sleep 0.5

since the test is very cheap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants