Skip to content

Commit 3554fc8

Browse files
committed
Prevent k8s volume path override leaking into the nginx template
1 parent e9eb10f commit 3554fc8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

k8s-init.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ mkdir "${K8S_VOLUME_PATH}/content"
2020
cp -a /etc/nginx/http.d "${K8S_VOLUME_PATH}/config"
2121
cp -a "${NGINX_SERVER_ROOT}" "${K8S_VOLUME_PATH}/content"
2222

23-
export OLD_NGINX_SERVER_ROOT="${NGINX_SERVER_ROOT}"
24-
export NGINX_SERVER_ROOT=${K8S_VOLUME_PATH}/content/html
25-
/templater.sh
23+
(
24+
export OLD_NGINX_SERVER_ROOT="${NGINX_SERVER_ROOT}"
25+
export NGINX_SERVER_ROOT=${K8S_VOLUME_PATH}/content/html
26+
/templater.sh
27+
)
2628

2729
render_templates "${K8S_VOLUME_PATH}/config/http.d/default.conf.tmpl"

tests/k8s.bats

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ teardown_file() {
1616
docker volume rm -f "${docker_volume}" || true
1717
}
1818

19-
@test "k8s-init" {
19+
@test "k8s-init check copy and render" {
2020
# Fix volume permissions to match K8s behaviour
2121
docker run --rm -v "${docker_volume}:/volume" busybox install -d -o root -g 2000 -m 2775 /volume
2222

@@ -30,10 +30,16 @@ teardown_file() {
3030
assert_line '/volume/config/http.d/default.conf'
3131
assert_line '/volume/content/html/env-config.js'
3232
assert_line '/volume/content/html/env-config2.js'
33+
}
34+
35+
@test "k8s-init check nginx default.conf" {
36+
# Don't need to redo the permissions and k8s-init since no parallelize is set in this file
3337

34-
# assert_output --regexp '/volume/config/http\.d/default\.conf[^.]'
35-
# assert_output --regexp '/volume/content/html/env-config\.js[^.]'
36-
# assert_output --regexp '/volume/content/html/env-config2\.js[^.]'
38+
# Print the content of nginx default.conf
39+
run docker run --rm -v "${docker_volume}:/volume" busybox cat /volume/config/http.d/default.conf
40+
41+
# diag "${output}"
42+
assert_line -p 'root /var/www/html;'
3743
}
3844

3945
@test "k8s-nginx" {

0 commit comments

Comments
 (0)