version: '3'

services:
  db:
    image: postgres:13-alpine
    ports:
      - ${POSTGRES_PORT:-5432}:5432
    environment:
      - POSTGRES_DB=${POSTGRES_DB:-test_db}
      - POSTGRES_USER=${POSTGRES_USER:-test_user}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
    volumes:
      - ./scripts/init-pgboss.sql:/docker-entrypoint-initdb.d/init-pgboss.sql

  filehosting:
    image: minio/minio:RELEASE.2023-03-24T21-41-23Z
    ports:
      - ${S3_PORT:-9000}:9000
      - ${MINIO_CONSOLE_PORT:-9001}:9001
    volumes:
      - minio_storage:/data
    environment:
      - MINIO_ROOT_USER=${MINIO_ROOT_USER:-admin}
      - MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD:-superSecretAdminPassword}
    command: server --console-address ":${MINIO_CONSOLE_PORT:-9001}" /data
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live']
      interval: 30s
      timeout: 20s
      retries: 3

  createbucket:
    image: minio/mc:RELEASE.2023-02-16T19-20-11Z
    depends_on:
      filehosting:
        condition: service_healthy
    entrypoint: >
      /bin/sh -c "
        /usr/bin/mc config host add cokoServer ${S3_PROTOCOL:-http}://${S3_HOST:-filehosting}:9000 ${MINIO_ROOT_USER:-admin} ${MINIO_ROOT_PASSWORD:-superSecretAdminPassword};
        /usr/bin/mc admin user add cokoServer/ ${S3_ACCESS_KEY_ID:-cokoServerUser} ${S3_SECRET_ACCESS_KEY:-superSecretUserPassword};
        /usr/bin/mc admin user enable cokoServer/ ${S3_ACCESS_KEY_ID:-cokoServerUser};
        /usr/bin/mc mb cokoServer/${S3_BUCKET:-uploads};
        /usr/bin/mc admin policy set cokoServer/ readwrite user=${S3_ACCESS_KEY_ID:-cokoServerUser};
        exit 0;
      "

volumes:
  minio_storage:
