Skip to main content

max / alloy

3.6 KB · 96 lines History Blame Raw
1 #!/usr/bin/env bash
2 #
3 # build.sh — build the three stand-in RPMs, the repo that serves them, and
4 # every base image variant.
5 #
6 # Everything lands in state/, which is gitignored. Deleting that directory is
7 # how to start clean; nothing here reads anything it did not put there.
8 #
9 # Rootful podman, because bootc install has to find the image in the same
10 # container store it runs out of, and a rootless-to-rootful copy of a 2 GB
11 # image is a slower way to arrive at the same place. That matches
12 # build-image.sh, which is rootful for the same reason.
13 set -euo pipefail
14
15 # shellcheck source=build/layertest/common.sh
16 . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
17
18 # shellcheck source=build/privilege.sh
19 . "$HERE/../privilege.sh"
20
21 mkdir -p "$STATE/rpms"
22
23 # ---------------------------------------------------------------- the RPMs
24 # Built in a container rather than on the host: rpmbuild and createrepo_c are
25 # not on a dev box by default, and the packages have to be fc43 to install into
26 # an fc43 base without an %{dist} mismatch nobody wants to debug.
27 say "building alloy-demo 0.0.1, 0.0.2 and 0.0.3"
28 podman run --rm -v "$HERE:/spec:ro,z" -v "$STATE:/state:z" -w /state \
29 registry.fedoraproject.org/fedora:43 bash -c '
30 set -e
31 dnf -y install rpm-build createrepo_c >/dev/null 2>&1
32 for v in 0.0.1 0.0.2 0.0.3; do
33 rpmbuild --define "_topdir /state/rpmbuild" --define "demo_version $v" \
34 -bb /spec/alloy-demo.spec >/dev/null
35 done
36 rm -rf /state/repo && mkdir -p /state/repo
37 cp /state/rpmbuild/RPMS/*/*.rpm /state/repo/
38 cp /state/rpmbuild/RPMS/*/*.rpm /state/rpms/
39 createrepo_c /state/repo >/dev/null
40
41 # And one repo per version, for the `carry` shape. A carried repo holding
42 # every version would let a machine resolve a version its image never
43 # shipped, so moving the base from one carry variant to the next would
44 # prove nothing.
45 rm -rf /state/repos && mkdir -p /state/repos
46 for v in 0.0.1 0.0.2 0.0.3; do
47 mkdir -p "/state/repos/$v"
48 cp "/state/rpmbuild/RPMS"/*/alloy-demo-$v-*.rpm "/state/repos/$v/"
49 createrepo_c "/state/repos/$v" >/dev/null
50 done
51 ' >/dev/null
52
53 # ------------------------------------------------------- the build context
54 # Written rather than tracked, because both files name a port that lives in
55 # common.sh, and two copies of a port number is one too many.
56 #
57 # Unsigned and insecure on purpose. Signing is its own subtask, and mixing it
58 # in here would add a way for a run to fail that has nothing to do with what is
59 # being measured.
60 cat > "$STATE/alloy-demo.repo" <<EOF
61 [alloy-demo]
62 name=alloy-demo hotfix channel (experiment)
63 baseurl=http://$HOST_FROM_GUEST:$REPO_PORT/
64 enabled=1
65 gpgcheck=0
66 EOF
67
68 cat > "$STATE/registries.conf" <<EOF
69 [[registry]]
70 location = "$HOST_FROM_GUEST:$REGISTRY_PORT"
71 insecure = true
72 EOF
73
74 # The guest is driven over ssh, so the key that drives it has to be in the
75 # image. Copied at build time rather than committed.
76 [ -f "$HOME/.ssh/id_ed25519.pub" ] || die "no ~/.ssh/id_ed25519.pub to authorize"
77 cp "$HOME/.ssh/id_ed25519.pub" "$STATE/authorized_keys"
78
79 # ------------------------------------------------------------- the images
80 for variant in "${VARIANTS[@]}"; do
81 mark="${variant%%:*}"
82 rest="${variant#*:}"
83 shape="${rest%%:*}"
84 version="${rest#*:}"
85 say "building $IMAGE:$mark (shape=$shape version=${version:-none})"
86 privc podman build \
87 -f "$HERE/Containerfile" \
88 --build-arg "SHAPE=$shape" \
89 --build-arg "DEMO_VERSION=${version:-0.0.1}" \
90 --build-arg "BASE_MARK=$mark" \
91 -t "$IMAGE:$mark" \
92 "$STATE" >/dev/null
93 done
94
95 say "built: $(printf '%s ' "${VARIANTS[@]%%:*}")"
96