# check .env files before running
services:

  # Kong: The API Gateway
  kong:
    container_name: kong
    image: kong:latest
    restart: always
    environment:
      KONG_DATABASE: ${KONG_DATABASE}
      KONG_PG_HOST: ${KONG_PG_HOST}
      KONG_PG_USER: ${KONG_PG_USER}
      KONG_PG_DATABASE: ${KONG_PG_DATABASE}
      KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}

      KONG_PROXY_LISTEN: 0.0.0.0:${KONG_PORT}
      KONG_PROXY_LISTEN_SSL: 0.0.0.0:${KONG_PORT_SSL}
      KONG_ADMIN_LISTEN: 0.0.0.0:${KONG_ADMIN_PORT}
    depends_on:
      - kong-migration
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://kong:${KONG_ADMIN_PORT}" ]
      interval: 5s
      timeout: 2s
      retries: 15
    ports:
      - "${KONG_PORT}:${KONG_PORT}"
      - "${KONG_PORT_SSL}:${KONG_PORT_SSL}"
      - "${KONG_ADMIN_PORT}:${KONG_ADMIN_PORT}"

  # Kong database migration task
  kong-migration: # one time job
    container_name: kong-migration
    image: kong:latest
    command: "kong migrations bootstrap"
    restart: on-failure
    environment:
      KONG_DATABASE: ${KONG_DATABASE}
      KONG_PG_HOST: ${KONG_PG_HOST}
      KONG_PG_USER: ${KONG_PG_USER}
      KONG_PG_DATABASE: ${KONG_PG_DATABASE}
      KONG_PG_PASSWORD: ${KONG_PG_PASSWORD}