-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (62 loc) · 2.81 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (62 loc) · 2.81 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
# Build the frontend assets
FROM node:24-alpine AS frontend
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web/ ./
RUN npm run build
# Prepare writable dirs for distroless runtime
FROM alpine:3.24 AS prep
RUN mkdir -p /outfs/work /outfs/tmp \
# Change group ownership of /work and /tmp to GID 0 (root group),
# because OpenShift assigns containers a random UID but always includes them in group 0.
&& chgrp -R 0 /outfs/work /outfs/tmp \
# Give group 0 read/write/execute (X only applies to dirs or already-executable files).
# This makes the dirs writable by arbitrary UIDs in group 0.
&& chmod -R g+rwX /outfs/work /outfs/tmp \
# Set the setgid bit on the dirs so that any new files/dirs created inside
# will inherit group 0 instead of the creator's primary group.
&& chmod g+s /outfs/work /outfs/tmp
# Build the manager binary
FROM golang:1.26 AS builder
ARG TARGETOS
ARG TARGETARCH
ARG LDFLAGS="-s -w"
ENV CGO_ENABLED=0
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY internal/ internal
COPY --from=frontend /web/dist web/dist
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="$LDFLAGS" -a -o heartbeats main.go
RUN mkdir -p /outfs/work /outfs/tmp \
# Change group ownership of /work and /tmp to GID 0 (root group),
# because OpenShift assigns containers a random UID but always includes them in group 0.
&& chgrp -R 0 /outfs/work /outfs/tmp \
# Give group 0 read/write/execute (X only applies to dirs or already-executable files).
# This makes the dirs writable by arbitrary UIDs in group 0.
&& chmod -R g+rwX /outfs/work /outfs/tmp \
# Set the setgid bit on the dirs so that any new files/dirs created inside
# will inherit group 0 instead of the creator's primary group.
&& chmod g+s /outfs/work /outfs/tmp
# 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
COPY --from=prep /outfs/work /work
COPY --from=prep /outfs/tmp /tmp
ENV HOME=/tmp
WORKDIR /work
COPY --from=builder /workspace/heartbeats .
USER 65532:65532
ENTRYPOINT ["/heartbeats"]