mirror of https://github.com/knative/docs.git
serving/samples: update helloworld-go to go:1.13 and go modules (#1774)
* serving/samples: update helloworld-go to go:1.13 and go modules * seving/samples: sync helloworld-go Dockerfile to README * alpine:3.10 => alpine:3 * serving/samples: helloworld-go name binary helloworld-server * serving/samples: simpler comment for go build in helloworld-go * serving/samples: helloworld-go README sync * serving/samples: fix up README * serving/samples: add go.mod to test config * serving/samples: Add instruction to create a go.mod
This commit is contained in:
parent
3a2dde05fc
commit
61d24a1196
|
@ -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"]
|
||||
|
|
|
@ -72,27 +72,33 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-go
|
|||
# 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"]
|
||||
```
|
||||
|
||||
1. Create a new file, `service.yaml` and copy the following service definition
|
||||
|
@ -115,6 +121,13 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-go
|
|||
value: "Go Sample v1"
|
||||
```
|
||||
|
||||
1. Use the go tool to create a
|
||||
[`go.mod`](https://github.com/golang/go/wiki/Modules#gomod) manifest.
|
||||
|
||||
```shell
|
||||
go mod init github.com/knative/docs/docs/serving/samples/hello-world/helloworld-go
|
||||
```
|
||||
|
||||
## Building and deploying the sample
|
||||
|
||||
Once you have recreated the sample code files (or used the files in the sample
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/knative/docs/docs/serving/samples/hello-world/helloworld-go
|
||||
|
||||
go 1.13
|
|
@ -11,6 +11,7 @@ languages:
|
|||
- language: "go"
|
||||
expectedOutput: "Hello Go Sample v1!"
|
||||
copies:
|
||||
- "go.mod"
|
||||
- "helloworld.go"
|
||||
- "service.yaml"
|
||||
- "Dockerfile"
|
||||
|
|
Loading…
Reference in New Issue