Skip to content

Commit d5e52e8

Browse files
committed
Rewrite the image builder in Golang
1 parent b3af0e6 commit d5e52e8

File tree

19 files changed

+569
-401
lines changed

19 files changed

+569
-401
lines changed

Dockerfile

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,29 @@ RUN \
2424
--mount=type=cache,target=/root/.cache/go-build \
2525
CGO_ENABLED=0 go build -o /go/bin/init -v --ldflags '-s -w -extldflags=-static'
2626

27+
# =========================================================
28+
FROM golang:1.25.2-alpine AS imager-build
29+
WORKDIR /go/src
30+
COPY imager/go.mod imager/go.sum ./
31+
RUN go mod download
32+
COPY imager .
33+
RUN \
34+
--mount=type=cache,target=/root/.cache/go-build \
35+
go generate -v ./... && \
36+
go test && \
37+
CGO_ENABLED=0 go build -o /go/bin/imager -v --ldflags '-s -w -extldflags=-static' cmd/main.go
38+
2739
# =========================================================
2840
FROM alpine:3.22.2 AS alpine-base
2941

3042
# =========================================================
3143
FROM alpine-base AS imager
32-
SHELL ["/bin/ash", "-euxo", "pipefail", "-c"]
33-
RUN \
34-
echo "@edge-community https://dl-cdn.alpinelinux.org/alpine/edge/community" >>/etc/apk/repositories && \
35-
apk add --no-cache \
36-
bash \
37-
binutils \
38-
coreutils \
39-
cpio \
40-
dosfstools \
41-
findutils \
42-
mtools \
43-
pigz \
44-
qemu-img \
45-
sfdisk \
46-
xorriso \
47-
zstd \
48-
xz \
49-
systemd-efistub@edge-community
44+
RUN apk add --no-cache binutils systemd-efistub
45+
# TODO: embed init
5046
COPY --from=init /go/bin/init /usr/share/claylinux/init
51-
COPY build-image.sh /usr/bin/build-image
47+
COPY --from=imager-build /go/bin/imager /bin/imager
5248
WORKDIR /out
53-
ENTRYPOINT ["build-image"]
49+
ENTRYPOINT ["/bin/imager"]
5450

5551
# =========================================================
5652
FROM alpine-base AS bootable-alpine-rootfs
@@ -110,14 +106,14 @@ RUN if [ "$UCODE" != "none" ]; then apk add --no-cache "${UCODE}-ucode"; fi
110106
# hadolint ignore=DL3006
111107
FROM imager AS test
112108
ARG FORMAT=efi
113-
RUN --mount=from=test-rootfs,target=/system build-image --format "$FORMAT"
109+
RUN --mount=from=test-rootfs,target=/system /bin/imager --format "$FORMAT"
114110

115111
# =========================================================
116112
# Generate a qemu image running our custom OS image
117113
FROM alpine-base AS emulator
118114
RUN apk add --no-cache bash qemu-system-x86_64 ovmf
119115
COPY emulator.sh /entrypoint
120-
ENTRYPOINT ["/entrypoint"]
121116
COPY --from=test /out /images
122117
ARG FORMAT
123118
ENV FORMAT="$FORMAT"
119+
ENTRYPOINT ["/entrypoint"]

0 commit comments

Comments
 (0)