-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
98 lines (77 loc) · 2.97 KB
/
Copy pathDockerfile
File metadata and controls
98 lines (77 loc) · 2.97 KB
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
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
################################################################################
# Create a stage for building the application.
ARG GO_VERSION=1.26.0
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
WORKDIR /workspace
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into
# the container.
ENV GOMODCACHE=/go/pkg/mod
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x
# This is the architecture you’re building for, which is passed in by the builder.
# Placing it here allows the previous steps to be cached across architectures.
ARG TARGETARCH
# Build the application.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage a bind mount to the current directory to avoid having to copy the
# source code into the container.
ENV GOCACHE=/root/.cache/go-build
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,target=. \
CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /target/ces-exporter ./
FROM alpine:3.21 AS classic
LABEL maintainer="hello@cloudogu.com" \
NAME="ces-exporter" \
VERSION="2.0.0"
ENV MODE=classic
# Install any runtime dependencies that are needed to run your application.
# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds.
RUN --mount=type=cache,target=/var/cache/apk \
apk update && \
apk upgrade && \
apk add \
ca-certificates \
tzdata \
bash \
openssh \
rsync \
nfs-utils \
btrfs-progs \
&& \
update-ca-certificates
# Configure SSH
RUN \
ssh-keygen -A && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
mkdir -p /root/.ssh && \
chmod -R 700 /root && \
chmod -R 600 /root/.ssh
COPY resources /
WORKDIR /
COPY --from=build /target/ces-exporter .
EXPOSE 8080
ENTRYPOINT ["/startup.sh"]
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot AS multinode
LABEL maintainer="hello@cloudogu.com" \
NAME="ces-exporter" \
VERSION="2.0.0"
ENV MODE=multinode
WORKDIR /
COPY --from=build /target/ces-exporter .
# the linter has a problem with the valid colon-syntax
# dockerfile_lint - ignore
USER 65532:65532
EXPOSE 8080
ENTRYPOINT ["/ces-exporter"]