Skip to content

Commit a95f814

Browse files
committed
Added Dockerfile
1 parent 0b06423 commit a95f814

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Built following https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
2+
3+
# STEP 1 build executable binary
4+
FROM golang:alpine as builder
5+
# Install SSL ca certificates
6+
RUN apk update && apk add git && apk add ca-certificates
7+
# Create appuser
8+
RUN adduser -D -g '' appuser
9+
COPY . $GOPATH/src/mypackage/myapp/
10+
WORKDIR $GOPATH/src/mypackage/myapp/
11+
#get dependancies
12+
RUN go get -d -v
13+
#build the binary
14+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/alertmanager-discord
15+
16+
17+
# STEP 2 build a small image
18+
# start from scratch
19+
FROM scratch
20+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
21+
COPY --from=builder /etc/passwd /etc/passwd
22+
# Copy our static executable
23+
COPY --from=builder /go/bin/alertmanager-discord /go/bin/alertmanager-discord
24+
USER appuser
25+
ENTRYPOINT ["/go/bin/alertmanager-discord"]
26+

0 commit comments

Comments
 (0)