version: '3.4'
services:
  filebrowser:
    image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/filebrowser
    ports:
      - 5000:80
    environment:
      - AUTH_BACKEND_URL=https://api.sika.sik.party/jwt_nginx
      - AUTH_LOGIN_URL=https://sika.sik.party/admin/login
    volumes:
      - /home/sik/production/files/static:/srv
      - /home/sik/production/filebrowser.db:/filebrowser.db

  db:
    image: postgres:12
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure

    environment:
      - POSTGRES_USER_FILE=/run/secrets/DJANGO_DB_USER
      - POSTGRES_PASSWORD_FILE=/run/secrets/DJANGO_DB_PASSWD
    ports:
      - 5432:5432
    volumes:
      - dbdata:/var/lib/postgresql/data
    secrets:
      - DJANGO_DB_USER
      - DJANGO_DB_PASSWD

  backend:
    image: registry.gitlab.com/sahkoinsinoorikilta/vtmk/web2.0-backend:latest
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
      update_config:
        order: start-first
    depends_on:
      - db
    ports:
      - 8000:8000
    volumes:
      - type: bind
        source: /home/sik/production/files/static/.hidden/django/media
        target: /app/media
      - type: bind
        source: /home/sik/production/files/static/.hidden/django/static
        target: /app/static
      - type: bind
        source: /home/sik/production/files/static/.hidden/django/collected_static
        target: /app/collected_static

    environment:
      - SECRET_KEY_FILE=/run/secrets/DJANGO_SECRET_KEY
      - TG_BOT_TOKEN_FILE=/run/secrets/DJANGO_TG_BOT_TOKEN
      - EMAIL_PASSWD_FILE=/run/secrets/DJANGO_EMAIL_PASSWD
      - DB_USER_FILE=/run/secrets/DJANGO_DB_USER
      - DB_PASSWD_FILE=/run/secrets/DJANGO_DB_PASSWD
      - DB_HOST=db
      - DB_PORT=5432

    secrets:
      - DJANGO_SECRET_KEY
      - DJANGO_TG_BOT_TOKEN
      - DJANGO_EMAIL_PASSWD
      - DJANGO_DB_USER
      - DJANGO_DB_PASSWD
secrets:
  DJANGO_SECRET_KEY:
    external: true
  DJANGO_TG_BOT_TOKEN:
    external: true
  DJANGO_EMAIL_PASSWD:
    external: true
  DJANGO_DB_NAME:
    external: true
  DJANGO_DB_USER:
    external: true
  DJANGO_DB_PASSWD:
    external: true

volumes:
  dbdata:
