services:
  www:
    build:
      context: ./
    image: ghcr.io/codl/forget
    pull_policy: missing
    restart: always
    volumes:
      - type: bind
        source: ./config.py
        target: /usr/src/app/config.py
        read_only: true
    depends_on:
      - 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"

  worker:
    build:
      context: ./
    image: ghcr.io/codl/forget
    pull_policy: missing
    restart: always
    volumes:
      - type: bind
        source: ./config.py
        target: /usr/src/app/config.py
        read_only: true
      - ./data/celery/run:/var/run/celery
    depends_on:
      - redis
      - db
    networks:
      - forget
    command: bash -c "
        mkdir -p /var/run/celery &&
        chown -R nobody:nogroup /var/run/celery &&
        exec celery --app=tasks worker
                    --loglevel=INFO
                    --statedb=/var/run/celery/worker.state
                    --hostname=worker
                    --uid=nobody --gid=nogroup
      "

  beat:
    build:
      context: ./
    image: ghcr.io/codl/forget
    pull_policy: missing
    restart: always
    volumes:
      - type: bind
        source: ./config.py
        target: /usr/src/app/config.py
        read_only: true
      - ./data/celery/run:/var/run/celery
    depends_on:
      - redis
      - db
    networks:
      - forget
    command: bash -c "
        mkdir -p /var/run/celery &&
        chown -R nobody:nogroup /var/run/celery &&
        exec celery --app=tasks beat
                    --loglevel=INFO
                    --schedule=/var/run/celery/schedule
                    --uid=nobody --gid=nogroup
      "

  redis:
    image: redis:4.0-alpine
    restart: always
    volumes:
      - ./data/redis:/data
    networks:
      - forget

  db:
    image: postgres:14-alpine
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=forget
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    networks:
      - forget

networks:
  forget:
