services:
  localstack:
    environment:
      - DEBUG=${DEBUG-}
      - PERSISTENCE=${PERSISTENCE-}
      - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
      - DOCKER_HOST=unix:///var/run/docker.sock
    image: localstack/localstack
    ports:
      - "127.0.0.1:4566:4566"            # LocalStack Gateway
      - "127.0.0.1:4510-4559:4510-4559"  # external services port range
    volumes:
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

  app:
    command:
      - scripts/docker_local_setup.sh
    depends_on:
      - worker
      - db
    entrypoint:
      - /usr/bin/dumb-init
      - --
      - ./utils/wait-for-it.sh
      - palolo-db:5432
      - --
    environment:
      # Workaround for https://github.com/prisma/prisma/issues/12598
      - DATABASE_HOST=db
      - DATABASE_PORT=5432
      - DEPLOYED_AT
      - LOCAL_DOCKER=true
      - PALOLO_ENV=docker
      - PALOLO_COMMAND=server
    image: ${ARTIFACTS_REGISTRY}/palolo
    ports:
      - "3000:3000"
      - "3001:3001"
    volumes:
      # /app is the home_directory of our local user
      # If you get weird errors that you can't pull secrets beacuse no region
      # did you change this?
      - $HOME/.aws:/app/.aws
      # I would love to say that I never login as root, but I do for debugging sometimes
      - $HOME/.aws:/root/.aws
      - ./utils:/app/utils:ro
      - ./scripts/:/app/scripts/
      - ./packages/server/scripts/:/app/packages/server/scripts/

  db:
    env_file: config/postgres/.env
    image: ${ARTIFACTS_REGISTRY}/postgres:14
    ports:
      - "5433:5432"
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data
    # - ./packages/server/.postgres/db:/var/lib/postgresql/data

  worker:
    command:
      - scripts/docker_local_setup.sh
    depends_on:
      - db
      - localstack
    entrypoint:
      - /usr/bin/dumb-init
      - --
      - ./utils/wait-for-it.sh
      - palolo-db:5432
      - --
    environment:
      # Workaround for https://github.com/prisma/prisma/issues/12598
      - DATABASE_HOST=db
      - DATABASE_PORT=5432
      - DEPLOYED_AT
      - LOCAL_DOCKER=true
      - PALOLO_ENV=docker
      - PALOLO_COMMAND=worker
    image: ${ARTIFACTS_REGISTRY}/palolo
    ports:
      - "4002:4001"
    volumes:
      # /app is the home_directory of our local user
      # If you get weird errors that you can't pull secrets beacuse no region
      # did you change this?
      - $HOME/.aws:/app/.aws
      # I would love to say that I never login as root, but I do for debugging sometimes
      - $HOME/.aws:/root/.aws
      - ./utils:/app/utils:ro
      - ./scripts/:/app/scripts/
      - ./packages/server/scripts/:/app/packages/server/scripts/

volumes:
  postgres:
    name: palolo-db
