Skip to content

Commit cc723d4

Browse files
committed
xtask: basic tool to build Helios agent in a job
1 parent d39eb27 commit cc723d4

File tree

2 files changed

+112
-9
lines changed

2 files changed

+112
-9
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
#
4+
# This job script is run inside a buildomat ephemeral VM.
5+
#
6+
if [[ -z $BUILDOMAT_JOB_ID ]]; then
7+
printf 'ERROR: this is supposed to be run under buildomat.\n' >&2
8+
exit 1
9+
fi
10+
11+
set -o errexit
12+
set -o pipefail
13+
set -o xtrace
14+
15+
#
16+
# Make sure we can locate the C compiler:
17+
#
18+
export PATH=/usr/bin:/usr/sbin:/sbin:/opt/ooce/sbin:/opt/ooce/bin
19+
20+
#
21+
# Install a stable Rust toolchain:
22+
#
23+
RUSTUP_INIT_SKIP_PATH_CHECK=yes \
24+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s - \
25+
--default-toolchain stable \
26+
--profile minimal \
27+
--no-modify-path \
28+
-y -q
29+
30+
. "$HOME/.cargo/env"
31+
32+
mkdir -p /work
33+
mkdir -p /out
34+
35+
cd /work
36+
37+
#
38+
# Unpack the templates and scripts we included when kicking off the job:
39+
#
40+
cpio -idv < '/input/src.cpio'
41+
42+
cargo build --features vendored-openssl --release --locked -p buildomat-agent
43+
44+
#
45+
# Copy rather than moving, because we're on the same file system and gzip
46+
# complains about a link count issue otherwise:
47+
#
48+
cp target/release/buildomat-agent /out/buildomat-agent
49+
chmod 0755 /out/buildomat-agent
50+
51+
sha256sum /out/buildomat-agent \
52+
>/out/buildomat-agent.sha256.txt
53+
gzip /out/buildomat-agent
54+
sha256sum /out/buildomat-agent.gz \
55+
>/out/buildomat-agent.gz.sha256.txt
56+
57+
find '/out' -type f -ls

xtask/src/main.rs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,52 @@ fn openapi() -> Result<()> {
9191
Ok(())
9292
}
9393

94-
fn build_linux_agent() -> Result<()> {
94+
#[derive(Copy, Clone, Debug)]
95+
enum AgentBuild {
96+
Linux,
97+
Helios,
98+
}
99+
100+
impl AgentBuild {
101+
fn job_name(&self) -> &str {
102+
match self {
103+
AgentBuild::Linux => "build-linux-agent",
104+
AgentBuild::Helios => "build-helios-agent",
105+
}
106+
}
107+
108+
fn script(&self) -> &str {
109+
match self {
110+
AgentBuild::Linux => {
111+
include_str!("../scripts/build_linux_agent.sh")
112+
}
113+
AgentBuild::Helios => {
114+
include_str!("../scripts/build_helios_agent.sh")
115+
}
116+
}
117+
}
118+
119+
fn output_filename(&self) -> &str {
120+
match self {
121+
AgentBuild::Linux => "buildomat-agent-linux.gz",
122+
AgentBuild::Helios => "buildomat-agent.gz",
123+
}
124+
}
125+
126+
fn use_target(&self) -> &str {
127+
/*
128+
* We should use the earliest version of a target when building the
129+
* agent. Using a newer target may result in binaries that don't work
130+
* in older images.
131+
*/
132+
match self {
133+
AgentBuild::Linux => "ubuntu-18.04",
134+
AgentBuild::Helios => "helios-2.0-20240204",
135+
}
136+
}
137+
}
138+
139+
fn build_agent(ab: AgentBuild) -> Result<()> {
95140
let files = Command::new("git").arg("ls-files").output()?;
96141

97142
if !files.status.success() {
@@ -132,13 +177,13 @@ fn build_linux_agent() -> Result<()> {
132177
.arg("run")
133178
.arg("-W")
134179
.arg("-n")
135-
.arg("build-linux-agent")
180+
.arg(ab.job_name())
136181
.arg("-c")
137-
.arg(include_str!("../scripts/build_linux_agent.sh"))
182+
.arg(ab.script())
138183
.arg("-t")
139-
.arg("ubuntu-18.04")
184+
.arg(ab.use_target())
140185
.arg("-O")
141-
.arg("=/out/buildomat-agent-linux.gz")
186+
.arg(format!("=/out/{}", ab.output_filename()))
142187
.arg("-O")
143188
.arg("=/out/*.sha256.txt")
144189
.arg("-i")
@@ -182,8 +227,8 @@ fn build_linux_agent() -> Result<()> {
182227
.arg("job")
183228
.arg("copy")
184229
.arg(&jid)
185-
.arg("/out/buildomat-agent-linux.gz")
186-
.arg("./buildomat-agent-linux.gz")
230+
.arg(format!("/out/{}", ab.output_filename()))
231+
.arg(format!("./{}", ab.output_filename()))
187232
.stdin(Stdio::inherit())
188233
.stdout(Stdio::inherit())
189234
.stderr(Stdio::inherit())
@@ -192,7 +237,7 @@ fn build_linux_agent() -> Result<()> {
192237
println!("unpacking agent...");
193238

194239
Command::new("gunzip")
195-
.arg("./buildomat-agent-linux.gz")
240+
.arg(format!("./{}", ab.output_filename()))
196241
.stdin(Stdio::inherit())
197242
.stdout(Stdio::inherit())
198243
.stderr(Stdio::inherit())
@@ -309,7 +354,8 @@ fn crates() -> Result<()> {
309354
fn main() -> Result<()> {
310355
match std::env::args().nth(1).as_deref() {
311356
Some("openapi") => openapi(),
312-
Some("build-linux-agent") => build_linux_agent(),
357+
Some("build-linux-agent") => build_agent(AgentBuild::Linux),
358+
Some("build-agent") => build_agent(AgentBuild::Helios),
313359
Some("crates") => crates(),
314360
Some(_) | None => {
315361
bail!("do not know how to do that");

0 commit comments

Comments
 (0)