services:

  app-migrations:
    container_name: next_finances_migrations
    image: markusthielker/next-finances:latest
    env_file:
      - .env
    depends_on:
      postgres:
        condition: service_healthy
    command: bunx prisma migrate deploy
    labels:
      - "com.centurylinklabs.watchtower.enable=true"
    networks:
      - internal

  app:
    container_name: next_finances_app
    image: markusthielker/next-finances:latest
    env_file:
      - .env
    depends_on:
      app-migrations:
        condition: service_completed_successfully
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.xyz-next-finances.rule=Host(`${APPLICATION_DOMAIN}`)"
      - "traefik.http.routers.xyz-next-finances.entrypoints=web, websecure"
      - "traefik.http.routers.xyz-next-finances.tls=true"
      - "traefik.http.routers.xyz-next-finances.tls.certresolver=lets-encrypt"
      - "com.centurylinklabs.watchtower.enable=true"
    networks:
      - web
      - internal

  app-studio:
    container_name: next_finances_studio
    image: markusthielker/next-finances:latest
    env_file:
      - .env
    depends_on:
      app-migrations:
        condition: service_completed_successfully
    command: bunx prisma studio
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.xyz-next-finances-studio.rule=Host(`studio.${APPLICATION_DOMAIN}`)"
      - "traefik.http.routers.xyz-next-finances-studio.entrypoints=web, websecure"
      - "traefik.http.services.xyz-next-finances-studio.loadbalancer.server.port=5555"
      - "traefik.http.routers.xyz-next-finances-studio.tls=true"
      - "traefik.http.routers.xyz-next-finances-studio.tls.certresolver=lets-encrypt"
      - "com.centurylinklabs.watchtower.enable=true"
    networks:
      - web
      - internal

  postgres:
    container_name: next_finances_postgres
    image: postgres:15.2
    restart: unless-stopped
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready" ]
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: finances
    volumes:
      - postgres-data:/var/lib/postgresql/data
    networks:
      - internal


volumes:
  postgres-data:


networks:
  web:
    external: true
  internal: