chore: improve Dockerfile.
This commit is contained in:
18
Dockerfile
18
Dockerfile
@ -1,10 +1,26 @@
|
|||||||
FROM golang:1.12 as builder
|
FROM golang:1.13-alpine as builder
|
||||||
|
|
||||||
|
RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
|
||||||
|
&& update-ca-certificates \
|
||||||
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
WORKDIR /go/whoami
|
WORKDIR /go/whoami
|
||||||
|
|
||||||
|
# Download go modules
|
||||||
|
COPY go.mod .
|
||||||
|
COPY go.sum .
|
||||||
|
RUN GO111MODULE=on GOPROXY=https://proxy.golang.org go mod download
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN make build
|
RUN make build
|
||||||
|
|
||||||
# Create a minimal container to run a Golang static binary
|
# Create a minimal container to run a Golang static binary
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
|
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
COPY --from=builder /go/whoami/whoami .
|
COPY --from=builder /go/whoami/whoami .
|
||||||
|
|
||||||
ENTRYPOINT ["/whoami"]
|
ENTRYPOINT ["/whoami"]
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
5
Makefile
5
Makefile
@ -1,12 +1,9 @@
|
|||||||
.PHONY: default build dependencies image
|
.PHONY: default build image
|
||||||
|
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami
|
CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o whoami
|
||||||
|
|
||||||
dependencies:
|
|
||||||
go mod download
|
|
||||||
|
|
||||||
image:
|
image:
|
||||||
docker build -t containous/whoami .
|
docker build -t containous/whoami .
|
||||||
|
Reference in New Issue
Block a user