forked from rancher/elemental-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
55 lines (50 loc) · 2.11 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
FROM registry.suse.com/bci/golang:1.19 AS build
RUN zypper -n install -l openssl-devel
WORKDIR /src
COPY go.mod go.sum /src/
RUN go mod download
COPY cmd/operator/main.go /src/
COPY api /src/api
COPY controllers /src/controllers
COPY pkg /src/pkg
COPY cmd /src/cmd
# Set arg/env after go mod download, otherwise we invalidate the cached layers due to the commit changing easily
FROM build AS build-operator
ARG TAG=v0.0.0
ARG COMMIT=""
ARG COMMITDATE=""
ENV CGO_ENABLED=0
RUN go build \
-ldflags "-w -s \
-X github.com/rancher/elemental-operator/pkg/version.Version=$TAG \
-X github.com/rancher/elemental-operator/pkg/version.Commit=$COMMIT \
-X github.com/rancher/elemental-operator/pkg/version.CommitDate=$COMMITDATE" \
-o /usr/sbin/elemental-operator ./cmd/operator
FROM build AS build-register
ARG TAG=v0.0.0
ARG COMMIT=""
ARG COMMITDATE=""
ENV CGO_ENABLED=1
RUN go build \
-ldflags "-w -s \
-X github.com/rancher/elemental-operator/pkg/version.Version=$TAG \
-X github.com/rancher/elemental-operator/pkg/version.Commit=$COMMIT \
-X github.com/rancher/elemental-operator/pkg/version.CommitDate=$COMMITDATE" \
-o /usr/sbin/elemental-register ./cmd/register
ENV CGO_ENABLED=0
RUN go build \
-ldflags "-w -s \
-X github.com/rancher/elemental-operator/pkg/version.Version=$TAG \
-X github.com/rancher/elemental-operator/pkg/version.Commit=$COMMIT \
-X github.com/rancher/elemental-operator/pkg/version.CommitDate=$COMMITDATE" \
-o /usr/sbin/elemental-support ./cmd/support
FROM scratch AS elemental-operator
COPY --from=build /var/lib/ca-certificates/ca-bundle.pem /etc/ssl/certs/ca-certificates.crt
COPY --from=build-operator /usr/sbin/elemental-operator /usr/sbin/elemental-operator
USER 10010:10010
ENTRYPOINT ["/usr/sbin/elemental-operator"]
FROM scratch AS elemental-register
COPY --from=build /var/lib/ca-certificates/ca-bundle.pem /etc/ssl/certs/ca-certificates.crt
COPY --from=build-register /usr/sbin/elemental-register /usr/sbin/elemental-register
COPY --from=build-register /usr/sbin/elemental-support /usr/sbin/elemental-support
ENTRYPOINT ["/usr/sbin/elemental-register"]