#
# Please consult the `Deployment` section in the readme if you want to deploy
# this. You *need* to keep this nginx service, even if you have your own,
# otherwise the static files will not be served correctly! If you do remove
# it, configure yours similarly to what's in config/nginx.conf
# Also take a look at the "Static files" section in the .env file

services:
  web:
    image: wger/server:latest
    container_name: wger_web
    environment:
      - DJANGO_DB_ENGINE=django.db.backends.postgresql
      - DJANGO_DB_DATABASE=wger
      - DJANGO_DB_USER=wger
      - DJANGO_DB_PASSWORD=wger
      - DJANGO_DB_HOST=db
      - DJANGO_DB_PORT=5432
      - DJANGO_PERFORM_MIGRATIONS=True # Perform any new database migrations on startup
      - TZ=America/Moncton
      - CSRF_TRUSTED_ORIGINS=https://wger.shoebottom.ca
      - X_FORWARDED_PROTO_HEADER_SET=True
      - MEDIA_URL=https://wger.shoebottom.ca/media/
      - STATIC_URL=https://wger.shoebottom.ca/static/
      - WGER_INSTANCE=https://wger.de # Wger instance from which to sync exercises, images, etc.
      - ALLOW_REGISTRATION=False
      - ALLOW_GUEST_USERS=False
      - ALLOW_UPLOAD_VIDEOS=False
      - MIN_ACCOUNT_AGE_TO_TRUST=21
      - DOWNLOAD_INGREDIENTS_FROM=WGER
      - USE_CELERY=False
      - AXES_ENABLED=False
      - DJANGO_DEBUG=False
      - WGER_USE_GUNICORN=True
      - EXERCISE_CACHE_TTL=18000 # in seconds - 5*60*60, 5 hours
      - SITE_URL=https://wger.shoebottom.ca
      - ACCESS_TOKEN_LIFETIME=10 # The lifetime duration of the access token, in minutes
      - REFRESH_TOKEN_LIFETIME=24 # The lifetime duration of the refresh token, in hours
      - USE_RECAPTCHA=False
      - DJANGO_CLEAR_STATIC_FIRST=False
      - FROM_EMAIL='wger Workout Manager <wger@shoebottom.com>'
      - DJANGO_CACHE_BACKEND=django_redis.cache.RedisCache
      - DJANGO_CACHE_LOCATION=redis://cache:6379/1
      - DJANGO_CACHE_TIMEOUT=1296000 # in seconds - 60*60*24*15, 15 Days
      - DJANGO_CACHE_CLIENT_CLASS=django_redis.client.DefaultClient
    depends_on:
      db:
        condition: service_healthy
      cache:
        condition: service_healthy
    env_file:
      - ../stack.env
    volumes:
      - /docker/appdata/wger/static:/home/wger/static
      - /docker/appdata/wger/media:/home/wger/media
    expose:
      - 8000
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://localhost:8000
      interval: 10s
      timeout: 5s
      start_period: 300s
      retries: 5
    restart: unless-stopped

  db:
    image: postgres:15-alpine
    container_name: wger_db
    environment:
      - POSTGRES_USER=wger
      - POSTGRES_PASSWORD=wger
      - POSTGRES_DB=wger
    volumes:
      - /docker/appdata/wger/db:/var/lib/postgresql/data/
    expose:
      - 5432
    healthcheck:
      test: pg_isready -U wger
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    restart: unless-stopped

  nginx:
    image: nginx:stable
    container_name: wger_nginx
    depends_on:
      - web
    volumes:
      - /docker/appdata/wger/nginx.conf:/etc/nginx/conf.d/default.conf
      - /docker/appdata/wger/static:/wger/static:ro
      - /docker/appdata/wger/media:/wger/media:ro
    ports:
      - "9002:80"
    healthcheck:
      test: service nginx status
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    restart: unless-stopped

  cache:
    image: redis
    container_name: wger_cache
    expose:
      - 6379
    volumes:
      - /docker/appdata/wger/cache:/data
    healthcheck:
      test: redis-cli ping
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    restart: unless-stopped