-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
39 lines (26 loc) · 813 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# STEP 1 build executable binary
# golang 1.20
FROM golang:1.20.6-alpine3.18 as builder
# Install git, Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
# Create appuser
RUN adduser -D -g '' appuser
WORKDIR $GOPATH/src/mypackage/epoch/
COPY . .
# Fetch dependencies.
RUN go get -d -v
# Build the binary
RUN GITREV=$(git rev-parse --short HEAD) && \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s -X main.Version=$GITREV" -a -installsuffix cgo -o /go/bin/epoch .
##
# STEP 2 build a small image
FROM scratch
# Import from builder.
COPY --from=builder /etc/passwd /etc/passwd
# Copy our static executable
COPY --from=builder /go/bin/epoch /go/bin/epoch
# Use an unprivileged user.
USER appuser
# Run the hello binary.
ENTRYPOINT ["/go/bin/epoch"]
EXPOSE 8080