version: "3.7"
name: "davis-docker"

services:

  nginx:
    image: nginx:1.25-alpine
    container_name: nginx
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
    depends_on:
      - davis
    volumes:
      - davis_www:/var/www/davis
      - type: bind
        source: ./configurations/nginx.conf
        target: /etc/nginx/conf.d/default.conf
    ports:
      - 9000:80

  postgresql:
    image: postgres:16-alpine
    container_name: postgresql
    environment:
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_DATABASE}
      - POSTGRES_USER=${DB_USER}
    volumes:
      - database_pg:/var/lib/postgresql/data

  davis:
    build:
      context: ../
      dockerfile: ./docker/Dockerfile
    image: davis:latest
    # If you want to use a prebuilt image from Github
    # image: ghcr.io/tchapi/davis:edge
    container_name: davis
    environment:
      - APP_ENV=prod
      - DATABASE_DRIVER=postgresql
      - DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@postgresql:5432/${DB_DATABASE}?serverVersion=15&charset=UTF-8
      - MAILER_DSN=smtp://${MAIL_USERNAME}:${MAIL_PASSWORD}@${MAIL_HOST}:${MAIL_PORT}
      - ADMIN_LOGIN=${ADMIN_LOGIN}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD}
      - AUTH_REALM=${AUTH_REALM}
      - AUTH_METHOD=${AUTH_METHOD}
      - CALDAV_ENABLED=${CALDAV_ENABLED}
      - CARDDAV_ENABLED=${CARDDAV_ENABLED}
      - WEBDAV_ENABLED=${WEBDAV_ENABLED}
      - WEBDAV_TMP_DIR=${WEBDAV_TMP_DIR}
      - WEBDAV_PUBLIC_DIR=${WEBDAV_PUBLIC_DIR}
      - WEBDAV_HOMES_DIR=${WEBDAV_HOMES_DIR}
      - INVITE_FROM_ADDRESS=${INVITE_FROM_ADDRESS}
      - APP_TIMEZONE=${TIMEZONE}
    depends_on:
      - postgresql
    volumes:
      - davis_www:/var/www/davis

volumes:
  davis_www:
    name: davis_www
  database_pg:
    name: database_pg
