From 26e3232f2c50c1378e92409d2c0ad6541db85479 Mon Sep 17 00:00:00 2001 From: Tan Jay Jun Date: Sat, 7 Sep 2019 16:47:31 +0800 Subject: [PATCH 1/3] tests: check orphaned processes are reaped --- tests/apps/zombies-buildpack/CHECKS | 1 + tests/apps/zombies-buildpack/Procfile | 1 + tests/apps/zombies-buildpack/go.mod | 4 +++ tests/apps/zombies-buildpack/web.go | 27 +++++++++++++++++++ tests/apps/zombies-dockerfile-no-tini/CHECKS | 1 + .../zombies-dockerfile-no-tini/Dockerfile | 6 +++++ .../apps/zombies-dockerfile-no-tini/Procfile | 1 + tests/apps/zombies-dockerfile-no-tini/go.mod | 3 +++ tests/apps/zombies-dockerfile-no-tini/web.go | 27 +++++++++++++++++++ tests/apps/zombies-dockerfile-tini/CHECKS | 1 + tests/apps/zombies-dockerfile-tini/Dockerfile | 11 ++++++++ tests/apps/zombies-dockerfile-tini/Procfile | 1 + tests/apps/zombies-dockerfile-tini/go.mod | 3 +++ tests/apps/zombies-dockerfile-tini/web.go | 27 +++++++++++++++++++ tests/unit/50_init_1.bats | 20 ++++++++++++++ tests/unit/50_init_2.bats | 20 ++++++++++++++ tests/unit/50_init_3.bats | 20 ++++++++++++++ 17 files changed, 174 insertions(+) create mode 100644 tests/apps/zombies-buildpack/CHECKS create mode 100644 tests/apps/zombies-buildpack/Procfile create mode 100644 tests/apps/zombies-buildpack/go.mod create mode 100644 tests/apps/zombies-buildpack/web.go create mode 100644 tests/apps/zombies-dockerfile-no-tini/CHECKS create mode 100644 tests/apps/zombies-dockerfile-no-tini/Dockerfile create mode 100644 tests/apps/zombies-dockerfile-no-tini/Procfile create mode 100644 tests/apps/zombies-dockerfile-no-tini/go.mod create mode 100644 tests/apps/zombies-dockerfile-no-tini/web.go create mode 100644 tests/apps/zombies-dockerfile-tini/CHECKS create mode 100644 tests/apps/zombies-dockerfile-tini/Dockerfile create mode 100644 tests/apps/zombies-dockerfile-tini/Procfile create mode 100644 tests/apps/zombies-dockerfile-tini/go.mod create mode 100644 tests/apps/zombies-dockerfile-tini/web.go create mode 100644 tests/unit/50_init_1.bats create mode 100644 tests/unit/50_init_2.bats create mode 100644 tests/unit/50_init_3.bats diff --git a/tests/apps/zombies-buildpack/CHECKS b/tests/apps/zombies-buildpack/CHECKS new file mode 100644 index 000000000..52e1189c7 --- /dev/null +++ b/tests/apps/zombies-buildpack/CHECKS @@ -0,0 +1 @@ +/ go diff --git a/tests/apps/zombies-buildpack/Procfile b/tests/apps/zombies-buildpack/Procfile new file mode 100644 index 000000000..bb58ffb7a --- /dev/null +++ b/tests/apps/zombies-buildpack/Procfile @@ -0,0 +1 @@ +web: bin/web diff --git a/tests/apps/zombies-buildpack/go.mod b/tests/apps/zombies-buildpack/go.mod new file mode 100644 index 000000000..d0bf47916 --- /dev/null +++ b/tests/apps/zombies-buildpack/go.mod @@ -0,0 +1,4 @@ +module dokku.me/web + +// +heroku goVersion go1.12 +go 1.12 diff --git a/tests/apps/zombies-buildpack/web.go b/tests/apps/zombies-buildpack/web.go new file mode 100644 index 000000000..101bdce35 --- /dev/null +++ b/tests/apps/zombies-buildpack/web.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "os/exec" +) + +func main() { + // spawn an orphaned zombie + err := exec.Command("/bin/bash", "-c", "/bin/false &").Run() + if err != nil { + panic(err) + } + + http.HandleFunc("/", hello) + fmt.Println("listening...") + err = http.ListenAndServe(":"+os.Getenv("PORT"), nil) + if err != nil { + panic(err) + } +} + +func hello(res http.ResponseWriter, req *http.Request) { + fmt.Fprintln(res, "go") +} diff --git a/tests/apps/zombies-dockerfile-no-tini/CHECKS b/tests/apps/zombies-dockerfile-no-tini/CHECKS new file mode 100644 index 000000000..52e1189c7 --- /dev/null +++ b/tests/apps/zombies-dockerfile-no-tini/CHECKS @@ -0,0 +1 @@ +/ go diff --git a/tests/apps/zombies-dockerfile-no-tini/Dockerfile b/tests/apps/zombies-dockerfile-no-tini/Dockerfile new file mode 100644 index 000000000..3a126d5e7 --- /dev/null +++ b/tests/apps/zombies-dockerfile-no-tini/Dockerfile @@ -0,0 +1,6 @@ +FROM golang:1.12 + +ADD . /go/src/github.com/dokku/apps/web +WORKDIR /go/src/github.com/dokku/apps/web + +RUN go install -v ./... diff --git a/tests/apps/zombies-dockerfile-no-tini/Procfile b/tests/apps/zombies-dockerfile-no-tini/Procfile new file mode 100644 index 000000000..eabc37787 --- /dev/null +++ b/tests/apps/zombies-dockerfile-no-tini/Procfile @@ -0,0 +1 @@ +web: /go/bin/web diff --git a/tests/apps/zombies-dockerfile-no-tini/go.mod b/tests/apps/zombies-dockerfile-no-tini/go.mod new file mode 100644 index 000000000..232b9d2a1 --- /dev/null +++ b/tests/apps/zombies-dockerfile-no-tini/go.mod @@ -0,0 +1,3 @@ +module dokku.me/web + +go 1.12 diff --git a/tests/apps/zombies-dockerfile-no-tini/web.go b/tests/apps/zombies-dockerfile-no-tini/web.go new file mode 100644 index 000000000..101bdce35 --- /dev/null +++ b/tests/apps/zombies-dockerfile-no-tini/web.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "os/exec" +) + +func main() { + // spawn an orphaned zombie + err := exec.Command("/bin/bash", "-c", "/bin/false &").Run() + if err != nil { + panic(err) + } + + http.HandleFunc("/", hello) + fmt.Println("listening...") + err = http.ListenAndServe(":"+os.Getenv("PORT"), nil) + if err != nil { + panic(err) + } +} + +func hello(res http.ResponseWriter, req *http.Request) { + fmt.Fprintln(res, "go") +} diff --git a/tests/apps/zombies-dockerfile-tini/CHECKS b/tests/apps/zombies-dockerfile-tini/CHECKS new file mode 100644 index 000000000..52e1189c7 --- /dev/null +++ b/tests/apps/zombies-dockerfile-tini/CHECKS @@ -0,0 +1 @@ +/ go diff --git a/tests/apps/zombies-dockerfile-tini/Dockerfile b/tests/apps/zombies-dockerfile-tini/Dockerfile new file mode 100644 index 000000000..0e46c9a30 --- /dev/null +++ b/tests/apps/zombies-dockerfile-tini/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.12 + +ADD . /go/src/github.com/dokku/apps/web +WORKDIR /go/src/github.com/dokku/apps/web + +RUN go install -v ./... + +ENV TINI_VERSION v0.18.0 +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini +RUN chmod +x /tini +ENTRYPOINT ["/tini", "--"] diff --git a/tests/apps/zombies-dockerfile-tini/Procfile b/tests/apps/zombies-dockerfile-tini/Procfile new file mode 100644 index 000000000..eabc37787 --- /dev/null +++ b/tests/apps/zombies-dockerfile-tini/Procfile @@ -0,0 +1 @@ +web: /go/bin/web diff --git a/tests/apps/zombies-dockerfile-tini/go.mod b/tests/apps/zombies-dockerfile-tini/go.mod new file mode 100644 index 000000000..232b9d2a1 --- /dev/null +++ b/tests/apps/zombies-dockerfile-tini/go.mod @@ -0,0 +1,3 @@ +module dokku.me/web + +go 1.12 diff --git a/tests/apps/zombies-dockerfile-tini/web.go b/tests/apps/zombies-dockerfile-tini/web.go new file mode 100644 index 000000000..101bdce35 --- /dev/null +++ b/tests/apps/zombies-dockerfile-tini/web.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "os/exec" +) + +func main() { + // spawn an orphaned zombie + err := exec.Command("/bin/bash", "-c", "/bin/false &").Run() + if err != nil { + panic(err) + } + + http.HandleFunc("/", hello) + fmt.Println("listening...") + err = http.ListenAndServe(":"+os.Getenv("PORT"), nil) + if err != nil { + panic(err) + } +} + +func hello(res http.ResponseWriter, req *http.Request) { + fmt.Fprintln(res, "go") +} diff --git a/tests/unit/50_init_1.bats b/tests/unit/50_init_1.bats new file mode 100644 index 000000000..2572c9140 --- /dev/null +++ b/tests/unit/50_init_1.bats @@ -0,0 +1,20 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(init) buildpack" { + deploy_app zombies-buildpack + run ps ax + echo "output: $output" + assert_output_contains "" "0" +} diff --git a/tests/unit/50_init_2.bats b/tests/unit/50_init_2.bats new file mode 100644 index 000000000..550f11bf9 --- /dev/null +++ b/tests/unit/50_init_2.bats @@ -0,0 +1,20 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(init) dockerfile no tini" { + deploy_app zombies-dockerfile-no-tini + run ps ax + echo "output: $output" + assert_output_contains "" "0" +} diff --git a/tests/unit/50_init_3.bats b/tests/unit/50_init_3.bats new file mode 100644 index 000000000..71ad74035 --- /dev/null +++ b/tests/unit/50_init_3.bats @@ -0,0 +1,20 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(init) dockerfile with tini" { + deploy_app zombies-dockerfile-tini + run ps ax + echo "output: $output" + assert_output_contains "" "0" +} From e425092d009ea9f9aa7ef7ce428daddf129f077e Mon Sep 17 00:00:00 2001 From: Tan Jay Jun Date: Sat, 3 Aug 2019 19:50:22 +0800 Subject: [PATCH 2/3] fix: reap orphaned processes with --init --- plugins/scheduler-docker-local/scheduler-deploy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index 2b6705f26..d87c46b41 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -98,16 +98,16 @@ scheduler-docker-local-scheduler-deploy() { START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") if [[ "$DOKKU_NETWORK_BIND_ALL" == "false" ]]; then # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container run --label=com.dokku.container-type=deploy "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --detach --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) + cid=$("$DOCKER_BIN" container run --label=com.dokku.container-type=deploy "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --init --detach --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) else # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container run --label=com.dokku.container-type=deploy "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --detach $DOKKU_DOCKER_PORT_ARGS --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) + cid=$("$DOCKER_BIN" container run --label=com.dokku.container-type=deploy "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --init --detach $DOKKU_DOCKER_PORT_ARGS --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) fi else START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH") # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container run --label=com.dokku.container-type=deploy "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --detach "${ARG_ARRAY[@]}" $IMAGE $START_CMD) + cid=$("$DOCKER_BIN" container run --label=com.dokku.container-type=deploy "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --init --detach "${ARG_ARRAY[@]}" $IMAGE $START_CMD) fi ipaddr=$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$cid") From 414ea55ca8f74a02deb82d6cd08dbbe278273792 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 3 Feb 2020 12:10:39 -0500 Subject: [PATCH 3/3] tests: use 'ps auxf' --- tests/unit/50_init_2.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/50_init_2.bats b/tests/unit/50_init_2.bats index 550f11bf9..9515f52c2 100644 --- a/tests/unit/50_init_2.bats +++ b/tests/unit/50_init_2.bats @@ -14,7 +14,7 @@ teardown() { @test "(init) dockerfile no tini" { deploy_app zombies-dockerfile-no-tini - run ps ax + run ps auxf echo "output: $output" assert_output_contains "" "0" }