Skip to content

Commit 5592a3f

Browse files
scooby87lexfrei
authored andcommitted
build(seaweedfs): re-pin the in-tree build from make update
The in-tree build pinned its source, base image and toolchain by hand, and nothing moved them when `make update` vendored a new chart, so a bump would build one release's weed into another release's image, or keep patching a release that already carries the fix. Pin the source archive by checksum and the upstream image by digest as build arguments, compile with the toolchain upstream's own builder uses for the tag, and let `make update` re-pin all of them from the vendored chart and fail when the patches no longer apply. The tests of the patched packages now run once rather than once per target platform, and `weed version` names the build. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent d2c6b85 commit 5592a3f

2 files changed

Lines changed: 66 additions & 17 deletions

File tree

‎packages/system/seaweedfs/Makefile‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SEAWEEDFS_TAG=$(shell grep -F 'ARG VERSION=' images/seaweedfs/Dockerfile | cut -
44
include ../../../hack/common-envs.mk
55
include ../../../hack/package.mk
66

7+
.PHONY: image
78
image:
89
docker buildx build images/seaweedfs \
910
$(call image-tags,seaweedfs,$(SEAWEEDFS_TAG)) \
@@ -61,4 +62,34 @@ update:
6162
patch --no-backup-if-mismatch -p4 < patches/s3-service-name-consumers.patch
6263
patch --no-backup-if-mismatch -p4 < patches/cluster-scoped-names-per-namespace.patch
6364
#patch --no-backup-if-mismatch -p4 < patches/retention-policy-delete.yaml
65+
$(MAKE) update-image
66+
67+
# Re-pins images/seaweedfs/Dockerfile to the vendored chart's appVersion: the
68+
# source archive checksum, the upstream image digest and upstream's builder
69+
# toolchain for that tag. The patches are Go, so they are checked against the
70+
# whole source tree of the tag; once a release carries a fix, its patch stops
71+
# applying here and is dropped.
72+
.PHONY: update-image
73+
update-image:
74+
version=$$(yq e '.appVersion' charts/seaweedfs/Chart.yaml) && \
75+
upstream=$$(docker buildx imagetools inspect "chrislusf/seaweedfs:$${version}" --format '{{json .Manifest}}' | yq e '.digest' -) && \
76+
case "$$upstream" in sha256:*) ;; *) echo "ERROR: no digest for chrislusf/seaweedfs:$${version}" >&2; exit 1;; esac && \
77+
$(SED_INPLACE) -e "s/^ARG VERSION=.*/ARG VERSION=$${version}/" -e "s/^ARG UPSTREAM_DIGEST=.*/ARG UPSTREAM_DIGEST=$${upstream}/" images/seaweedfs/Dockerfile && \
78+
tmpdir=$$(mktemp -d) && \
79+
{ curl --fail --silent --show-error --location -o "$$tmpdir/source.tar.gz" \
80+
"https://github.com/seaweedfs/seaweedfs/archive/refs/tags/$${version}.tar.gz" && \
81+
mkdir "$$tmpdir/src" && tar -xzf "$$tmpdir/source.tar.gz" --strip-components=1 -C "$$tmpdir/src" || { rm -rf "$$tmpdir"; exit 1; }; } && \
82+
source=$$(sha256sum "$$tmpdir/source.tar.gz" | cut -d' ' -f1) && \
83+
$(SED_INPLACE) "s/^ARG SOURCE_SHA256=.*/ARG SOURCE_SHA256=$${source}/" images/seaweedfs/Dockerfile && \
84+
{ git -C "$$tmpdir/src" apply --check $(CURDIR)/images/seaweedfs/patches/*.diff || \
85+
{ echo "ERROR: images/seaweedfs/patches/*.diff no longer apply to seaweedfs $${version}; regenerate them, or drop the ones the new tag already carries" >&2; \
86+
rm -rf "$$tmpdir"; exit 1; }; } && \
87+
golang=$$(sed -n 's/^FROM --platform=\$$BUILDPLATFORM \([^ ]*\) AS builder$$/\1/p' "$$tmpdir/src/docker/Dockerfile.go_build") && \
88+
{ [ -n "$$golang" ] || { echo "ERROR: no builder FROM line in upstream docker/Dockerfile.go_build $${version}" >&2; rm -rf "$$tmpdir"; exit 1; }; } && \
89+
builder=$$(docker buildx imagetools inspect "$$golang" --format '{{json .Manifest}}' | yq e '.digest' -) && \
90+
{ case "$$builder" in sha256:*) ;; *) echo "ERROR: no digest for $${golang}" >&2; rm -rf "$$tmpdir"; exit 1;; esac; } && \
91+
$(SED_INPLACE) "s|^FROM --platform=\$$BUILDPLATFORM [^ ]* AS builder$$|FROM --platform=\$$BUILDPLATFORM $${golang}@$${builder} AS builder|" images/seaweedfs/Dockerfile && \
92+
{ grep -qF "FROM --platform=\$$BUILDPLATFORM $${golang}@$${builder} AS builder" images/seaweedfs/Dockerfile || \
93+
{ echo "ERROR: the builder FROM line in images/seaweedfs/Dockerfile was not re-pinned; its shape no longer matches the update recipe" >&2; rm -rf "$$tmpdir"; exit 1; }; } && \
94+
rm -rf "$$tmpdir"
6495

‎packages/system/seaweedfs/images/seaweedfs/Dockerfile‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,57 @@
1212
# about a gigabyte of a single object in memory, is OOM-killed under the 512Mi
1313
# limit the S3 deployment gets from its resources preset, and the client sees
1414
# the response cut off tens of megabytes in:
15-
# https://github.com/cozystack/cozystack/issues/3782. Upstream carries the same
16-
# defect on master, tracked as seaweedfs/seaweedfs#11672; drop the patch on the
17-
# first release that carries a fix.
18-
19-
# Keep in step with the chart appVersion pulled by `make update`, and with the
20-
# base image below: the patched binary replaces this version's, so building it
21-
# from another tag would run one version's weed against the rest of another's
22-
# image.
15+
# https://github.com/cozystack/cozystack/issues/3782. Upstream fixed it in
16+
# seaweedfs/seaweedfs#11674 after 4.48; drop the patch on the first vendored
17+
# release that carries it.
18+
#
19+
# `make update` re-pins VERSION from the vendored chart, SOURCE_SHA256 from the
20+
# source archive of that tag, UPSTREAM_DIGEST from the upstream image of that
21+
# tag and the builder from upstream's docker/Dockerfile.go_build, and checks
22+
# that the patches still apply.
2323
ARG VERSION=4.45
24+
ARG SOURCE_SHA256=800a91693e2a4e974ef0e2a157b6a04eff9f4df507303b1cff31b0601081fc30
25+
ARG UPSTREAM_DIGEST=sha256:fc9f76fa993ad69966ffeb2f65d0318fcae39c6f8e20cf68ef7b3a5cb97769e5
2426

25-
FROM --platform=$BUILDPLATFORM golang:1.26@sha256:eb36c1664dd974cde625f736e02c204383deebe03977365caaec5bf49f794348 AS builder
27+
# The Go toolchain of upstream's builder (docker/Dockerfile.go_build), which
28+
# compiles the upstream weed.
29+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine@sha256:3082400e369fa24d5fc60bca20edab3f6d604e0c5a690ec66b295eff4dd87ade AS builder
2630
ARG GOPROXY
2731
ARG VERSION
28-
ARG TARGETOS
29-
ARG TARGETARCH
32+
ARG SOURCE_SHA256
33+
34+
RUN apk add --no-cache git curl
3035

31-
WORKDIR /workspace
36+
WORKDIR /go/src/github.com/seaweedfs/seaweedfs
3237

33-
RUN curl -sSL https://github.com/seaweedfs/seaweedfs/archive/refs/tags/${VERSION}.tar.gz | tar -xzf- --strip=1
38+
RUN curl -fsSL -o /tmp/source.tar.gz https://github.com/seaweedfs/seaweedfs/archive/refs/tags/${VERSION}.tar.gz && \
39+
echo "${SOURCE_SHA256} /tmp/source.tar.gz" | sha256sum -c - && \
40+
tar -xzf /tmp/source.tar.gz --strip-components=1 && rm /tmp/source.tar.gz
3441

3542
COPY patches /patches
3643
RUN git apply /patches/*.diff
3744

45+
ENV CGO_ENABLED=0
46+
3847
# go build never compiles a _test.go, so nothing else runs the tests the
3948
# patches carry. The list is read into a variable first: a for loop drops the
4049
# exit status of a command substitution, so a patch git cannot read would leave
4150
# the list empty and the step green.
4251
RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \
4352
for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \
44-
go test -race "./$dir" || exit 1; \
53+
go test "./$dir" || exit 1; \
4554
done
4655

47-
RUN cd weed && GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o /workspace/weed-bin .
56+
# Declared after the tests so they run once on the build platform rather than
57+
# once per target platform.
58+
ARG TARGETOS
59+
ARG TARGETARCH
60+
61+
# The source archive carries no git history for upstream's `git rev-parse`, so
62+
# the commit field of `weed version` names this build instead.
63+
RUN cd weed && GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
64+
-ldflags "-X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=cozystack-patched" \
65+
-o /out/weed .
4866

49-
FROM chrislusf/seaweedfs:${VERSION}@sha256:fc9f76fa993ad69966ffeb2f65d0318fcae39c6f8e20cf68ef7b3a5cb97769e5
50-
COPY --from=builder /workspace/weed-bin /usr/bin/weed
67+
FROM chrislusf/seaweedfs:${VERSION}@${UPSTREAM_DIGEST}
68+
COPY --from=builder /out/weed /usr/bin/weed

0 commit comments

Comments
 (0)