From 04359e0b67e914b43a56803c8603291d0dec0d57 Mon Sep 17 00:00:00 2001 From: Chi Zhang Date: Wed, 11 Sep 2019 13:56:08 -0700 Subject: [PATCH 1/3] add log messages --- test/e2e/sampleapptestbase.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/e2e/sampleapptestbase.go b/test/e2e/sampleapptestbase.go index 97b7d500e93..00f357f5bb4 100644 --- a/test/e2e/sampleapptestbase.go +++ b/test/e2e/sampleapptestbase.go @@ -108,6 +108,8 @@ func prepareWorkDir(t *testing.T, srcDir, workDir string, preCommands []sampleap func pushDockerImage(t *testing.T, imagePath, workDir string) { t.Logf("Pushing docker image to: '%s'", imagePath) + t.Logf("image path is: %s", imagePath) + t.Logf("work dir is: %s", workDir) if output, err := exec.Command("docker", "build", "-t", imagePath, workDir).CombinedOutput(); err != nil { t.Fatalf("Error building docker image: %v", strings.TrimSpace(string(output))) } From 71e922ce59c1b0c935667f425ed53b488c3075d3 Mon Sep 17 00:00:00 2001 From: Chi Zhang Date: Wed, 11 Sep 2019 14:07:08 -0700 Subject: [PATCH 2/3] test --- .../hello-world/helloworld-go/Dockerfile | 28 +++++++++++-------- .../samples/hello-world/helloworld-go/go.mod | 3 ++ test/sampleapp/config.yaml | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 docs/serving/samples/hello-world/helloworld-go/go.mod diff --git a/docs/serving/samples/hello-world/helloworld-go/Dockerfile b/docs/serving/samples/hello-world/helloworld-go/Dockerfile index 5d4a0584a8f..61606cf03a2 100644 --- a/docs/serving/samples/hello-world/helloworld-go/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-go/Dockerfile @@ -1,24 +1,30 @@ # Use the offical Golang image to create a build artifact. # This is based on Debian and sets the GOPATH to /go. # https://hub.docker.com/_/golang -FROM golang:1.12 as builder +FROM golang:1.13 as builder + +# Create and change to the app directory. +WORKDIR /app + +# Retrieve application dependencies. +# This allows the container build to reuse cached dependencies. +COPY go.* ./ +RUN go mod download # Copy local code to the container image. -WORKDIR /go/src/github.com/knative/docs/helloworld -COPY . . +COPY . ./ -# Build the command inside the container. -# (You may fetch or manage dependencies here, -# either manually or with a tool like "godep".) -RUN CGO_ENABLED=0 GOOS=linux go build -v -o helloworld +# Build the binary. +RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server -# Use a Docker multi-stage build to create a lean production image. +# Use the official Alpine image for a lean production container. +# https://hub.docker.com/_/alpine # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds -FROM alpine +FROM alpine:3 RUN apk add --no-cache ca-certificates # Copy the binary to the production image from the builder stage. -COPY --from=builder /go/src/github.com/knative/docs/helloworld/helloworld /helloworld +COPY --from=builder /app/server /server # Run the web service on container startup. -CMD ["/helloworld"] +CMD ["/server"] \ No newline at end of file diff --git a/docs/serving/samples/hello-world/helloworld-go/go.mod b/docs/serving/samples/hello-world/helloworld-go/go.mod new file mode 100644 index 00000000000..2f2e86c7d02 --- /dev/null +++ b/docs/serving/samples/hello-world/helloworld-go/go.mod @@ -0,0 +1,3 @@ +module github.com/knative/docs/docs/serving/samples/hello-world/helloworld-go + +go 1.13 \ No newline at end of file diff --git a/test/sampleapp/config.yaml b/test/sampleapp/config.yaml index 049f2a7c8cf..8e33defddc7 100644 --- a/test/sampleapp/config.yaml +++ b/test/sampleapp/config.yaml @@ -14,6 +14,7 @@ languages: - "helloworld.go" - "service.yaml" - "Dockerfile" + - "go.mod" - language: "kotlin" expectedOutput: "Hello Kotlin Sample v1!" copies: From 690b80498a7c87376079d5dab55073182dd5cf2e Mon Sep 17 00:00:00 2001 From: Chi Zhang Date: Wed, 11 Sep 2019 14:16:17 -0700 Subject: [PATCH 3/3] remove mod read-only --- docs/serving/samples/hello-world/helloworld-go/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/serving/samples/hello-world/helloworld-go/Dockerfile b/docs/serving/samples/hello-world/helloworld-go/Dockerfile index 61606cf03a2..7f56bdd19b8 100644 --- a/docs/serving/samples/hello-world/helloworld-go/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-go/Dockerfile @@ -15,7 +15,7 @@ RUN go mod download COPY . ./ # Build the binary. -RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server +RUN CGO_ENABLED=0 GOOS=linux go build -v -o server # Use the official Alpine image for a lean production container. # https://hub.docker.com/_/alpine