Skip to content

Commit 9042d70

Browse files
committed
Rewrite the image builder in Golang
1 parent 23ddc20 commit 9042d70

File tree

16 files changed

+425
-402
lines changed

16 files changed

+425
-402
lines changed

Dockerfile

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,27 @@ 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.24.5-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+
#COPY --from=init /go/bin/init /usr/share/claylinux/init
34+
RUN \
35+
--mount=type=cache,target=/root/.cache/go-build \
36+
go generate -v ./... && \
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.1 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
50-
COPY --from=init /go/bin/init /usr/share/claylinux/init
51-
COPY build-image.sh /usr/bin/build-image
44+
RUN apk add --no-cache binutils systemd-efistub
45+
COPY --from=imager-build /go/bin/imager /bin/imager
5246
WORKDIR /out
53-
ENTRYPOINT ["build-image"]
47+
ENTRYPOINT ["/bin/imager"]
5448

5549
# =========================================================
5650
FROM alpine-base AS bootable-alpine-rootfs
@@ -110,14 +104,14 @@ RUN if [ "$UCODE" != "none" ]; then apk add --no-cache "${UCODE}-ucode"; fi
110104
# hadolint ignore=DL3006
111105
FROM imager AS test
112106
ARG FORMAT=efi
113-
RUN --mount=from=test-rootfs,target=/system build-image --format "$FORMAT"
107+
RUN --mount=from=test-rootfs,target=/system /bin/imager --format "$FORMAT"
114108

115109
# =========================================================
116110
# Generate a qemu image running our custom OS image
117111
FROM alpine-base AS emulator
118112
RUN apk add --no-cache bash qemu-system-x86_64 ovmf
119113
COPY emulator.sh /entrypoint
120-
ENTRYPOINT ["/entrypoint"]
121114
COPY --from=test /out /images
122115
ARG FORMAT
123116
ENV FORMAT="$FORMAT"
117+
ENTRYPOINT ["/entrypoint"]

0 commit comments

Comments
 (0)