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") 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..9515f52c2 --- /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 auxf + 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" +}