diff --git a/docs/serving/samples/hello-world/helloworld-go/Dockerfile b/docs/serving/samples/hello-world/helloworld-go/Dockerfile index 5d4a0584a8f..7f56bdd19b8 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 -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/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))) } 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: