Merge pull request #3609 from jayjun/init

Start long running containers with --init with tests
This commit is contained in:
Jose Diaz-Gonzalez
2020-02-03 13:05:11 -05:00
committed by GitHub
18 changed files with 177 additions and 3 deletions

View File

@@ -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")

View File

@@ -0,0 +1 @@
/ go

View File

@@ -0,0 +1 @@
web: bin/web

View File

@@ -0,0 +1,4 @@
module dokku.me/web
// +heroku goVersion go1.12
go 1.12

View File

@@ -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")
}

View File

@@ -0,0 +1 @@
/ go

View File

@@ -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 ./...

View File

@@ -0,0 +1 @@
web: /go/bin/web

View File

@@ -0,0 +1,3 @@
module dokku.me/web
go 1.12

View File

@@ -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")
}

View File

@@ -0,0 +1 @@
/ go

View File

@@ -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", "--"]

View File

@@ -0,0 +1 @@
web: /go/bin/web

View File

@@ -0,0 +1,3 @@
module dokku.me/web
go 1.12

View File

@@ -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")
}

20
tests/unit/50_init_1.bats Normal file
View File

@@ -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 "<defunct>" "0"
}

20
tests/unit/50_init_2.bats Normal file
View File

@@ -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 "<defunct>" "0"
}

20
tests/unit/50_init_3.bats Normal file
View File

@@ -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 "<defunct>" "0"
}