Skip to content

Commit 2635852

Browse files
authored
Split install prerequisites script (#1369)
Although the old variant of the script still exists, it now internally calls: - `install_builder_prerequisites.sh` - `install_runner_prerequisites.sh` This distinction allows a different set of software to be installed for "building Omicron" vs "running Omicron".
1 parent b473c9c commit 2635852

File tree

8 files changed

+338
-221
lines changed

8 files changed

+338
-221
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Update PATH
3535
run: echo "$PWD/out/cockroachdb/bin:$PWD/out/clickhouse" >> "$GITHUB_PATH"
3636
- name: Install Pre-Requisites
37-
run: ./tools/install_prerequisites.sh -y
37+
run: ./tools/install_builder_prerequisites.sh -y
3838
- name: Check build of deployed Omicron packages
3939
run: cargo run --bin omicron-package -- check
4040

@@ -52,7 +52,7 @@ jobs:
5252
- name: Update PATH
5353
run: echo "$PWD/out/cockroachdb/bin:$PWD/out/clickhouse" >> "$GITHUB_PATH"
5454
- name: Install Pre-Requisites
55-
run: ./tools/install_prerequisites.sh -y
55+
run: ./tools/install_builder_prerequisites.sh -y
5656
- name: Run Clippy Lints
5757
#
5858
# Clippy's style nits are useful, but not worth keeping in CI. This
@@ -75,7 +75,7 @@ jobs:
7575
- name: Update PATH
7676
run: echo "$PWD/out/cockroachdb/bin:$PWD/out/clickhouse" >> "$GITHUB_PATH"
7777
- name: Install Pre-Requisites
78-
run: ./tools/install_prerequisites.sh -y
78+
run: ./tools/install_builder_prerequisites.sh -y
7979
- name: Test build documentation
8080
run: cargo doc
8181

@@ -117,7 +117,7 @@ jobs:
117117
- name: Update PATH
118118
run: echo "$PWD/out/cockroachdb/bin:$PWD/out/clickhouse" >> "$GITHUB_PATH"
119119
- name: Install Pre-Requisites
120-
run: ./tools/install_prerequisites.sh -y
120+
run: ./tools/install_builder_prerequisites.sh -y
121121
- name: Create temporary directory for test outputs
122122
run: mkdir -p $OMICRON_TMP
123123
- name: Build

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ WORKDIR /usr/src/omicron
2020
# sudo and path thing are only needed to get prereqs script to run
2121
ENV PATH=/usr/src/omicron/out/cockroachdb/bin:/usr/src/omicron/out/clickhouse:${PATH}
2222
RUN apt-get update && apt-get install -y sudo --no-install-recommends && rm -rf /var/lib/apt/lists/*
23-
RUN tools/install_prerequisites.sh -y
23+
RUN tools/install_builder_prerequisites.sh -y
2424

2525
RUN cargo build --release
2626

deploy/src/bin/thing-flinger.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,27 @@ fn do_install_prereqs(config: &Config) -> Result<()> {
274274

275275
// run install_prereqs on each server
276276
let builder = &config.servers[&config.builder.server];
277-
let build_server = (builder, &config.builder.omicron_path);
278-
let all_servers = std::iter::once(build_server).chain(
279-
config.servers.iter().filter_map(|(name, server)| {
280-
// skip running prereq installing on a deployment target if it is
281-
// also the builder, because we're already running it on the builder
282-
if *name == config.builder.server {
283-
None
284-
} else {
285-
Some((server, &config.deployment.staging_dir))
286-
}
287-
}),
277+
let all_servers = config
278+
.servers
279+
.iter()
280+
.map(|(_name, server)| (server, &config.deployment.staging_dir));
281+
282+
// -y: assume yes instead of prompting
283+
// -p: skip check that deps end up in $PATH
284+
let cmd = format!(
285+
"cd {} && mkdir -p out && pfexec ./tools/install_builder_prerequisites.sh -y -p",
286+
config.builder.omicron_path.display()
288287
);
288+
println!("install builder prerequisites on {}", builder.addr);
289+
ssh_exec(builder, &cmd, false)?;
289290

290291
for (server, root_path) in all_servers {
291292
// -y: assume yes instead of prompting
292-
// -p: skip check that deps end up in $PATH
293293
let cmd = format!(
294-
"cd {} && mkdir -p out && pfexec ./tools/install_prerequisites.sh -y -p",
294+
"cd {} && mkdir -p out && pfexec ./tools/install_runner_prerequisites.sh -y",
295295
root_path.display()
296296
);
297-
println!("install prerequisites on {}", server.addr);
297+
println!("install runner prerequisites on {}", server.addr);
298298
ssh_exec(server, &cmd, false)?;
299299
}
300300

docs/how-to-run-simulated.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Prerequisite software may be installed with the following script:
2727

2828
[source,text]
2929
----
30-
$ ./tools/install_prerequisites.sh
30+
$ ./tools/install_builder_prerequisites.sh
3131
----
3232

3333
== Running

docs/how-to-run.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ Any additional prerequisite software may be installed with the following script:
2525
$ ./tools/install_prerequisites.sh
2626
----
2727

28+
This script expects that you are both attempting to compile code and execute
29+
it on the same machine. If you'd like to have a different machine for a "builder"
30+
and a "runner", you can use the two more fine-grained scripts:
31+
32+
[source,text]
33+
----
34+
# To be invoked on the machine building Omicron
35+
$ ./tools/install_builder_prerequisites.sh
36+
# To be invoked on the machine running Omicron
37+
$ ./tools/install_runner_prerequisites.sh
38+
----
39+
2840
=== Make (or unmake) me a Gimlet!
2941

3042
The sled agent expects to manage a real Gimlet. However, until those are built,
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
MARKER=/etc/opt/oxide/NO_INSTALL
6+
if [[ -f "$MARKER" ]]; then
7+
echo "This system has the marker file $MARKER, aborting." >&2
8+
exit 1
9+
fi
10+
11+
# Set the CWD to Omicron's source.
12+
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
13+
cd "${SOURCE_DIR}/.."
14+
15+
function on_exit
16+
{
17+
echo "Something went wrong, but this script is idempotent - If you can fix the issue, try re-running"
18+
}
19+
20+
trap on_exit ERR
21+
22+
# Parse command line options:
23+
#
24+
# -y Assume "yes" intead of showing confirmation prompts.
25+
# -p Skip checking paths
26+
ASSUME_YES="false"
27+
SKIP_PATH_CHECK="false"
28+
while getopts yp flag
29+
do
30+
case "${flag}" in
31+
y) ASSUME_YES="true" ;;
32+
p) SKIP_PATH_CHECK="true" ;;
33+
esac
34+
done
35+
36+
# Offers a confirmation prompt, unless we were passed `-y`.
37+
#
38+
# Args:
39+
# $1: Text to be displayed
40+
function confirm
41+
{
42+
if [[ "${ASSUME_YES}" == "true" ]]; then
43+
response=y
44+
else
45+
read -r -p "$1 (y/n): " response
46+
fi
47+
case $response in
48+
[yY])
49+
true
50+
;;
51+
*)
52+
false
53+
;;
54+
esac
55+
}
56+
57+
# Packages to be installed on all OSes:
58+
#
59+
# - libpq, the PostgreSQL client lib.
60+
# We use Diesel's PostgreSQL support to connect to CockroachDB (which is
61+
# wire-compatible with PostgreSQL). Diesel uses the native libpq to do this.
62+
# `pg_config` is a utility which may be used to query for the installed
63+
# PostgreSQL libraries, and is expected by the Omicron build to exist in
64+
# the developer's PATH variable.
65+
# - pkg-config, a tool for querying installed libraries.
66+
#
67+
# Packages to be installed on Helios only:
68+
#
69+
# - pkg, the IPS client (though likely it will just be updated)
70+
# - build-essential: Common development tools
71+
# - brand/omicron1/tools: Oxide's omicron1-brand Zone
72+
73+
HOST_OS=$(uname -s)
74+
if [[ "${HOST_OS}" == "Linux" ]]; then
75+
packages=(
76+
'libpq-dev'
77+
'pkg-config'
78+
'xmlsec1'
79+
'libxmlsec1-dev'
80+
'libxmlsec1-openssl'
81+
'libclang-dev'
82+
'libsqlite3-dev'
83+
)
84+
sudo apt-get update
85+
if [[ "${ASSUME_YES}" == "true" ]]; then
86+
sudo apt-get install -y ${packages[@]}
87+
else
88+
confirm "Install (or update) [${packages[*]}]?" && sudo apt-get install ${packages[@]}
89+
fi
90+
elif [[ "${HOST_OS}" == "SunOS" ]]; then
91+
packages=(
92+
'pkg:/package/pkg'
93+
'build-essential'
94+
'library/postgresql-13'
95+
'pkg-config'
96+
'library/libxmlsec1'
97+
# "bindgen leverages libclang to preprocess, parse, and type check C and C++ header files."
98+
'pkg:/ooce/developer/clang-120'
99+
)
100+
101+
# Install/update the set of packages.
102+
# Explicitly manage the return code using "rc" to observe the result of this
103+
# command without exiting the script entirely (due to bash's "errexit").
104+
rc=0
105+
confirm "Install (or update) [${packages[*]}]?" && { pfexec pkg install -v "${packages[@]}" || rc=$?; }
106+
# Return codes:
107+
# 0: Normal Success
108+
# 4: Failure because we're already up-to-date. Also acceptable.
109+
if [[ "$rc" -ne 4 ]] && [[ "$rc" -ne 0 ]]; then
110+
exit "$rc"
111+
fi
112+
113+
pkg list -v "${packages[@]}"
114+
elif [[ "${HOST_OS}" == "Darwin" ]]; then
115+
packages=(
116+
'postgresql'
117+
'pkg-config'
118+
'libxmlsec1'
119+
)
120+
confirm "Install (or update) [${packages[*]}]?" && brew install ${packages[@]}
121+
else
122+
echo "Unsupported OS: ${HOST_OS}"
123+
exit -1
124+
fi
125+
126+
# CockroachDB and Clickhouse are used by Omicron for storage of
127+
# control plane metadata and metrics.
128+
#
129+
# They are used in a couple of spots within Omicron:
130+
#
131+
# - Test Suite: The test suite, regardless of host OS, builds temporary
132+
# databases for testing, and expects `cockroach` and `clickhouse` to
133+
# exist as a part of the PATH.
134+
# - Packaging: When constructing packages on Helios, these utilities
135+
# are packaged into zones which may be launched by the sled agent.
136+
137+
./tools/ci_download_cockroachdb
138+
./tools/ci_download_clickhouse
139+
140+
# Install static console assets. These are used when packaging Nexus.
141+
./tools/ci_download_console
142+
143+
# Download the OpenAPI spec for maghemite. This is required to build the
144+
# ddm-admin-api crate.
145+
./tools/ci_download_maghemite_openapi
146+
147+
# Validate the PATH:
148+
expected_in_path=(
149+
'pg_config'
150+
'pkg-config'
151+
'cockroach'
152+
'clickhouse'
153+
)
154+
155+
function show_hint
156+
{
157+
case "$1" in
158+
"pg_config")
159+
if [[ "${HOST_OS}" == "SunOS" ]]; then
160+
echo "On illumos, $1 is typically found in '/opt/ooce/bin'"
161+
fi
162+
;;
163+
"pkg-config")
164+
if [[ "${HOST_OS}" == "SunOS" ]]; then
165+
echo "On illumos, $1 is typically found in '/usr/bin'"
166+
fi
167+
;;
168+
"cockroach")
169+
echo "$1 should have been installed to '$PWD/out/cockroachdb/bin'"
170+
;;
171+
"clickhouse")
172+
echo "$1 should have been installed to '$PWD/out/clickhouse'"
173+
;;
174+
*)
175+
;;
176+
esac
177+
}
178+
179+
# Check all paths before returning an error, unless we were told not too.
180+
if [[ "$SKIP_PATH_CHECK" == "true" ]]; then
181+
echo "All prerequisites installed successfully"
182+
exit 0
183+
fi
184+
185+
ANY_PATH_ERROR="false"
186+
for command in "${expected_in_path[@]}"; do
187+
rc=0
188+
which "$command" &> /dev/null || rc=$?
189+
if [[ "$rc" -ne 0 ]]; then
190+
echo "ERROR: $command seems installed, but was not found in PATH. Please add it."
191+
show_hint "$command"
192+
ANY_PATH_ERROR="true"
193+
fi
194+
done
195+
196+
if [[ "$ANY_PATH_ERROR" == "true" ]]; then
197+
exit -1
198+
fi
199+
200+
echo "All builder prerequisites installed successfully, and PATH looks valid"

0 commit comments

Comments
 (0)