Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor host OS CI scripts to allow running them locally #2557

Merged
merged 8 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions .github/buildomat/jobs/host-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,15 @@ done
#
export CARGO_NET_GIT_FETCH_WITH_CLI=true

pfexec mkdir -p /work
cd /work

# /work/gz: Global Zone artifacts to be placed in the Helios image.
mkdir gz && cd gz
ptime -m tar xvzf /input/package/work/global-zone-packages.tar.gz
cd -

# TODO: Consider importing zones here too?

# Checkout helios at a pinned commit
# Checkout helios at a pinned commit into /work/helios
pfexec mkdir -p /work
pushd /work
git clone https://github.com/oxidecomputer/helios.git
cd helios

git checkout "$COMMIT"
popd

# Create the "./helios-build" command, which lets us build images
gmake setup

# Commands that "./helios-build" would ask us to run (either explicitly
# or implicitly, to avoid an error).
pfexec pkg install /system/zones/brand/omicron1/tools
pfexec zfs create -p rpool/images/build

./helios-build experiment-image \
-p helios-netdev=https://pkg.oxide.computer/helios-netdev \
-F optever=0.21 \
-P /work/gz/root \
-B
# TODO: Consider importing zones here too?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little redundant with the comment on line 66?

./tools/build-host-image.sh -B /work/helios /input/package/work/global-zone-packages.tar.gz
2 changes: 1 addition & 1 deletion .github/buildomat/jobs/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ files=(
tools/create_virtual_hardware.sh
)

pfexec mkdir -p /work && pfexec chown $USER /work
ptime -m tar cvzf /work/package.tar.gz "${files[@]}"

# Build necessary for the global zone
Expand Down Expand Up @@ -86,7 +87,6 @@ cd "$pkg_dir"
tar -xvfz "$tarball_src_dir/maghemite.tar"
cd -

mkdir -p /work
cd "$tmp_gz" && tar cvfz /work/global-zone-packages.tar.gz oxide.json root
cd -

Expand Down
26 changes: 4 additions & 22 deletions .github/buildomat/jobs/recovery-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,12 @@ done
#
export CARGO_NET_GIT_FETCH_WITH_CLI=true

# Checkout helios at a pinned commit into /work/helios
pfexec mkdir -p /work
cd /work

# /work/gz: Global Zone artifacts to be placed in the Helios image.
mkdir gz && cd gz
ptime -m tar xvzf /input/package/work/trampoline-global-zone-packages.tar.gz
cd -

# Checkout helios at a pinned commit
pushd /work
git clone https://github.com/oxidecomputer/helios.git
cd helios

git checkout "$COMMIT"
popd

# Create the "./helios-build" command, which lets us build images
gmake setup

# Commands that "./helios-build" would ask us to run (either explicitly
# or implicitly, to avoid an error).
pfexec pkg install /system/zones/brand/omicron1/tools
pfexec zfs create -p rpool/images/build

./helios-build experiment-image \
-p helios-netdev=https://pkg.oxide.computer/helios-netdev \
-F optever=0.21 \
-P /work/gz/root \
-R
./tools/build-host-image.sh -R /work/helios /input/package/work/trampoline-global-zone-packages.tar.gz
33 changes: 33 additions & 0 deletions docs/how-to-run.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,36 @@ the exact addresses that are available depends on the environment.
6. Optionally, attach to the proxied propolis server serial console (this requires https://github.com/oxidecomputer/cli/commit/adab246142270778db7208126fb03724f5d35858[this commit] or newer of the CLI.)

oxide instance serial --interactive -p myproj -o myorg myinst

== Building host images

Host images for both the standard omicron install and the trampoline/recovery
install are built as a part of CI. To build them locally, first run the CI
script:

[source,text]
----
$ ./.github/buildomat/jobs/package.sh
----

This will create a `/work` directory with a few tarballs in it. Building a host
image requires a checkout of
https://github.com/oxidecomputer/helios-engvm[helios]; the instructions below
use `$HELIOS_PATH` for the path to this repository. To match CI builds, you
should check out the commit specified in `./tools/helios_version`. (The script
will check your current commit hash and will refuse to run if it doesn't match
unless you pass `-f`.)

To build a standard host image:

[source,text]
----
$ ./tools/build-host-image.sh -B $HELIOS_PATH /work/global-zone-packages.tar.gz
----

To build a recovery host image:

[source,text]
----
$ ./tools/build-host-image.sh -R $HELIOS_PATH /work/trampoline-global-zone-packages.tar.gz
----
120 changes: 120 additions & 0 deletions tools/build-host-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash

set -o errexit
set -o pipefail

function usage
{
echo "usage: $0 [-fRB] HELIOS_PATH PACKAGES_TARBALL"
echo
echo " -f Force helios build despite git hash mismatch"
echo " -R Build recovery (trampoline) image"
echo " -B Build standard image"
exit 1
}

function main
{
while getopts ":hfRB" opt; do
case $opt in
f)
FORCE=1
shift
;;
R)
BUILD_RECOVERY=1
HELIOS_BUILD_EXTRA_ARGS=-R
shift
;;
B)
BUILD_STANDARD=1
HELIOS_BUILD_EXTRA_ARGS=-B
shift
;;
h | \?)
usage
;;
esac
done

# Ensure we got either -R or -B but not both
case "x$BUILD_RECOVERY$BUILD_STANDARD" in
x11)
echo "specify at most one of -R, -B"
exit 1
;;
x)
echo "must specify either -R or -B"
exit 1
;;
*) ;;
esac

if [ "$#" != "2" ]; then
usage
fi

# Read expected helios commit into $COMMIT
TOOLS_DIR="$(pwd)/$(dirname $0)"
source "$TOOLS_DIR/helios_version"

# Convert args to absolute paths
case $1 in
/*) HELIOS_PATH=$1 ;;
*) HELIOS_PATH=$(pwd)/$1 ;;
esac
case $2 in
/*) TRAMPOLINE_PATH=$2 ;;
*) TRAMPOLINE_PATH=$(pwd)/$2 ;;
esac

# Extract the trampoline global zone tarball into a tmp_gz directory
if ! tmp_gz=$(mktemp -d); then
exit 1
fi
trap 'cd /; rm -rf "$tmp_gz"' EXIT

echo "Extracting trampoline gz packages into $tmp_gz"
ptime -m tar xvzf $TRAMPOLINE_PATH -C $tmp_gz
Comment on lines +71 to +78
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect we'll want to package zone tarballs into the OS image at some point, which will probably end up changing this a little bit? IDK if we just want to pass an "already unpacked" directory to this script, or to make it a separate argument to pass files that should not be unpacked before getting thrown to the -P flag below.


# Move to the helios checkout
cd $HELIOS_PATH

# Unless the user passed -f, check that the helios commit matches the one we
# have specified in `tools/helios_version`
if [ "x$FORCE" == "x" ]; then
CURRENT_COMMIT=$(git rev-parse HEAD)
if [ "x$COMMIT" != "x$CURRENT_COMMIT" ]; then
echo "WARNING: omicron/tools/helios_version specifies helios commit"
echo " $COMMIT"
echo "but you have"
echo " $CURRENT_COMMIT"
echo "Either check out the expected commit or pass -f to this"
echo "script to disable this check."
fi
fi

# Create the "./helios-build" command, which lets us build images
gmake setup

# Commands that "./helios-build" would ask us to run (either explicitly
# or implicitly, to avoid an error).
rc=0
pfexec pkg install -q /system/zones/brand/omicron1/tools || rc=$?
case $rc in
# `man pkg` notes that exit code 4 means no changes were made because
# there is nothing to do; that's fine. Any other exit code is an error.
0 | 4) ;;
*) exit $rc ;;
esac

pfexec zfs create -p rpool/images/$USER

./helios-build experiment-image \
-p helios-netdev=https://pkg.oxide.computer/helios-netdev \
-F optever=0.21 \
-P $tmp_gz/root \
$HELIOS_BUILD_EXTRA_ARGS
}

main "$@"