Skip to content

Commit fdaded2

Browse files
authored
ci/tuf-repo: Consistent artifact versions (#3437)
Fixes #3430. Changes: - Changes the prerelease field in our version from `alpha` to `0.ci`, which comes before alpha, so that we can use `alpha` or other words found early in the dictionary and have them count as later than a CI build. - Stamps a non-placeholder version into the global zone packages installed in the host and trampoline OS images. - Adds `caboose-util`, loosely based on the small part of hubedit I needed, tweaked for usefulness to a shell script. - Reads the version out of a Hubris archive's caboose and uses that for the TUF repository, instead of the control plane version we generate here.
1 parent dc64fc0 commit fdaded2

File tree

7 files changed

+109
-25
lines changed

7 files changed

+109
-25
lines changed

.github/buildomat/jobs/ci-tools.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#: rust_toolchain = "1.70.0"
77
#: output_rules = [
88
#: "=/work/end-to-end-tests/*.gz",
9+
#: "=/work/caboose-util.gz",
910
#: "=/work/tufaceous.gz",
1011
#: ]
1112

@@ -37,6 +38,13 @@ for p in target/debug/bootstrap $(/opt/ooce/bin/jq -r 'select(.profile.test) | .
3738
ptime -m gzip < "$p" > /work/end-to-end-tests/"$(basename "$p").gz"
3839
done
3940

41+
########## caboose-util ##########
42+
43+
banner caboose-util
44+
45+
ptime -m cargo build --locked -p caboose-util --release
46+
ptime -m gzip < target/release/caboose-util > /work/caboose-util.gz
47+
4048
########## tufaceous ##########
4149

4250
banner tufaceous

.github/buildomat/jobs/package.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#: target = "helios-latest"
66
#: rust_toolchain = "1.70.0"
77
#: output_rules = [
8+
#: "=/work/version.txt",
89
#: "=/work/package.tar.gz",
910
#: "=/work/global-zone-packages.tar.gz",
1011
#: "=/work/trampoline-global-zone-packages.tar.gz",
@@ -28,6 +29,17 @@ set -o xtrace
2829
cargo --version
2930
rustc --version
3031

32+
#
33+
# Generate the version for control plane artifacts here. We use `0.git` as the
34+
# prerelease field because it comes before `alpha`.
35+
#
36+
# In this job, we stamp the version into packages installed in the host and
37+
# trampoline global zone images.
38+
#
39+
COMMIT=$(git rev-parse HEAD)
40+
VERSION="1.0.0-0.ci+git${COMMIT:0:11}"
41+
echo "$VERSION" >/work/version.txt
42+
3143
ptime -m ./tools/install_builder_prerequisites.sh -yp
3244
ptime -m ./tools/ci_download_softnpu_machinery
3345

@@ -37,8 +49,6 @@ ptime -m cargo run --locked --release --bin omicron-package -- \
3749
ptime -m cargo run --locked --release --bin omicron-package -- \
3850
-t test package
3951

40-
tarball_src_dir="$(pwd)/out"
41-
4252
# Assemble some utilities into a tarball that can be used by deployment
4353
# phases of buildomat.
4454

@@ -56,14 +66,29 @@ files=(
5666
pfexec mkdir -p /work && pfexec chown $USER /work
5767
ptime -m tar cvzf /work/package.tar.gz "${files[@]}"
5868

69+
tarball_src_dir="$(pwd)/out/versioned"
70+
stamp_packages() {
71+
for package in "$@"; do
72+
# TODO: remove once https://github.com/oxidecomputer/omicron-package/pull/54 lands
73+
if [[ $package == maghemite ]]; then
74+
echo "0.0.0" > VERSION
75+
tar rvf "out/$package.tar" VERSION
76+
rm VERSION
77+
fi
78+
79+
cargo run --locked --release --bin omicron-package -- stamp "$package" "$VERSION"
80+
done
81+
}
82+
5983
# Build necessary for the global zone
6084
ptime -m cargo run --locked --release --bin omicron-package -- \
6185
-t host target create -i standard -m gimlet -s asic
6286
ptime -m cargo run --locked --release --bin omicron-package -- \
6387
-t host package
88+
stamp_packages omicron-sled-agent maghemite propolis-server
6489

6590
# Create global zone package @ /work/global-zone-packages.tar.gz
66-
ptime -m ./tools/build-global-zone-packages.sh $tarball_src_dir /work
91+
ptime -m ./tools/build-global-zone-packages.sh "$tarball_src_dir" /work
6792

6893
# Non-Global Zones
6994

@@ -101,6 +126,7 @@ ptime -m cargo run --locked --release --bin omicron-package -- \
101126
-t recovery target create -i trampoline
102127
ptime -m cargo run --locked --release --bin omicron-package -- \
103128
-t recovery package
129+
stamp_packages installinator maghemite
104130

105131
# Create trampoline global zone package @ /work/trampoline-global-zone-packages.tar.gz
106-
ptime -m ./tools/build-trampoline-global-zone-packages.sh $tarball_src_dir /work
132+
ptime -m ./tools/build-trampoline-global-zone-packages.sh "$tarball_src_dir" /work

.github/buildomat/jobs/tuf-repo.sh

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,12 @@ set -o pipefail
4444
set -o xtrace
4545

4646
TOP=$PWD
47+
VERSION=$(< /input/package/work/version.txt)
4748

48-
source "$TOP/tools/dvt_dock_version"
49-
DVT_DOCK_COMMIT=$COMMIT
50-
source "$TOP/tools/hubris_version"
51-
HUBRIS_COMMIT=$COMMIT
52-
53-
COMMIT=$(git rev-parse HEAD)
54-
VERSION="1.0.0-alpha+git${COMMIT:0:11}"
55-
56-
ptime -m gunzip < /input/ci-tools/work/tufaceous.gz > /work/tufaceous
57-
chmod a+x /work/tufaceous
49+
for bin in caboose-util tufaceous; do
50+
ptime -m gunzip < /input/ci-tools/work/$bin.gz > /work/$bin
51+
chmod a+x /work/$bin
52+
done
5853

5954
#
6055
# We do two things here:
@@ -113,31 +108,41 @@ EOF
113108
done
114109

115110
# Fetch signed ROT images from oxidecomputer/dvt-dock.
111+
source "$TOP/tools/dvt_dock_version"
116112
git clone https://github.com/oxidecomputer/dvt-dock.git /work/dvt-dock
117-
(cd /work/dvt-dock; git checkout "$DVT_DOCK_COMMIT")
118-
DVT_DOCK_VERSION="1.0.0-alpha+git${DVT_DOCK_COMMIT:0:11}"
113+
(cd /work/dvt-dock; git checkout "$COMMIT")
119114

120115
for noun in gimlet psc sidecar; do
121116
tufaceous_kind=${noun//sidecar/switch}_rot
122117
hubris_kind=${noun}-rot
118+
path_a="/work/dvt-dock/staging/build-$hubris_kind-image-a-cert-dev.zip"
119+
path_b="/work/dvt-dock/staging/build-$hubris_kind-image-b-cert-dev.zip"
120+
version_a=$(/work/caboose-util read-version "$path_a")
121+
version_b=$(/work/caboose-util read-version "$path_b")
122+
if [[ "$version_a" != "$version_b" ]]; then
123+
echo "version mismatch:"
124+
echo " $path_a: $version_a"
125+
echo " $path_b: $version_b"
126+
exit 1
127+
fi
123128
cat >>/work/manifest.toml <<EOF
124129
[artifact.$tufaceous_kind]
125130
name = "$tufaceous_kind"
126-
version = "$DVT_DOCK_VERSION"
131+
version = "$version_a"
127132
[artifact.$tufaceous_kind.source]
128133
kind = "composite-rot"
129134
[artifact.$tufaceous_kind.source.archive_a]
130135
kind = "file"
131-
path = "/work/dvt-dock/staging/build-$hubris_kind-image-a-cert-dev.zip"
136+
path = "$path_a"
132137
[artifact.$tufaceous_kind.source.archive_b]
133138
kind = "file"
134-
path = "/work/dvt-dock/staging/build-$hubris_kind-image-b-cert-dev.zip"
139+
path = "$path_b"
135140
EOF
136141
done
137142

138143
# Fetch SP images from oxidecomputer/hubris GHA artifacts.
139-
HUBRIS_VERSION="1.0.0-alpha+git${HUBRIS_COMMIT:0:11}"
140-
run_id=$(curl --netrc -fsS "https://api.github.com/repos/oxidecomputer/hubris/actions/runs?head_sha=$HUBRIS_COMMIT" \
144+
source "$TOP/tools/hubris_version"
145+
run_id=$(curl --netrc -fsS "https://api.github.com/repos/oxidecomputer/hubris/actions/runs?head_sha=$COMMIT" \
141146
| /opt/ooce/bin/jq -r '.workflow_runs[] | select(.path == ".github/workflows/dist.yml") | .id')
142147
artifacts=$(curl --netrc -fsS "https://api.github.com/repos/oxidecomputer/hubris/actions/runs/$run_id/artifacts")
143148
for noun in gimlet-c psc-b sidecar-b; do
@@ -147,13 +152,15 @@ for noun in gimlet-c psc-b sidecar-b; do
147152
url=$(/opt/ooce/bin/jq --arg name "$job_name" -r '.artifacts[] | select(.name == $name) | .archive_download_url' <<<"$artifacts")
148153
curl --netrc -fsSL -o $job_name.zip "$url"
149154
unzip $job_name.zip
155+
path="$PWD/build-$noun-image-default.zip"
156+
version=$(/work/caboose-util read-version "$path")
150157
cat >>/work/manifest.toml <<EOF
151158
[artifact.$tufaceous_kind]
152159
name = "$tufaceous_kind"
153-
version = "$HUBRIS_VERSION"
160+
version = "$version"
154161
[artifact.$tufaceous_kind.source]
155162
kind = "file"
156-
path = "$PWD/build-$noun-image-default.zip"
163+
path = "$path"
157164
EOF
158165
done
159166

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"api_identity",
44
"bootstore",
55
"bootstrap-agent-client",
6+
"caboose-util",
67
"certificates",
78
"common",
89
"ddm-admin-client",
@@ -63,6 +64,7 @@ members = [
6364

6465
default-members = [
6566
"bootstrap-agent-client",
67+
"caboose-util",
6668
"certificates",
6769
"common",
6870
"ddm-admin-client",
@@ -182,10 +184,11 @@ hex-literal = "0.3.4"
182184
hkdf = "0.12.3"
183185
http = "0.2.9"
184186
httptest = "0.15.4"
185-
hyper-rustls = "0.24.0"
187+
hubtools = { git = "https://github.com/oxidecomputer/hubtools.git" }
188+
humantime = "2.1.0"
186189
hyper = "0.14"
190+
hyper-rustls = "0.24.0"
187191
hyper-staticfile = "0.9.5"
188-
humantime = "2.1.0"
189192
illumos-utils = { path = "illumos-utils" }
190193
indexmap = "1.9.3"
191194
indicatif = { version = "0.17.5", features = ["rayon"] }

caboose-util/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "caboose-util"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MPL-2.0"
6+
7+
[dependencies]
8+
anyhow.workspace = true
9+
hubtools.workspace = true

caboose-util/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
// Copyright 2023 Oxide Computer Company
6+
7+
use anyhow::{bail, Context, Result};
8+
use hubtools::RawHubrisArchive;
9+
10+
fn main() -> Result<()> {
11+
let mut args = std::env::args().skip(1);
12+
match args.next().context("subcommand required")?.as_str() {
13+
"read-version" => {
14+
let archive = RawHubrisArchive::load(
15+
&args.next().context("path to hubris archive required")?,
16+
)?;
17+
let caboose = archive.read_caboose()?;
18+
println!("{}", std::str::from_utf8(caboose.version()?)?);
19+
Ok(())
20+
}
21+
unknown => bail!("unknown command {}", unknown),
22+
}
23+
}

0 commit comments

Comments
 (0)