services:

  db:
    image: postgres:16
    env_file:
      - .env
    ports:
      - "${PGPORT}:${PGPORT}"
    volumes:
      - postgres-db:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${PGUSER}
      - POSTGRES_PASSWORD=${PGPASSWORD}
      - POSTGRES_DB=${PGDATABASE}
    
  api:
    build:
      context: ./api
      dockerfile: Dockerfile
    env_file:
      - .env
    ports:
      - "${SERVER_PORT}:${SERVER_PORT}"
    volumes:
      - .:/usr/src/app
    depends_on:
      - db
    command: ./bin/api.exe

  migrator:
    build:
      context: ./migrator
      dockerfile: Dockerfile
    env_file:
      - .env
    depends_on:
      - api
      - db
    volumes:
      - goose:/migrations
    environment:
      - GOOSE_DRIVER=${GOOSE_DRIVER}
      - GOOSE_DBSTRING=${GOOSE_DBSTRING}
    command: goose up

volumes:
  postgres-db:
  goose: