version: '3.8'

services:
  db:
    image: postgres:16.2
    restart: always
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - ${POSTGRES_PORT}:5432

  dbadmin:
    image: dpage/pgadmin4:8.5
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
    ports:
      - ${PGADMIN_PORT}:80
    volumes:
      - pgadmindata:/var/lib/pgadmin
    depends_on:
      - db

  cache:
    image: redis:7.0.2-alpine
    restart: always
    ports:
      - ${REDIS_PORT}:6379
    command: redis-server --save 20 1 --loglevel warning
    volumes:
      - redisdata:/data

  mailer:
    image: mailhog/mailhog:v1.0.1
    restart: always
    ports:
      - ${MAIL_PORT}:1025
      - ${MAIL_HOG_WEB_PORT}:8025

  proxy:
    image: nginx:1.20.2
    restart: always
    volumes:
      - ../volumes/proxy/templates:/etc/nginx/templates
    environment:
      - API_PORT=${API_PORT}
      - MAIL_HOG_WEB_PORT=${MAIL_HOG_WEB_PORT}
      - PGADMIN_PORT=${PGADMIN_PORT}
    ports:
      - '80:80'
    extra_hosts:
      - 'host.docker.internal:host-gateway'

volumes:
  pgdata:
  pgadmindata:
  redisdata:
