version: "3.8"

services:
  rallly:
    image: lukevella/rallly:4.11.1
    restart: unless-stopped
    depends_on:
      - db
      - minio
      - minio-init
    environment:
      NEXT_PUBLIC_BASE_URL: ${NEXT_PUBLIC_BASE_URL}
      DATABASE_URL: ${DATABASE_URL}
      SECRET_PASSWORD: ${SECRET_PASSWORD}
      SUPPORT_EMAIL: ${SUPPORT_EMAIL}
      NOREPLY_EMAIL: ${NOREPLY_EMAIL}
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      SMTP_USER: ${SMTP_USER}
      SMTP_PWD: ${SMTP_PWD}
      SMTP_SECURE: ${SMTP_SECURE}
      S3_ENDPOINT: ${S3_ENDPOINT}
      S3_BUCKET_NAME: ${S3_BUCKET_NAME}
      S3_REGION: ${S3_REGION}
      S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID}
      S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY}
      INITIAL_ADMIN_EMAIL: ${INITIAL_ADMIN_EMAIL}

  db:
    image: postgres:14-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: rallly
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - rallly-db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d rallly"]
      interval: 10s
      timeout: 5s
      retries: 5

  minio:
    image: minio/minio:latest
    restart: unless-stopped
    command: server /data
    environment:
      MINIO_ROOT_USER: ${S3_ACCESS_KEY_ID}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_ACCESS_KEY}
    volumes:
      - rallly-minio:/data

  minio-init:
    image: minio/mc:latest
    depends_on:
      - minio
    restart: "no"
    entrypoint: >
      /bin/sh -c "
      until mc alias set local http://minio:9000 ${S3_ACCESS_KEY_ID} ${S3_SECRET_ACCESS_KEY}; do sleep 2; done;
      mc mb --ignore-existing local/rallly;
      "

volumes:
  rallly-db:
  rallly-minio: