services:
  migrate:
    image: registry.example.com/thaifortravel-miniapp-api:latest
    command: ["node_modules/.bin/prisma", "migrate", "deploy"]
    env_file: .env.production
    restart: "no"

  api:
    image: registry.example.com/thaifortravel-miniapp-api:latest
    command: ["node", "dist/src/server.js"]
    env_file: .env.production
    restart: unless-stopped
    depends_on:
      migrate:
        condition: service_completed_successfully
    ports:
      - "127.0.0.1:3100:3100"
    healthcheck:
      test:
        [
          "CMD",
          "node",
          "-e",
          "fetch('http://127.0.0.1:3100/health/ready').then(r=>{if(!r.ok)process.exit(1)})",
        ]
      interval: 15s
      timeout: 5s
      retries: 10

  worker:
    image: registry.example.com/thaifortravel-miniapp-api:latest
    command: ["node", "dist/src/worker.js"]
    env_file: .env.production
    restart: unless-stopped
    depends_on:
      migrate:
        condition: service_completed_successfully
