-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
56 lines (44 loc) · 1.14 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
ARG GO_VERSION=1.19.0
###########################
# Build executable binary #
###########################
FROM golang:${GO_VERSION}-alpine AS builder
# Git is required for fetching the dependencies
RUN apk update && \
apk add --no-cache git ca-certificates && \
update-ca-certificates
# Create appuser
ENV USER=otel
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR /src
# Fetch dependencies
COPY ./go.mod ./go.sum ./
RUN go mod download
COPY *.go ./
# Build the binary
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
RUN go build -ldflags="-w -s" -o /otel-action
#########################
# Build the small image #
#########################
FROM scratch
LABEL maintainer="MNThomson"
# Setup SSL certs
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Setup user
COPY --from=builder /etc/passwd /etc/group /etc/
USER otel:otel
# Copy the static executable
COPY --from=builder /otel-action /otel-action
# Run the binary
ENTRYPOINT ["/otel-action"]