-
Notifications
You must be signed in to change notification settings - Fork 53
/
Dockerfile
73 lines (62 loc) · 2.21 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
ARG BASE_OS_IMAGE=registry.opensuse.org/opensuse/tumbleweed
ARG GO_VERSION=1.22
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS elemental-bin
ENV CGO_ENABLED=0
WORKDIR /src/
# Add specific dirs to the image so cache is not invalidated when modifying non go files
ADD go.mod .
ADD go.sum .
ADD vendor vendor
RUN go mod download
ADD cmd cmd
ADD internal internal
ADD pkg pkg
ADD main.go .
# Set arg/env after go mod download, otherwise we invalidate the cached layers due commit hash changes
ARG ELEMENTAL_VERSION=0.0.1
ARG ELEMENTAL_COMMIT=""
ENV ELEMENTAL_VERSION=${ELEMENTAL_VERSION}
ENV ELEMENTAL_COMMIT=${ELEMENTAL_COMMIT}
ARG TARGETOS
ARG TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go generate ./...
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
-ldflags "-w -s \
-X github.com/rancher/elemental-toolkit/v2/internal/version.version=${ELEMENTAL_VERSION} \
-X github.com/rancher/elemental-toolkit/v2/internal/version.gitCommit=${ELEMENTAL_COMMIT}" \
-o /usr/bin/elemental
FROM ${BASE_OS_IMAGE} AS elemental-toolkit
# This helps invalidate the cache on each build so the following steps are really run again getting the latest packages
# versions, as long as the elemental commit has changed
ARG ELEMENTAL_COMMIT=""
ENV ELEMENTAL_COMMIT=${ELEMENTAL_COMMIT}
ARG TARGETARCH
RUN ARCH=$(uname -m); \
[[ "${ARCH}" == "aarch64" ]] && ARCH="arm64"; \
zypper --non-interactive removerepo repo-update || true; \
zypper install -y --no-recommends xfsprogs \
parted \
util-linux-systemd \
e2fsprogs \
udev \
rsync \
grub2 \
dosfstools \
grub2-${ARCH}-efi \
squashfs \
mtools \
xorriso \
cosign \
gptfdisk \
patterns-microos-selinux \
btrfsprogs \
lvm2 && \
zypper cc -a
# Copy the built CLI
COPY --from=elemental-bin /usr/bin/elemental /usr/bin/elemental
# Fix for blkid only using udev on opensuse
RUN echo "EVALUATE=scan" >> /etc/blkid.conf
ENTRYPOINT ["/usr/bin/elemental"]
# Add to /system/oem folder so install/upgrade/reset hooks will run when running this container.
# Needed for boot-assessment
COPY pkg/features/embedded/cloud-config-essentials/system/oem /system/oem/