
volumes:
  kong_data: {}

services:
  kong-bootstrap:
    command: kong migrations bootstrap
    image: kong:3.4
    depends_on:
      - db
    environment:
      KONG_DATABASE: postgres
      KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
      KONG_PG_HOST: db
      KONG_PG_USER: ${KONG_PG_USER:-kong}
      KONG_PG_PASSWORD: kong
    logging:
      driver: syslog
      options:
        tag: appsentinels-kong
    volumes:
      - /var/crash:/var/crash
    restart: on-failure
    deploy:
      restart_policy:
        condition: on-failure

  kong-migrations-up:
    image: kong:3.4
    command: kong migrations up 
    depends_on:
      - db
    environment:
      KONG_DATABASE: postgres
      KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
      KONG_PG_HOST: db
      KONG_PG_USER: ${KONG_PG_USER:-kong}
      KONG_PG_PASSWORD: kong    
    logging:
      driver: syslog
      options:
        tag: appsentinels-kong
    volumes:
      - /var/crash:/var/crash
    restart: on-failure
    deploy:
      restart_policy:
        condition: on-failure

  kong-migrations-finish:
    image: kong:3.4
    command: kong migrations finish
    depends_on:
      - db
    environment:
      KONG_DATABASE: postgres
      KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
      KONG_PG_HOST: db
      KONG_PG_USER: ${KONG_PG_USER:-kong}
      KONG_PG_PASSWORD: kong    
    logging:
      driver: syslog
      options:
        tag: appsentinels-kong
    volumes:
      - /var/crash:/var/crash
    restart: on-failure
    deploy:
      restart_policy:
        condition: on-failure

  kong:
    image: kong:3.4
    #image: "${KONG_DOCKER_TAG:-kong:custom2}"
    user: "${KONG_USER:-kong}"
    depends_on:
      - db
    environment:
      KONG_ADMIN_ACCESS_LOG: /dev/stdout
      KONG_ADMIN_ERROR_LOG: /dev/stderr
      KONG_ADMIN_LISTEN: '0.0.0.0:8001'
      KONG_CASSANDRA_CONTACT_POINTS: db
      KONG_DATABASE: postgres
      KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
      KONG_PG_HOST: db
      KONG_PG_USER: ${KONG_PG_USER:-kong}
      KONG_PROXY_ACCESS_LOG: /dev/stdout
      KONG_PROXY_ERROR_LOG: /dev/stderr
      KONG_PG_PASSWORD: kong 
      KONG_PLUGINS: bundled,appsentinels
      KONG_LOG_LEVEL: debug
    ports:
      - "8000:8000/tcp"
      - "8001:8001/tcp"
      - "8443:8443/tcp"
    extra_hosts:
      - "httpserver:172.18.0.1"
    healthcheck:
      test: ["CMD", "kong", "health"]
      interval: 10s
      timeout: 10s
      retries: 10
    restart: on-failure
    deploy:
      restart_policy:
        condition: on-failure
    logging:
      driver: syslog
      options:
        tag: appsentinels-kong
    volumes:
      - /var/crash:/var/crash
      - ./appsentinels:/usr/local/share/lua/5.1/kong/plugins/appsentinels

  db:
    image: postgres:9.5
    environment:
      POSTGRES_DB: ${KONG_PG_DATABASE:-kong}
      POSTGRES_USER: ${KONG_PG_USER:-kong}
      POSTGRES_PASSWORD: kong
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "${KONG_PG_USER:-kong}"]
      interval: 30s
      timeout: 30s
      retries: 3
    restart: on-failure
    deploy:
      restart_policy:
        condition: on-failure
    stdin_open: true
    tty: true
    volumes:
      - kong_data:/var/lib/postgresql/data
