| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | source=$1 |
| 4 | output=$2 |
| 5 | target_os=$3 |
| 6 | target_arch=$4 |
| 7 | version=$5 |
| 8 | bundle=internal/release/bundled |
| 9 | # An existing directory belongs to another build. Never remove or reuse it. |
| 10 | mkdir "$bundle" |
| 11 | trap 'rm -rf "$bundle"' EXIT |
| 12 | trap 'exit 1' HUP INT TERM |
| 13 | # The page renderer (renderer.tar.gz) is not bundled: the Linux runner |
| 14 | # fetches it from its forge release (internal/release RendererForge). The |
| 15 | # platform caps one ship at 256 MiB, and the renderer alone is ~230 MB. |
| 16 | for name in install-manifest.json equipo-runner equipo-tool-proxy gitleaks install-v1.sh; do |
| 17 | cp "$source/$name" "$bundle/$name" |
| 18 | done |
| 19 | # The Mac worker's runner, served under darwin-arm64/ (it has no tool proxy). |
| 20 | mkdir "$bundle/darwin-arm64" |
| 21 | for name in equipo-runner gitleaks; do |
| 22 | cp "$source/darwin-arm64/$name" "$bundle/darwin-arm64/$name" |
| 23 | done |
| 24 | # Everything embedded stays well under the ship cap (a bound, not the cap). |
| 25 | bundled=$(du -sb "$bundle" | cut -f 1) |
| 26 | if [ "$bundled" -gt $((160 << 20)) ]; then |
| 27 | echo "build-instance-release: the bundle is $bundled bytes, over 160 MiB" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | # The instance serves only the tool proxy of its own build: its digest is |
| 31 | # linked in, as it is into the runners (Makefile, RELEASE_LDFLAGS). |
| 32 | proxy=$(sha256sum "$source/equipo-tool-proxy" | cut -d ' ' -f 1) |
| 33 | ldflags="-s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$version -X amadan.net/oficina/equipo/internal/release.toolProxySHA256=$proxy" |
| 34 | # Exercise the same manifest and digest checks as the download handler. |
| 35 | EQUIPO_BUNDLE_VERSION="$version" CGO_ENABLED=0 go test -tags runnerassets -ldflags "$ldflags" ./internal/release -run '^TestBundledInstallAssets$' -count=1 |
| 36 | CGO_ENABLED=0 GOOS="$target_os" GOARCH="$target_arch" go build -tags runnerassets -trimpath \ |
| 37 | -ldflags "$ldflags" \ |
| 38 | -o "$output" ./cmd/equipo |
| 39 | |