-
Notifications
You must be signed in to change notification settings - Fork 1.3k
serving/samples: update helloworld-go to go:1.13 and go modules #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f68efcf
66b92cf
b0b4a3f
812a8ea
a7e68f6
e19ebe1
4484ccc
007e214
1930ac6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 . ./ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this should do the (I'm not attached to adding it - definitely makes things more complex, but it might be worth it.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added go mod download and modified go build to use -mod=readonly for strictness of the build. |
||
|
|
||
| # 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"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module github.com/knative/docs/docs/serving/samples/hello-world/helloworld-go | ||
|
|
||
| go 1.13 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an empty line after this line. Otherwise |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason not to use golang:1?
We have to keep updating this every 6 months otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that sometimes the minor version has significant change to best practices (e.g., modules) I think the clarity is worthwhile for the reader and motivation to update.