-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathDockerfile
102 lines (80 loc) · 2.46 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# The build mode (options: build, copy) passed in as a --build-arg. If build is specified, then the copy
# stage will be skipped and vice versa. The build mode builds the binary from the source files, while
# the copy mode copies in a pre-built binary.
ARG BUILDMODE=build
################################
# Base Stage #
# #
################################
FROM alpine:latest AS base
ARG USERNAME=aoc
ARG USER_UID=4317
RUN addgroup \
-g $USER_UID \
$USERNAME && \
adduser \
-D \
-g $USERNAME \
-h "/home/${USERNAME}"\
-G $USERNAME \
-u $USER_UID \
$USERNAME
RUN apk --update add ca-certificates
################################
# Build Stage #
# #
################################
FROM golang:1.23 AS prep-build
ARG TARGETARCH
# pass in the GOPROXY as a --build-arg (e.g. --build-arg GOPROXY=direct)
ARG GOPROXY
ENV GOPROXY=${GOPROXY}
# download go modules ahead to speed up the building
WORKDIR /workspace
COPY go.mod .
COPY go.sum .
RUN go mod download -x
# copy source
COPY . .
# build
RUN make ${TARGETARCH}-build
# move
RUN mv /workspace/build/linux/$TARGETARCH/aoc /workspace/awscollector
################################
# Copy Stage #
# #
################################
FROM scratch AS prep-copy
WORKDIR /workspace
ARG TARGETARCH
# copy artifacts
# always assume binary is created
COPY build/linux/$TARGETARCH/aoc /workspace/awscollector
COPY build/linux/$TARGETARCH/healthcheck /workspace/healthcheck
################################
# Packing Stage #
# #
################################
FROM prep-${BUILDMODE} AS package
COPY config.yaml /workspace/config/otel-config.yaml
COPY config/ /workspace/config/
################################
# Final Stage #
# #
################################
FROM scratch
ARG USERNAME=aoc
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
COPY --from=base /home/$USERNAME/ /home/$USERNAME
COPY --from=package /workspace/awscollector /awscollector
COPY --from=package /workspace/config/ /etc/
COPY --from=package /workspace/healthcheck /healthcheck
ENV RUN_IN_CONTAINER="True"
USER $USERNAME
# aws-sdk-go needs $HOME to look up shared credentials
ENV HOME=/home/$USERNAME
ENTRYPOINT ["/awscollector"]
CMD ["--config=/etc/otel-config.yaml"]
EXPOSE 4317 55681 2000