-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile.build
More file actions
83 lines (66 loc) · 2.25 KB
/
Dockerfile.build
File metadata and controls
83 lines (66 loc) · 2.25 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
### builder
# Build the binary
# TODO this needs to match go.mod. Unsure how they can be
# kept in sync.
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
ARG GOPATH
ARG GOCACHE
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG CC
RUN printf "Building for TARGETPLATFORM=${TARGETPLATFORM}" \
&& printf ", TARGETARCH=${TARGETARCH}" \
&& printf ", TARGETOS=${TARGETOS}" \
&& printf ", TARGETVARIANT=${TARGETVARIANT} \n" \
&& printf "With 'uname -s': $(uname -s) and 'uname -m': $(uname -m)"
# Install cross-compilation dependencies
RUN apt-get update && \
apt-get install -y g++-aarch64-linux-gnu && \
rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
# TODO
# We currently have a lot of variance in directory structure.
# This is annoying for Dockerfile design; we can't just consistently
# copy the same set of files. Enforcing pkg/ and internal/ only across
# the board would maybe help.
# Original also had this copying to GOPATH, e.g.
# COPY cmd $GOPATH/src/github.com/OpenCHAMI/power-control/v2/cmd
# I've encountered enough Dockerfiles that just copy it to workdir
COPY cmd cmd
COPY api api
COPY internal internal
COPY go.mod go.mod
COPY go.sum go.sum
# TODO
# These are more for the final image. Unsure if we need them for build.
# At worst they're just some extra dead weight, pruning them later is easy, and it's not like we really care about the size of the build image
COPY configs configs
COPY scripts scripts
COPY migrations migrations
# Build
ARG CGO_ENABLED
RUN mkdir bin
# Use shell parameter expansion to add -ldflags if CC is set to specify the external linker
RUN CGO_ENABLED="${CGO_ENABLED}" \
GOOS=linux \
GOARCH="${TARGETARCH}" \
CC="${CC}" \
GO111MODULE=on \
go build ${CC:+-ldflags="-extld=$CC"} -v -o bin/power-control ./cmd/power-control
### release image
# TODO seems kinda off that we don't pin wolfi or tini, but whatever
FROM chainguard/wolfi-base:latest AS main
RUN set -ex \
&& apk update \
&& apk add --no-cache tini \
&& rm -rf /var/cache/apk/* \
&& rm -rf /tmp/*
WORKDIR /
COPY --from=builder /workspace/bin/power-control /usr/local/bin/
COPY configs configs
COPY migrations migrations
#nobody 65534:65534
USER 65534:65534
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/power-control"]