Last active
March 19, 2019 08:36
-
-
Save bgadrian/4594d454ec718fc22d1891b54e902e68 to your computer and use it in GitHub Desktop.
Multi phase Go 1.11 module builder and scratch container for a swagger web service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.11.1 AS builder | |
WORKDIR /src | |
#avoid downloading the dependencies on succesive builds | |
COPY go.mod go.sum ./ | |
RUN go mod download | |
RUN go mod verify | |
COPY . . | |
RUN mkdir -p ./build/ | |
#GO111MODULE=on is optional, but just in case you want to put the project inside the GOPATH ... | |
RUN env GO111MODULE=on go test -race ./... | |
#compiling without CGO, so we do not depend on libraries that are missing on scratch | |
RUN env GO111MODULE=on CGO_ENABLED=0 go build -o ./build/pseudoservice ./cmd/pseudo-service-server/main.go | |
FROM scratch | |
COPY --from=builder /src/build/pseudoservice . | |
ENV PORT=8080 | |
EXPOSE 8080 | |
#example params for a goswagger.io generated service | |
#listening on all interfaces 0.0.0.0 is important! | |
ENTRYPOINT ["./pseudoservice", "--read-timeout=1s", "--write-timeout=1s", "--keep-alive=15s", "--listen-limit=1024", "--max-header-size=3KiB", "--host=0.0.0.0"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because scratch does not have SH or other utilities, see here how can you debug it:
https://medium.com/@rothgar/how-to-debug-a-running-docker-container-from-a-separate-container-983f11740dc6