mirror of https://github.com/knative/docs.git
serving/samples/helloworld-go: simplify and standardize Dockerfile (#508)
This commit is contained in:
parent
382ed049e0
commit
f2518ca45b
|
@ -1,17 +1,25 @@
|
||||||
# Start from a Debian image with the latest version of Go installed
|
# Use the offical Golang image to create a build artifact.
|
||||||
# and a workspace (GOPATH) configured at /go.
|
# This is based on Debian and sets the GOPATH to /go.
|
||||||
FROM golang
|
FROM golang as builder
|
||||||
|
|
||||||
# Copy the local package files to the container's workspace.
|
# Copy local code to the container image.
|
||||||
ADD . /go/src/github.com/knative/docs/helloworld
|
COPY . /go/src/github.com/knative/docs/helloworld
|
||||||
|
|
||||||
# Build the outyet command inside the container.
|
# Build the outyet command inside the container.
|
||||||
# (You may fetch or manage dependencies here,
|
# (You may fetch or manage dependencies here,
|
||||||
# either manually or with a tool like "godep".)
|
# either manually or with a tool like "godep".)
|
||||||
RUN go install github.com/knative/docs/helloworld
|
RUN go install github.com/knative/docs/helloworld
|
||||||
|
|
||||||
# Run the outyet command by default when the container starts.
|
# Use a Docker multi-stage build to create a lean production image.
|
||||||
ENTRYPOINT ["/go/bin/helloworld"]
|
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
# Document that the service listens on port 8080.
|
# Copy the binary to the production image from the builder stage.
|
||||||
EXPOSE 8080
|
COPY --from=builder /go/bin/helloworld /helloworld
|
||||||
|
|
||||||
|
# Configure and document the service HTTP port.
|
||||||
|
ENV PORT 8080
|
||||||
|
EXPOSE $PORT
|
||||||
|
|
||||||
|
# Run the web service on container startup.
|
||||||
|
CMD ["/helloworld"]
|
||||||
|
|
|
@ -59,23 +59,31 @@ following instructions recreate the source files from this folder.
|
||||||
[Deploying Go servers with Docker](https://blog.golang.org/docker).
|
[Deploying Go servers with Docker](https://blog.golang.org/docker).
|
||||||
|
|
||||||
```docker
|
```docker
|
||||||
# Start from a Debian image with the latest version of Go installed
|
# Use the offical Golang image to create a build artifact.
|
||||||
# and a workspace (GOPATH) configured at /go.
|
# This is based on Debian and sets the GOPATH to /go.
|
||||||
FROM golang
|
FROM golang as builder
|
||||||
|
|
||||||
# Copy the local package files to the container's workspace.
|
# Copy local code to the container image.
|
||||||
ADD . /go/src/github.com/knative/docs/helloworld
|
COPY . /go/src/github.com/knative/docs/helloworld
|
||||||
|
|
||||||
# Build the helloworld command inside the container.
|
# Build the outyet command inside the container.
|
||||||
# (You may fetch or manage dependencies here,
|
# (You may fetch or manage dependencies here,
|
||||||
# either manually or with a tool like "godep".)
|
# either manually or with a tool like "godep".)
|
||||||
RUN go install github.com/knative/docs/helloworld
|
RUN go install github.com/knative/docs/helloworld
|
||||||
|
|
||||||
# Run the helloworld command by default when the container starts.
|
# Use a Docker multi-stage build to create a lean production image.
|
||||||
ENTRYPOINT /go/bin/helloworld
|
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
# Document that the service listens on port 8080.
|
# Copy the binary to the production image from the builder stage.
|
||||||
EXPOSE 8080
|
COPY --from=builder /go/bin/helloworld /helloworld
|
||||||
|
|
||||||
|
# Configure and document the service HTTP port.
|
||||||
|
ENV PORT 8080
|
||||||
|
EXPOSE $PORT
|
||||||
|
|
||||||
|
# Run the web service on container startup.
|
||||||
|
CMD ["/helloworld"]
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create a new file, `service.yaml` and copy the following service definition
|
1. Create a new file, `service.yaml` and copy the following service definition
|
||||||
|
|
Loading…
Reference in New Issue