services:
  server:
    build:
      context: .
      dockerfile: docker/server/server.dockerfile
    environment:
      - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST:-db}:${POSTGRES_PORT:-5432}/tralalere
      - DEBUG=${DEBUG}
      - DJANGO_SECRET=${DJANGO_SECRET}
    depends_on:
      db:
        condition: service_healthy
    volumes:
      - ./data_docker/static:/static
      - ./data_docker/index:/index

  db:
    image: postgres
    restart: always
    volumes:
      - ./data_docker/db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: "tralalere"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
      POSTGRES_USER: "${POSTGRES_USER}"
      POSTGRES_HOST_AUTH_METHOD: "md5"
      POSTGRES_INITDB_ARGS: "--auth-local=md5"
    healthcheck:
      test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

  caddy:
    build:
      context: docker/web
      dockerfile: web.dockerfile
    volumes:
      - ./data_docker/static:/static
    ports:
      - "80:80"
      - "443:443"
