Repository navigation
Expand file tree
/
Copy pathdemo.sh
More file actions
executable file
·99 lines (73 loc) · 2.66 KB
/
Copy pathdemo.sh
File metadata and controls
executable file
·99 lines (73 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -x
DEMO_KONG_CONTAINER="${DEMO_KONG_CONTAINER:-kong-wasm}"
DEMO_KONG_IMAGE="${DEMO_KONG_IMAGE:-kong/kong:nightly}"
function message() {
set +x
echo "----------------------------------------------------------------------"
echo $1
echo "----------------------------------------------------------------------"
set -x
}
################################################################################
if [[ "$1" == "stop" ]]
then
docker stop $DEMO_KONG_CONTAINER
docker rm $DEMO_KONG_CONTAINER
exit 0
fi
### Build filter ###############################################################
message "Building the filter using cargo..."
(
cd ..
cargo build --target=wasm32-wasi --release || exit 1
) || exit 1
### Copy filter to wasm/ #######################################################
mkdir -p wasm
cp -a ../target/wasm32-wasi/release/*.wasm wasm/
cp ../*.meta.json wasm/
script_dir=$(dirname $(realpath $0))
### Start container ############################################################
message "Setting up the Kong Gateway container..."
docker stop $DEMO_KONG_CONTAINER
docker rm $DEMO_KONG_CONTAINER
# Config trick to access localhost in a local Docker test,
# in case you want to edit your config/demo.yml to target
# a localhost server rather than httpbin.org:
#
# access_localhost="--add-host=host.docker.internal:$(ip -j address | jq -r '[ .[] | select(.ifname | test("^[ew]")) | .addr_info[] | select(.family == "inet") | .local ][0]')"
access_localhost=""
docker run -d --name "$DEMO_KONG_CONTAINER" \
$access_localhost \
-v "$script_dir/config:/kong/config/" \
-v "$script_dir/wasm:/wasm" \
-e "KONG_LOG_LEVEL=info" \
-e "KONG_DATABASE=off" \
-e "KONG_DECLARATIVE_CONFIG=/kong/config/demo.yml" \
-e "KONG_NGINX_WASM_SHM_KV_DATAKIT=12m" \
-e "KONG_NGINX_HTTP_PROXY_WASM_ISOLATION=none" \
-e "KONG_NGINX_WORKER_PROCESSES=2" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_WASM=on" \
-e "KONG_WASM_FILTERS_PATH=/wasm" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
"$DEMO_KONG_IMAGE"
### Show configuration #########################################################
message "This is the configuration loaded into Kong:"
cat config/demo.yml
sleep 5
### Issue requests #############################################################
message "Now let's send a request to see the filter in effect:"
http :8000/anything
http :8000/anything
http :8000/anything
http :8000/anything
http :8000/anything
http :8000/anything
message "Finishing up!"
docker stop $DEMO_KONG_CONTAINER
#docker rm $DEMO_KONG_CONTAINER