Skip to content

Commit e96abdd

Browse files
committed
Added Kong in Docker, added development docs
1 parent 86dd6c9 commit e96abdd

File tree

7 files changed

+144
-1
lines changed

7 files changed

+144
-1
lines changed

.config/POSTGRES_PASSWORD

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
password

.config/kong.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# a very minimal declarative config file
2+
_format_version: "2.1"
3+
_transform: true

.config/kong/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ phpunit.xml
2929
phpstan.neon
3030
psalm.xml
3131
testbench.yaml
32-
/docs
3332
/coverage

bin/configure-kong

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
echo " 🚀 Export Default Configuration"
4+
curl -s localhost:8001 | jq '.configuration' > .config/kong/configuration-default.json
5+
6+
echo " 🚀 Set Rate Limit Globbaly to 60 requests per minute."
7+
curl -X POST http://localhost:8001/plugins \
8+
--data name=rate-limiting \
9+
--data config.minute=60 \
10+
--data config.policy=local | jq '.' > .config/kong/admin-api-rate-limit-global.json
11+
12+
echo " 🚀 Set Default Proxy Cache to 30 seconds"
13+
curl -X POST http://localhost:8001/plugins \
14+
--data "name=proxy-cache" \
15+
--data "config.request_method=GET" \
16+
--data "config.response_code=200" \
17+
--data "config.content_type=application/json; charset=utf-8" \
18+
--data "config.cache_ttl=30" \
19+
--data "config.strategy=memory" | jq '.' > .config/kong/admin-api-proxy-cache-global.json
20+
21+
echo " 🚀 Create Admin API Service"
22+
curl --request POST \
23+
--url http://localhost:8001/services \
24+
--data name=admin-api-service \
25+
--data url='http://localhost:8001' | jq '.' > .config/kong/admin-api-service.json
26+
27+
echo " 🚀 Create Admin API Route"
28+
curl --request POST \
29+
--url http://localhost:8001/services/admin-api-service/routes \
30+
--data 'paths[]=/admin-api' \
31+
--data name=admin-api-route | jq '.' > .config/kong/admin-api-route.json
32+
33+
echo " 🚀 Enable Key Auth on Admin API Service"
34+
curl --request POST \
35+
--url http://localhost:8001/services/admin-api-service/plugins \
36+
--header 'Content-Type: application/json' \
37+
--header 'accept: application/json' \
38+
--data '{"name":"key-auth","config":{"key_names":["api-key"],"key_in_query":false}}' | jq '.' > .config/kong/admin-api-key.json
39+
40+
echo " 🚀 Create Admin API Consumer"
41+
curl --request POST \
42+
--url http://localhost:8001/consumers \
43+
--header 'Content-Type: application/json' \
44+
--header 'accept: application/json' \
45+
--data '{"username":"apim","custom_id":"apim"}' | jq '.' > .config/kong/consumer-apim.json
46+
47+
echo " 🚀 Create APIM API Key"
48+
curl -X POST http://localhost:8001/consumers/apim/key-auth | jq '.' > .config/kong/admin-api-consumer-key.json

docker-compose.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
version: '3.9'
2+
3+
x-kong-config: &kong-env
4+
KONG_DATABASE: postgres
5+
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
6+
KONG_PG_HOST: kong-database
7+
KONG_PG_USER: ${POSTGRES_USER:-kong}
8+
KONG_PG_PASSWORD_FILE: /run/secrets/kong_postgres_password
9+
10+
services:
11+
kong-migrations:
12+
image: kong/kong-gateway:3.6.1.8
13+
command: kong migrations bootstrap
14+
depends_on:
15+
- kong-database
16+
environment:
17+
<<: *kong-env
18+
secrets:
19+
- kong_postgres_password
20+
networks:
21+
- kong-net
22+
restart: on-failure
23+
24+
kong-migrations-up:
25+
image: kong/kong-gateway:3.6.1.8
26+
command: kong migrations up && kong migrations finish
27+
depends_on:
28+
- kong-database
29+
environment:
30+
<<: *kong-env
31+
secrets:
32+
- kong_postgres_password
33+
networks:
34+
- kong-net
35+
restart: on-failure
36+
37+
kong-gateway:
38+
image: kong/kong-gateway:3.6.1.8
39+
user: "${KONG_USER:-kong}"
40+
networks:
41+
- kong-net
42+
environment:
43+
<<: *kong-env
44+
KONG_PROXY_ACCESS_LOG: /dev/stdout
45+
KONG_ADMIN_ACCESS_LOG: /dev/stdout
46+
KONG_PROXY_ERROR_LOG: /dev/stderr
47+
KONG_ADMIN_ERROR_LOG: /dev/stderr
48+
KONG_ADMIN_LISTEN: 0.0.0.0:${KONG_ADMIN_PORT:-8001}
49+
KONG_PROXY_LISTEN: 0.0.0.0:${KONG_PROXY_PORT:-8000}
50+
secrets:
51+
- kong_postgres_password
52+
ports:
53+
- '${KONG_PROXY_PORT:-8000}:8000'
54+
- '${KONG_ADMIN_PORT:-8001}:8001'
55+
depends_on:
56+
- kong-database
57+
healthcheck:
58+
test: ["CMD", "kong", "health"]
59+
interval: 10s
60+
timeout: 10s
61+
retries: 10
62+
restart: on-failure:5
63+
64+
kong-database:
65+
image: postgres:13
66+
environment:
67+
- POSTGRES_DB=${KONG_PG_DATABASE:-kong}
68+
- POSTGRES_USER=${POSTGRES_USER:-kong}
69+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
70+
networks:
71+
- kong-net
72+
73+
networks:
74+
kong-net:
75+
external: true
76+
77+
secrets:
78+
kong_postgres_password:
79+
file: .config/POSTGRES_PASSWORD

docs/development.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Development
2+
3+
TL;DR, run the following to setup package development environment:
4+
5+
```bash
6+
composer install
7+
docker-compose up -d
8+
. ./bin/configure-kong
9+
```
10+
11+
Kong Admin API key are located in `.config/kong/admin-api-consumer-key.json` file.

0 commit comments

Comments
 (0)