Skip to content

Commit 33c043e

Browse files
tomassrnkaclaude
andauthored
feat: download busybox from fc-busybox release instead of embedding (#2281)
* feat: download busybox from fc-busybox release instead of embedding Download busybox binary from e2b-dev/fc-busybox GitHub release at Docker build time (via ADD) and at local build time (via curl in Makefile). Removes ~3.2MB of committed binaries from git. - Dockerfile: ADD from GitHub release, uses TARGETARCH - Makefile: fetch-busybox target for local dev builds - Both amd64 and arm64 binaries from same reproducible CI build Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: fetch busybox in CI before tests and lint CI runs go test/lint directly (not via Docker), so the busybox binary for go:embed must be downloaded first. Add fetch-busybox to orchestrator test setup and lint workflow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: verify busybox checksum, handle stale version and partial downloads - Dockerfile: download with curl + sha256sum verification per arch - Makefile: track version in .version file to detect stale binaries, write to .tmp first to avoid partial downloads Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: verify busybox against published SHA256SUMS from fc-busybox release - Dockerfile: download SHA256SUMS from release, verify binary against it (no more hardcoded checksums that need manual updating) - Makefile: track version+arch in .version file to detect stale binaries, write to .tmp first to avoid partial downloads Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: move busybox download after COPY, fix sha256sum filename mismatch - Move RUN after COPY ./orchestrator/pkg so the target directory exists - Download as /tmp/{binary_name} (not /tmp/busybox) so sha256sum -c can find the file by the name in SHA256SUMS Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: don't re-download busybox in Docker, restore version tracking for local dev - Dockerfile: build go directly instead of make build-local, so fetch-busybox doesn't overwrite the SHA256-verified binary - Makefile: restore stamp file for version tracking in local dev, only used by build-local/build-debug (not Docker) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: subshell for cd /tmp in checksum verify, add fetch-busybox to test/lint - Dockerfile: wrap cd /tmp in subshell so mv/chmod use correct WORKDIR, use absolute paths for destination - Makefile: add fetch-busybox dependency to test and lint targets Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: add SHA256 verification to fetch-busybox Makefile target Download SHA256SUMS from the fc-busybox release and verify the binary checksum, matching the Dockerfile verification pattern. All build paths now verify integrity. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove fetch-busybox from test/lint targets test and lint are called inside test.Dockerfile which doesn't have the pkg/ directory. CI workflows have their own fetch-busybox setup steps. Local dev gets busybox via build-local/build-debug before running test/lint. fetch-busybox remains on: build-local, build-debug (the entry points for local builds that produce the full binary). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: single-source BUSYBOX_VERSION in Makefile, pass to Docker via build-arg Makefile is the single source of truth for BUSYBOX_VERSION. Docker build receives it via --build-arg. Removes the duplicate default from the Dockerfile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor: extract busybox download+verify into shared script Single fetch-busybox.sh script used by both Dockerfile and Makefile. Eliminates duplicated download/SHA256 verification logic. Dockerfile back to using make build-local (fetch-busybox skips since the script already placed the binary). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: use grep -wF for exact match in SHA256SUMS verification Regex grep with dots in version string matches unintended lines. Fixed-string whole-word match prevents false matches against .sig or other suffixed entries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: add fetch-busybox to test, lint, and build-template targets All Makefile targets that compile Go code now depend on fetch-busybox so a fresh checkout works without manual setup. The script skips download if the binary already exists with matching version/arch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ed97d54 commit 33c043e

File tree

10 files changed

+83
-13
lines changed

10 files changed

+83
-13
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
- name: Parse .tool-versions
3636
uses: wistia/parse-tool-versions@v2.1.1
3737

38+
- name: Fetch busybox for orchestrator embed
39+
if: contains(matrix.modules, 'orchestrator')
40+
run: make -C packages/orchestrator fetch-busybox
41+
3842
- name: golangci-lint ${{ matrix.modules }}
3943
uses: golangci/golangci-lint-action@v8
4044
with:

.github/workflows/pr-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ jobs:
5656

5757
- name: Setup orchestrator tests
5858
run: |
59+
# Download busybox for go:embed
60+
make -C packages/orchestrator fetch-busybox
61+
5962
# Enable unprivileged uffd mode
6063
echo 1 | sudo tee /proc/sys/vm/unprivileged_userfaultfd
6164

packages/orchestrator/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ bin
88
.shared
99
/tmp
1010
.local-build
11+
12+
# Downloaded at build time from fc-busybox release
13+
pkg/template/build/core/systeminit/busybox
14+
pkg/template/build/core/systeminit/busybox.stamp

packages/orchestrator/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ ARG GOLANG_VERSION=1.25.4
33
# It has to match with the host OS version (Ubuntu 22.04 = bookworm)
44
ARG DEBIAN_VERSION=bookworm
55

6+
# Busybox version from fc-busybox GitHub release.
7+
# Passed via --build-arg from Makefile (single source of truth).
8+
# TARGETARCH is set automatically by Docker --platform.
9+
ARG BUSYBOX_VERSION
10+
611
FROM golang:${GOLANG_VERSION}-${DEBIAN_VERSION} AS builder
12+
ARG BUSYBOX_VERSION
13+
ARG TARGETARCH
714

815
# Cached golang dependencies
916
WORKDIR /build/shared
@@ -24,11 +31,16 @@ WORKDIR /build
2431
COPY ./shared/pkg ./shared/pkg
2532
COPY ./clickhouse/pkg ./clickhouse/pkg
2633

34+
COPY ./orchestrator/scripts ./orchestrator/scripts
2735
COPY ./orchestrator/pkg ./orchestrator/pkg
2836
COPY ./orchestrator/cmd ./orchestrator/cmd
2937
COPY ./orchestrator/main.go ./orchestrator/main.go
3038
COPY ./orchestrator/Makefile ./orchestrator/Makefile
3139

40+
# Download busybox and verify SHA256 against published checksums.
41+
RUN ./orchestrator/scripts/fetch-busybox.sh "${BUSYBOX_VERSION}" "${TARGETARCH}" \
42+
./orchestrator/pkg/template/build/core/systeminit/busybox
43+
3244
WORKDIR /build/orchestrator
3345

3446
ARG COMMIT_SHA

packages/orchestrator/Makefile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ BUILD_ARCH ?= $(shell go env GOARCH)
1414
# BUILD_PLATFORM=linux/arm64 make build
1515
BUILD_PLATFORM ?= linux/$(BUILD_ARCH)
1616

17+
# Busybox version — single source of truth for both Docker and local builds.
18+
BUSYBOX_VERSION ?= 1.36.1
19+
BUSYBOX_EMBED := pkg/template/build/core/systeminit/busybox
20+
1721
.PHONY: init
1822
init:
1923
brew install protobuf
@@ -25,17 +29,23 @@ generate:
2529
.PHONY: build
2630
build:
2731
$(eval COMMIT_SHA := $(shell git rev-parse --short HEAD))
28-
@docker build --platform $(BUILD_PLATFORM) --output=bin --build-arg COMMIT_SHA="$(COMMIT_SHA)" -f ./Dockerfile ..
32+
@docker build --platform $(BUILD_PLATFORM) --output=bin --build-arg COMMIT_SHA="$(COMMIT_SHA)" --build-arg BUSYBOX_VERSION="$(BUSYBOX_VERSION)" -f ./Dockerfile ..
33+
34+
# Download busybox and verify SHA256 against published checksums.
35+
# Skips if binary exists and version/arch match the stamp file.
36+
.PHONY: fetch-busybox
37+
fetch-busybox:
38+
@./scripts/fetch-busybox.sh "$(BUSYBOX_VERSION)" "$(BUILD_ARCH)" "$(BUSYBOX_EMBED)"
2939

3040
.PHONY: build-local
31-
build-local:
41+
build-local: fetch-busybox
3242
# Allow for passing commit sha directly for docker builds
3343
$(eval COMMIT_SHA ?= $(shell git rev-parse --short HEAD))
3444
CGO_ENABLED=1 GOOS=linux GOARCH=$(BUILD_ARCH) go build -o bin/orchestrator -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" .
3545
CGO_ENABLED=1 GOOS=linux GOARCH=$(BUILD_ARCH) go build -o bin/clean-nfs-cache -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" ./cmd/clean-nfs-cache
3646

3747
.PHONY: build-debug
38-
build-debug:
48+
build-debug: fetch-busybox
3949
CGO_ENABLED=1 GOOS=linux GOARCH=$(BUILD_ARCH) go build -race -gcflags=all="-N -l" -o bin/orchestrator .
4050

4151
.PHONY: run-debug
@@ -102,7 +112,7 @@ build-and-upload/template-manager: build upload/template-manager
102112

103113

104114
.PHONY: test
105-
test:
115+
test: fetch-busybox
106116
go test -race -v ./...
107117

108118
.PHONY: test-docker
@@ -118,7 +128,7 @@ test-docker:
118128
@echo "Done"
119129

120130
.PHONY: build-template
121-
build-template:
131+
build-template: fetch-busybox
122132
TEMPLATE_BUCKET_NAME=$(TEMPLATE_BUCKET_NAME) \
123133
GOOGLE_SERVICE_ACCOUNT_BASE64=$(GOOGLE_SERVICE_ACCOUNT_BASE64) \
124134
DOCKER_AUTH_BASE64=$(DOCKER_AUTH_BASE64) \
@@ -137,5 +147,5 @@ migrate:
137147
./scripts/upload-envs.sh /mnt/disks/fc-envs/v1 $(TEMPLATE_BUCKET_NAME)
138148

139149
.PHONY: lint
140-
lint:
150+
lint: fetch-busybox
141151
golangci-lint run --fix ./...
Binary file not shown.
Binary file not shown.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//go:build amd64
22

3-
// Busybox v1.36.1 static binary for amd64 (musl, minimal ~16 applets).
4-
// Custom build added in #1002 — origin unknown, no distro tag in binary.
3+
// Busybox static binary for amd64.
4+
// Downloaded from https://github.com/e2b-dev/fc-busybox/releases at build time.
55

66
package systeminit
77

88
import _ "embed"
99

10-
//go:embed busybox_1.36.1-2_amd64
10+
//go:embed busybox
1111
var BusyboxBinary []byte
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//go:build arm64
22

3-
// Busybox v1.36.1 static binary for arm64 (glibc, full 271 applets).
4-
// Source: Debian busybox-static 1:1.36.1-9 (https://packages.debian.org/busybox-static)
5-
// TODO: rebuild both binaries from the same minimal config for consistency.
3+
// Busybox static binary for arm64.
4+
// Downloaded from https://github.com/e2b-dev/fc-busybox/releases at build time.
65

76
package systeminit
87

98
import _ "embed"
109

11-
//go:embed busybox_1.36.1-2_arm64
10+
//go:embed busybox
1211
var BusyboxBinary []byte
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Download busybox from e2b-dev/fc-busybox GitHub release and verify SHA256.
4+
# Skips download if binary exists and version/arch match the stamp file.
5+
#
6+
# Usage:
7+
# ./scripts/fetch-busybox.sh <version> <arch> <output_path>
8+
#
9+
# Example:
10+
# ./scripts/fetch-busybox.sh 1.36.1 amd64 pkg/template/build/core/systeminit/busybox
11+
12+
set -euo pipefail
13+
14+
VERSION="${1:?Usage: fetch-busybox.sh <version> <arch> <output_path>}"
15+
ARCH="${2:?Usage: fetch-busybox.sh <version> <arch> <output_path>}"
16+
OUTPUT="${3:?Usage: fetch-busybox.sh <version> <arch> <output_path>}"
17+
STAMP="${OUTPUT}.stamp"
18+
19+
# Skip if binary exists and version/arch match
20+
if [ -f "$OUTPUT" ] && [ "$(cat "$STAMP" 2>/dev/null)" = "${VERSION}-${ARCH}" ]; then
21+
exit 0
22+
fi
23+
24+
RELEASE_URL="https://github.com/e2b-dev/fc-busybox/releases/download/v${VERSION}"
25+
BINARY="busybox_v${VERSION}_${ARCH}"
26+
27+
echo "Downloading busybox v${VERSION} (${ARCH})..."
28+
29+
curl -sfL -o "/tmp/${BINARY}" "${RELEASE_URL}/${BINARY}"
30+
curl -sfL -o "/tmp/SHA256SUMS" "${RELEASE_URL}/SHA256SUMS"
31+
32+
(cd /tmp && grep -wF "${BINARY}" SHA256SUMS | sha256sum -c -)
33+
34+
mkdir -p "$(dirname "$OUTPUT")"
35+
mv "/tmp/${BINARY}" "$OUTPUT"
36+
chmod +x "$OUTPUT"
37+
echo "${VERSION}-${ARCH}" > "$STAMP"
38+
rm -f /tmp/SHA256SUMS

0 commit comments

Comments
 (0)