I am trying to use Kong in declarative way with a kong.yml file. I want to be able to use environment variables in the kong.yml file. I have the following content in my docker-compose:
kong:
image: kong:2.7.0-alpine
restart: "always"
hostname: kong
container_name: kong
networks:
- kong-net
environment:
KONG_DATABASE: "off"
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: "0.0.0.0:8001, 0.0.0.0:8444 ssl"
KONG_DECLARATIVE_CONFIG: "/opt/kong/kong.yml"
ADMIN_MICROSERVICE_PORT: ${ADMIN_MICROSERVICE_PORT}
REPORTING_MICROSERVICE_PORT: ${REPORTING_MICROSERVICE_PORT}
INTERNAL_IP: ${INTERNAL_IP}
command: "kong start --v"
ports:
- "${INTERNAL_IP}:8000:8000"
- "${INTERNAL_IP}:8443:8443"
- "${INTERNAL_IP}:8001:8001"
- "${INTERNAL_IP}:8444:8444"
volumes:
- ./kong/config:/opt/kong
And a kong.yml file:
_format_version: "2.1"
_transform: true
services:
- name: controllers
url: https://${INTERNAL_IP}:${ADMIN_MICROSERVICE_PORT}
routes:
- name: controller-routes
paths:
- /admin/controllers
- name: vpnprofiles
url: https://${INTERNAL_IP}:${ADMIN_MICROSERVICE_PORT}
routes:
- name: vpnprofiles-routes
paths:
- /admin/vpnprofiles
- name: device_report
url: https://${INTERNAL_IP}:${REPORTING_MICROSERVICE_PORT}
routes:
- name: device-report-routes
paths:
- /reporting/device_report
Here are the logs of the kong image:
022/01/01 12:38:46 [error] 1095#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:551: error parsing declarative config file /opt/kong/kong.yml:
in 'services':
- in entry 1 of 'services':
in 'host': invalid value: ${INTERNAL_IP}
in 'port': expected an integer
- in entry 2 of 'services':
in 'host': invalid value: ${INTERNAL_IP}
in 'port': expected an integer
- in entry 3 of 'services':
in 'host': invalid value: ${INTERNAL_IP}
in 'port': expected an integer
stack traceback:
[C]: in function 'error'
/usr/local/share/lua/5.1/kong/init.lua:551: in function 'init'
init_by_lua:3: in main chunk
However, variables in kong.yml are not substituted at launch. Am I doing something wrong ?