Skip to content

Commit a0a98d8

Browse files
fix: add kong config with nginx_worker_processes option (#1271)
* Add Kong nginx_worker_processes option * fix: set default worker processes to 1 --------- Co-authored-by: Qiao Han <qiao@supabase.io>
1 parent fa1f971 commit a0a98d8

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

internal/start/start.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,22 @@ EOF
268268
// Start Kong.
269269
p.Send(utils.StatusMsg("Starting containers..."))
270270
if !isContainerExcluded(utils.KongImage, excluded) {
271+
env := []string{
272+
"KONG_DATABASE=off",
273+
"KONG_DECLARATIVE_CONFIG=/home/kong/kong.yml",
274+
"KONG_DNS_ORDER=LAST,A,CNAME", // https://github.com/supabase/cli/issues/14
275+
"KONG_PLUGINS=request-transformer,cors",
276+
// Need to increase the nginx buffers in kong to avoid it rejecting the rather
277+
// sizeable response headers azure can generate
278+
// Ref: https://github.com/Kong/kong/issues/3974#issuecomment-482105126
279+
"KONG_NGINX_PROXY_PROXY_BUFFER_SIZE=160k",
280+
"KONG_NGINX_PROXY_PROXY_BUFFERS=64 160k",
281+
}
282+
283+
if utils.Config.Kong.NginxWorkerProcesses != 0 {
284+
env = append(env, fmt.Sprintf("KONG_NGINX_WORKER_PROCESSES=%d", utils.Config.Kong.NginxWorkerProcesses))
285+
}
286+
271287
var kongConfigBuf bytes.Buffer
272288

273289
if err := kongConfigTemplate.Execute(&kongConfigBuf, kongConfig{
@@ -287,17 +303,7 @@ EOF
287303
ctx,
288304
container.Config{
289305
Image: utils.KongImage,
290-
Env: []string{
291-
"KONG_DATABASE=off",
292-
"KONG_DECLARATIVE_CONFIG=/home/kong/kong.yml",
293-
"KONG_DNS_ORDER=LAST,A,CNAME", // https://github.com/supabase/cli/issues/14
294-
"KONG_PLUGINS=request-transformer,cors",
295-
// Need to increase the nginx buffers in kong to avoid it rejecting the rather
296-
// sizeable response headers azure can generate
297-
// Ref: https://github.com/Kong/kong/issues/3974#issuecomment-482105126
298-
"KONG_NGINX_PROXY_PROXY_BUFFER_SIZE=160k",
299-
"KONG_NGINX_PROXY_PROXY_BUFFERS=64 160k",
300-
},
306+
Env: env,
301307
Entrypoint: []string{"sh", "-c", `cat <<'EOF' > /home/kong/kong.yml && ./docker-entrypoint.sh kong docker-start
302308
` + kongConfigBuf.String() + `
303309
EOF

internal/utils/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type (
8989
Api api `toml:"api"`
9090
Db db `toml:"db" mapstructure:"db"`
9191
Studio studio `toml:"studio"`
92+
Kong kong `toml:"kong"`
9293
Inbucket inbucket `toml:"inbucket"`
9394
Storage storage `toml:"storage"`
9495
Auth auth `toml:"auth" mapstructure:"auth"`
@@ -116,6 +117,10 @@ type (
116117
Port uint `toml:"port"`
117118
}
118119

120+
kong struct {
121+
NginxWorkerProcesses uint `toml:"nginx_worker_processes"`
122+
}
123+
119124
inbucket struct {
120125
Port uint `toml:"port"`
121126
SmtpPort uint `toml:"smtp_port"`

internal/utils/templates/init_config.test.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ major_version = 15
2525
# Port to use for Supabase Studio.
2626
port = 54323
2727

28+
[kong]
29+
# Number of nginx workers for handling requests. Set this to 1 to minimize memory usage.
30+
# Omitting it or setting it to 0 will autodetect based on the number of CPU cores.
31+
nginx_worker_processes = 1
32+
2833
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
2934
# are monitored, and you can view the emails that would have been sent from the web interface.
3035
[inbucket]

internal/utils/templates/init_config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ major_version = 15
2525
# Port to use for Supabase Studio.
2626
port = 54323
2727

28+
[kong]
29+
# Number of nginx workers for handling requests. Set this to 1 to minimize memory usage.
30+
# Omitting it or setting it to 0 will autodetect based on the number of CPU cores.
31+
nginx_worker_processes = 1
32+
2833
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
2934
# are monitored, and you can view the emails that would have been sent from the web interface.
3035
[inbucket]

0 commit comments

Comments
 (0)