version: "3"
services:

  mongodb:
    image: mongo
    container_name: mongodb
    logging:
      driver: "none"
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - mongodb:/data/db
    ports:
      - 27017:27017
    restart: unless-stopped
    networks:
      - impler

  api:
    privileged: true
    image: "ghcr.io/implerhq/impler/api:0.27.5"
    depends_on:
      - mongodb
      - rabbitmq
    container_name: api
    environment:
      NODE_ENV: ${NODE_ENV}
      PORT: ${API_PORT}
      WIDGET_BASE_URL: ${WIDGET_BASE_URL}
      WEB_BASE_URL: ${WEB_BASE_URL}
      MONGO_URL: ${MONGO_URL}
      S3_REGION: ${S3_REGION}
      S3_LOCAL_STACK: ${S3_LOCAL_STACK}
      S3_BUCKET_NAME: ${S3_BUCKET_NAME}
      JWT_SECRET: ${JWT_SECRET}
      COOKIE_DOMAIN: ${COOKIE_DOMAIN}
      RABBITMQ_CONN_URL: ${RABBITMQ_CONN_URL}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      GITHUB_OAUTH_CLIENT_ID: ${GITHUB_OAUTH_CLIENT_ID}
      GITHUB_OAUTH_CLIENT_SECRET: ${GITHUB_OAUTH_CLIENT_SECRET}
      GITHUB_OAUTH_REDIRECT: ${GITHUB_OAUTH_REDIRECT}
      SES_REGION: ${SES_REGION}
      SES_ACCESS_KEY_ID: ${SES_ACCESS_KEY_ID}
      SES_SECRET_ACCESS_KEY: ${SES_SECRET_ACCESS_KEY}
      EMAIL_FROM: ${EMAIL_FROM}
      EMAIL_FROM_NAME: ${EMAIL_FROM_NAME}
      ALERT_EMAIL_FROM: ${ALERT_EMAIL_FROM}
    ports:
      - "3000:3000"
    networks:
      - impler

  queue-manager:
    image: "ghcr.io/implerhq/impler/queue-manager:0.27.5"
    depends_on:
      - api
      - rabbitmq
    container_name: queue-manager
    environment:
      NODE_ENV: ${NODE_ENV}
      MONGO_URL: ${MONGO_URL}
      RABBITMQ_CONN_URL: ${RABBITMQ_CONN_URL}
      S3_REGION: ${S3_REGION}
      API_ROOT_URL: ${API_ROOT_URL}
      S3_LOCAL_STACK: ${S3_LOCAL_STACK}
      S3_BUCKET_NAME: ${S3_BUCKET_NAME}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      SES_REGION: ${SES_REGION}
      SES_ACCESS_KEY_ID: ${SES_ACCESS_KEY_ID}
      SES_SECRET_ACCESS_KEY: ${SES_SECRET_ACCESS_KEY}
      EMAIL_FROM: ${EMAIL_FROM}
      EMAIL_FROM_NAME: ${EMAIL_FROM_NAME}
      ALERT_EMAIL_FROM: ${ALERT_EMAIL_FROM}
    networks:
      - impler

  widget:
    image: "ghcr.io/implerhq/impler/widget:0.27.5"
    depends_on:
      - api
    container_name: widget
    environment:
      REACT_APP_API_URL: ${API_ROOT_URL}
      REACT_APP_SENTRY_DSN: ${SENTRY_DSN}
      REACT_APP_ENVIRONMENT: ${NODE_ENV}
      REACT_APP_AMPLITUDE_ID: ${AMPLITUDE_ID}
    ports:
      - 3500:3500
    networks:
      - impler

  embed:
    depends_on:
      - widget
    image: "ghcr.io/implerhq/impler/embed:0.27.5"
    container_name: embed
    environment:
      WIDGET_URL: ${WIDGET_BASE_URL}
    ports:
      - 4701:4701
    networks:
      - impler

  web:
    depends_on:
      - api
    image: "ghcr.io/implerhq/impler/web:0.27.5"
    container_name: web
    environment:
      NEXT_PUBLIC_API_BASE_URL: ${API_ROOT_URL}
      NEXT_PUBLIC_EMBED_URL: ${WIDGET_EMBED_PATH}
      NEXT_PUBLIC_AMPLITUDE_ID: ${WEB_AMPLITUDE_ID}
      NEXT_PUBLIC_GTM_ID: ${NEXT_PUBLIC_GTM_ID}
      NEXT_PUBLIC_GOOGLE_ANALYTICS_ID: ${NEXT_PUBLIC_GOOGLE_ANALYTICS_ID}
    ports:
      - 4200:4200
    networks:
      - impler
  
  rabbitmq:
    image: rabbitmq:3-alpine
    container_name: 'rabbitmq'
    restart: always
    ports:
      - 5672:5672
    healthcheck:
      test: [ "CMD", "nc", "-z", "localhost", "5672" ]
      interval: 5s
      timeout: 15s
      retries: 1
    networks:
      - impler

  minio:
    image: minio/minio
    volumes:
      - minio_data:/data
    environment:
      MINIO_ROOT_USER: impler
      MINIO_ROOT_PASSWORD: implers3cr3t
    ports:
      - 9000:9000
      - 9001:9001
    command: server /data --console-address ":9001"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  createbuckets:
    image: minio/mc
    depends_on:
      - minio
    entrypoint: >
      /bin/sh -c "
      /usr/bin/mc alias set myminio http://minio:9000 impler implers3cr3t;
      /usr/bin/mc mb myminio/impler;
      exit 0;
      "

volumes:
  mongodb: ~

networks:
  impler:
