Skip to content

Instantly share code, notes, and snippets.

@pantsel
Last active October 10, 2024 12:50
Show Gist options
  • Save pantsel/73d949774bd8e917bfd3d9745d71febf to your computer and use it in GitHub Desktop.
Save pantsel/73d949774bd8e917bfd3d9745d71febf to your computer and use it in GitHub Desktop.
example docker-compose.yml for kong, postgres and konga
version: "3"
networks:
kong-net:
driver: bridge
services:
#######################################
# Postgres: The database used by Kong
#######################################
kong-database:
image: postgres:9.6
restart: always
networks:
- kong-net
environment:
POSTGRES_USER: kong
POSTGRES_DB: kong
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "kong"]
interval: 5s
timeout: 5s
retries: 5
#######################################
# Kong database migration
#######################################
kong-migration:
image: kong:latest
command: "kong migrations bootstrap"
networks:
- kong-net
restart: on-failure
environment:
KONG_PG_HOST: kong-database
links:
- kong-database
depends_on:
- kong-database
#######################################
# Kong: The API Gateway
#######################################
kong:
image: kong:latest
restart: always
networks:
- kong-net
environment:
KONG_PG_HOST: kong-database
KONG_PROXY_LISTEN: 0.0.0.0:8000
KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443
KONG_ADMIN_LISTEN: 0.0.0.0:8001
depends_on:
- kong-migration
- kong-database
healthcheck:
test: ["CMD", "curl", "-f", "http://kong:8001"]
interval: 5s
timeout: 2s
retries: 15
ports:
- "8001:8001"
- "8000:8000"
#######################################
# Konga database prepare
#######################################
konga-prepare:
image: pantsel/konga:next
command: "-c prepare -a postgres -u postgresql://kong@kong-database:5432/konga_db"
networks:
- kong-net
restart: on-failure
links:
- kong-database
depends_on:
- kong-database
#######################################
# Konga: Kong GUI
#######################################
konga:
image: pantsel/konga:next
restart: always
networks:
- kong-net
environment:
DB_ADAPTER: postgres
DB_HOST: kong-database
DB_USER: kong
TOKEN_SECRET: km1GUr4RkcQD7DewhJPNXrCuZwcKmqjb
DB_DATABASE: konga_db
NODE_ENV: production
depends_on:
- kong-database
ports:
- "1337:1337"
@mvillafuertem
Copy link

mvillafuertem commented Nov 23, 2020

Hi @baxiang,

I am new to kong, I'm trying enable go_plugins, but I get this error. Any hint?

This is my kong.conf

plugins = bundled,go-hello
go_pluginserver_exe = /usr/local/bin/go-pluginserver
go_plugins_dir = /usr/local/kong/go_plugins/ 

I'm using this docker-compose https://github.com/baxiang/docker_compose/blob/master/kong/docker-compose.yml

Thanks in advance.

kong              | sh: /usr/local/bin/go-pluginserver: not found
kong              | 2020/11/23 11:08:22 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/MessagePack.lua:813: missing bytes
kong              | stack traceback:
kong              | 	[C]: in function 'error'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:813: in function 'underflow'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:529: in function 'unpack_cursor'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:843: in function 'unpack'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:463: in function 'get_plugin_info'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:472: in function 'get_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:519: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:159: in function 'load_plugin_handler'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:243: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:295: in function 'load_plugin_schemas'
kong              | 	/usr/local/share/lua/5.1/kong/init.lua:467: in function 'init'
kong              | 	init_by_lua:3: in main chunk
kong              | nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/MessagePack.lua:813: missing bytes
kong              | stack traceback:
kong              | 	[C]: in function 'error'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:813: in function 'underflow'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:529: in function 'unpack_cursor'
kong              | 	/usr/local/share/lua/5.1/MessagePack.lua:843: in function 'unpack'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:463: in function 'get_plugin_info'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:472: in function 'get_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins/go.lua:519: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:159: in function 'load_plugin_handler'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:243: in function 'load_plugin'
kong              | 	/usr/local/share/lua/5.1/kong/db/dao/plugins.lua:295: in function 'load_plugin_schemas'
kong              | 	/usr/local/share/lua/5.1/kong/init.lua:467: in function 'init'
kong              | 	init_by_lua:3: in main chunk

@baxiang
Copy link

baxiang commented Nov 24, 2020

@mvillafuertem about go_plugins dockerfile

FROM kong/go-plugin-tool:latest-centos-7 as builder
ENV GOPROXY https://goproxy.cn,direct

RUN mkdir -p /go/src/kong-plugins&&mkdir -p /go/src/go-pluginserver
RUN git clone https://github.com/Kong/go-pluginserver /go/src/go-pluginserver \
&& cd /go/src/go-pluginserver && make

COPY ./ /go/src/kong-plugins
RUN cd /go/src/kong-plugins&& make build

FROM kong:2.2.0-centos

ENV KONG_DATABASE=off
ENV KONG_GO_PLUGINS_DIR=/tmp/go-plugins
ENV KONG_DECLARATIVE_CONFIG=/tmp/config.yml
ENV KONG_PLUGINS=go-kong
COPY --from=builder /go/src/go-pluginserver/go-pluginserver /usr/local/bin/go-pluginserver
RUN mkdir /tmp/go-plugins
COPY --from=builder /go/src/kong-plugins/go-kong.so /tmp/go-plugins/go-kong.so
COPY config.yml /tmp/config.yml

demo :https://github.com/baxiang/go-note/tree/master/kong-dev

@adibenc
Copy link

adibenc commented Aug 21, 2021

i created small fixes / additions here, hope helps..
https://gist.github.com/adibenc/d82415128cdb6d313e54d5b606e8c1ab

@rajeshknigam
Copy link

this worked for me, if the

  • services are started one by one
  • for the database instead of hostname kong-database, had to use the IP address. Somehow the hostname was not resolved.
  • Also added the volume for the database

version: "3"

networks:
kong-net:
driver: bridge

volumes:
kong-db:
driver: local
services:

#######################################

Postgres: The database used by Kong

#######################################
kong-database:
image: postgres:9.6
restart: always
networks:
- kong-net
environment:
POSTGRES_PASSWORD: kong
POSTGRES_USER: kong
POSTGRES_DB: kong
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "kong"]
interval: 5s
timeout: 5s
retries: 5
volumes:
- kong-db:/var/lib/postgresql/data

#######################################

Kong database migration

#######################################
kong-migration:
image: kong:latest
command: "kong migrations bootstrap"
networks:
- kong-net
restart: on-failure
environment:
KONG_PG_HOST: kong-database
KONG_DATABASE: postgres
KONG_PG_PASSWORD: kong
links:
- kong-database
depends_on:
- kong-database

#######################################

Kong: The API Gateway

#######################################
kong:
image: kong:latest
restart: always
networks:
- kong-net
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: 10.0.34.16
KONG_PG_USER: kong
KONG_PG_PASSWORD: kong
KONG_PROXY_LISTEN: 0.0.0.0:9000
KONG_PROXY_LISTEN_SSL: 0.0.0.0:9443
KONG_ADMIN_LISTEN: 0.0.0.0:9001
depends_on:
- kong-migration
- kong-database
healthcheck:
test: ["CMD", "curl", "-f", "http://kong:8001"]
interval: 5s
timeout: 2s
retries: 15
ports:
- "9001:9001"
- "9000:9000"

#######################################

Konga database prepare

#######################################
konga-prepare:
image: pantsel/konga:next
command: "-c prepare -a postgres -u postgresql://kong:kong@kong-database:5432/konga_db"
environment:
DB_ADAPTER: postgres
DB_HOST: 10.0.34.16
DB_USER: kong
DB_PASSWORD: kong
networks:
- kong-net
restart: on-failure
links:
- kong-database
depends_on:
- kong-database

#######################################

Konga: Kong GUI

#######################################
konga:
image: pantsel/konga:next
restart: always
networks:
- kong-net
environment:
DB_ADAPTER: postgres
DB_HOST: 10.0.34.16
DB_USER: kong
DB_PASSWORD: kong
TOKEN_SECRET: km1GUr4RkcQD7DewhJPNXrCuZwcKmqjb
DB_DATABASE: konga_db
NODE_ENV: production
depends_on:
- kong-database
ports:
- "1337:1337"

@LincWong
Copy link

LincWong commented Aug 23, 2022 via email

@ikenna
Copy link

ikenna commented Aug 25, 2023

Because postgres always require DB_PASSWORD

To get konga-prepare to work, I had to include the db password in the connection string in the format username:password -
command: "-c prepare -a postgres -u postgresql://kong:kong@kong-database:5432/konga_db"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment