-
Notifications
You must be signed in to change notification settings - Fork 24
/
gojira-hybrid
executable file
·150 lines (117 loc) · 3.27 KB
/
gojira-hybrid
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
HYBRID_PATH=$GOJIRA_PATH/extra/hybrid
GOJIRA_TARGET=kong-cp
GOJIRA_DATAPLANE_IMAGE=${GOJIRA_DATAPLANE_IMAGE:-}
GOJIRA_DATAPLANE_KONG_PATH=${GOJIRA_DATAPLANE_KONG_PATH:-}
kong_cp() {
GOJIRA_TARGET=kong-cp $0 lay --host kong-cp
}
kong_dp() {
local extra_dp_args=()
if [[ -n "$GOJIRA_DATAPLANE_IMAGE" ]]; then
extra_dp_args+=(--image)
extra_dp_args+=($GOJIRA_DATAPLANE_IMAGE)
unset GOJIRA_KONG_PATH
unset GOJIRA_PREFIX
elif [[ -n "$GOJIRA_DATAPLANE_KONG_PATH" ]]; then
extra_dp_args+=(--kong)
extra_dp_args+=($GOJIRA_DATAPLANE_KONG_PATH)
unset GOJIRA_MODE
unset GOJIRA_IMAGE
unset GOJIRA_PREFIX
fi
GOJIRA_TARGET=kong-dp $0 lay --host kong-dp --alone ${extra_dp_args[@]}
}
hybrid-usage () {
cat << EOF
hybrid mode / plugin
====================
run kong in hybrid mode without the hassle
- generate cluster keys
- creates a kong-dp and a kong-cp service, based on gojira flags
- seamlessly integrates and composes with other gojira modes
Options:
-di, --dataplane-image image to use for kong dataplane
-dk, --dataplane-kong PATH for a kong dataplane folder
Examples:
$ gojira hybrid up
$ gojira hybrid up -t some-branch
$ gojira hybrid up -k path/to/some/kong
$ gojira hybrid shell@kong-cp
$ gojira hybrid shell@kong-dp
$ gojira hybrid logs kong-cp kong-dp
$ gojira hybrid up -i kong:2.4 --di kong:2.3
$ gojira hybrid up -dk path/to/some/kong
EOF
}
hybrid_setup() {
COMPOSE_FILE=$HYBRID_PATH/docker-compose.yml.sh
# Propagate setting flags
export GOJIRA_DATABASE
export KONG_DATABASE
export GOJIRA_REDIS
export GOJIRA_KONG_PATH
if [[ ! -d "$GOJIRA_KONG_PATH" ]]; then create_kong; fi
local actions=()
while [[ $# -gt 0 ]]; do
if [[ ! $1 =~ ^- ]]; then
actions+=($1)
else
break
fi
shift
done
local unparsed_args=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-di|--dataplane-image)
GOJIRA_DATAPLANE_IMAGE=$2
shift
;;
-dk|--dataplane-kong)
GOJIRA_DATAPLANE_KONG_PATH=$2
shift
;;
*)
unparsed_args+=("$1")
;;
esac
shift
done
if [[ -n $GOJIRA_DATAPLANE_IMAGE ]] && [[ -n $GOJIRA_DATAPLANE_KONG_PATH ]]; then
>&2 echo "--dataplane-image and --dataplane-kong cannot be used together"
hybrid-usage
exit 1
fi
# Determine if the dataplane image should attempt to be built
if [[ -n "$GOJIRA_DATAPLANE_KONG_PATH" ]] && [[ "${actions[*]}" =~ (up|build) ]]; then
unset GOJIRA_MODE
unset GOJIRA_IMAGE
unset GOJIRA_PREFIX
$0 build --kong $GOJIRA_DATAPLANE_KONG_PATH
fi
add_egg kong_dp
add_egg kong_cp
add_egg "$COMPOSE_FILE"
if [[ ! -d $HYBRID_PATH/cluster_keys ]]; then
# Generate certs
mkdir -p $HYBRID_PATH/cluster_keys
pushd $HYBRID_PATH/cluster_keys
openssl req -x509 -newkey rsa:4096 -keyout cluster.key -out cluster.crt -days 365 -nodes -subj '/CN=kong_clustering/'
chmod 644 cluster.key
popd
fi
export CLUSTER_KEY_PATH=$HYBRID_PATH/cluster_keys
export GOJIRA_TARGET
# This only runs on "mode", not in plugin mode. Thus, makes it the plugin
# action call
case $1 in
help)
hybrid-usage
exit 0
;;
esac
[[ $1 != "plugin" ]] && main "${actions[@]}" "${unparsed_args[@]}"
}
hybrid_setup "$@"