Skip to content

Commit f94ef71

Browse files
committed
Rewrite the image builder in Golang
1 parent 7248762 commit f94ef71

23 files changed

+631
-410
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.bin

Dockerfile

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,28 @@ RUN --mount=type=bind,target=. \
1717
yamllint -v && yamllint -s -f colored .
1818

1919
# =========================================================
20-
FROM golang:1.25.5-alpine AS init
20+
FROM golang:1.25.5-alpine AS imager-build
21+
SHELL ["/bin/ash", "-euxo", "pipefail", "-c"]
2122
WORKDIR /go/src
23+
COPY imager/go.mod imager/go.sum ./
24+
RUN go mod download
25+
COPY imager .
2226
RUN \
23-
--mount=source=init,target=. \
2427
--mount=type=cache,target=/root/.cache/go-build \
25-
CGO_ENABLED=0 go build -o /go/bin/init -v --ldflags '-s -w -extldflags=-static'
28+
go generate -v ./...; \
29+
go test; \
30+
go build -o /go/bin/imager -v --ldflags "-s -w" cmd/main.go
2631

2732
# =========================================================
2833
FROM alpine:3.23.0 AS alpine-base
2934

3035
# =========================================================
3136
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
37+
# TODO: bundle objcopy (or use a golang lib) and systemd-efistub into the imager binary
38+
RUN apk add --no-cache binutils systemd-efistub
39+
COPY --from=imager-build /go/bin/imager /bin/imager
5240
WORKDIR /out
53-
ENTRYPOINT ["build-image"]
41+
ENTRYPOINT ["/bin/imager"]
5442

5543
# =========================================================
5644
FROM alpine-base AS bootable-alpine-rootfs
@@ -109,14 +97,14 @@ if [ "$UCODE" != "none" ]; then apk add --no-cache "${UCODE}-ucode"; fi;
10997
# hadolint ignore=DL3006
11098
FROM imager AS test
11199
ARG FORMAT=efi
112-
RUN --mount=from=test-rootfs,target=/system build-image --format "$FORMAT"
100+
RUN --mount=from=test-rootfs,target=/system /bin/imager --format "$FORMAT"
113101

114102
# =========================================================
115103
# Generate a qemu image running our custom OS image
116104
FROM alpine-base AS emulator
117105
RUN apk add --no-cache bash qemu-system-x86_64 ovmf
118106
COPY emulator.sh /entrypoint
119-
ENTRYPOINT ["/entrypoint"]
120107
COPY --from=test /out /images
121108
ARG FORMAT
122109
ENV FORMAT="$FORMAT"
110+
ENTRYPOINT ["/entrypoint"]

0 commit comments

Comments
 (0)