Skip to content

Commit

Permalink
Separate publish tasks
Browse files Browse the repository at this point in the history
If you just want to build images, you don't need to build the pubsys tool
first, only buildsys.  This change splits the tasks so that builds only need to
depend on buildsys.

Similarly, AMI and repo builds only need to depend on pubsys, not buildsys.
`cargo make` currently rebuilds images each run.  If you want to build repos
or build/copy AMIs based on a previous image build, you don't want to wait for
image rebuilds, and you don't want to use different files - you want to use the
same image files you had.  This change makes the ami and repo tasks depend only
on pubsys and sources, and checks for image file existence internally.  (The
image file names include version and commit, so you can't accidentally use an
old build.)

This will also apply for `cargo make ssm`, where timing is even more critical.

Co-authored-by: Zac Mrowicki <mrowicki@amazon.com>
Co-authored-by: Tom Kirchner <tjk@amazon.com>
  • Loading branch information
zmrow and tjkirch committed Aug 11, 2020
1 parent 8b38f52 commit 4d549bf
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ cargo install \
--root tools \
--force \
--quiet
'''
]

[tasks.publish-tools]
dependencies = ["setup", "fetch-sources"]
script = [
'''
cargo install \
${CARGO_MAKE_CARGO_ARGS} \
--path tools/pubsys \
Expand Down Expand Up @@ -281,7 +287,10 @@ alias = "build"
# to create a repo under /build/repos, named after the arch/variant/version,
# containing subdirectories for the repo metadata and targets.
[tasks.repo]
dependencies = ["build"]
# Rather than depend on "build", which currently rebuilds images each run, we
# check for the image files below to save time. This does mean that `cargo
# make` must be run before `cargo make repo`.
dependencies = ["publish-tools"]
script_runner = "bash"
script = [
'''
Expand All @@ -294,6 +303,14 @@ trap 'cleanup' EXIT
export PATH="${BUILDSYS_TOOLS_DIR}/bin:${PATH}"
bootlz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-boot.ext4.lz4"
rootlz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-root.ext4.lz4"
hashlz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-root.verity.lz4"
if [ ! -s "${bootlz4}" ] || [ ! -s "${rootlz4}" ] || [ ! -s "${hashlz4}" ]; then
echo "Image files don't exist for the current version/commit - ${BUILDSYS_VERSION_FULL} - please run 'cargo make'" >&2
exit 1
fi
# TODO: only add migrations from Release.toml, not all
MIGRATIONS_DIR="$(mktemp -d)"
tar xpf "${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-migrations.tar" -C "${MIGRATIONS_DIR}"
Expand All @@ -313,9 +330,9 @@ pubsys \
--version "${BUILDSYS_VERSION_IMAGE}" \
--variant "${BUILDSYS_VARIANT}" \
\
--boot-image "${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-boot.ext4.lz4" \
--root-image "${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-root.ext4.lz4" \
--hash-image "${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-root.verity.lz4" \
--boot-image "${bootlz4}" \
--root-image "${rootlz4}" \
--hash-image "${hashlz4}" \
${ADD_MIGRATION_TARGETS[*]} \
\
--repo-expiration-policy-path "${PUBLISH_EXPIRATION_POLICY_PATH}" \
Expand All @@ -332,19 +349,34 @@ ln -sfn "${PUBLISH_REPO_OUTPUT_DIR##*/}" "${PUBLISH_REPO_BASE_DIR}/latest"
]

[tasks.ami]
dependencies = ["build"]
# Rather than depend on "build", which currently rebuilds images each run, we
# depend on publish-tools and check for the image files below to save time.
# This does mean that `cargo make` must be run before `cargo make ami`.
dependencies = ["publish-tools"]
script_runner = "bash"
script = [
'''
set -e
export PATH="${BUILDSYS_TOOLS_DIR}/bin:${PATH}"
cleanup() {
[ -f "${root_image}" ] && rm -f "${root_image}"
[ -f "${data_image}" ] && rm -f "${data_image}"
}
trap 'cleanup' EXIT
export PATH="${BUILDSYS_TOOLS_DIR}/bin:${PATH}"
# Unlz4 the root / data images
rootlz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}.img.lz4"
root_image="${rootlz4%.lz4}"
datalz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-data.img.lz4"
data_image="${datalz4%.lz4}"
if [ ! -s "${rootlz4}" ] || [ ! -s "${datalz4}" ]; then
echo "Image files don't exist for the current version/commit - ${BUILDSYS_VERSION_FULL} - please run 'cargo make'" >&2
exit 1
fi
lz4 -df "${rootlz4}" "${root_image}"
lz4 -df "${datalz4}" "${data_image}"
# Canonicalize architecture identifier to the value recognized by EC2.
case "${BUILDSYS_ARCH,,}" in
Expand All @@ -356,15 +388,6 @@ case "${BUILDSYS_ARCH,,}" in
arch="${BUILDSYS_ARCH}" ;;
esac
# Unlz4 the root / data images
rootlz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}.img.lz4"
root_image="${rootlz4%.lz4}"
lz4 -df "${rootlz4}" "${root_image}"
datalz4="${BUILDSYS_OUTPUT_DIR}/${BUILDSYS_NAME_FULL}-data.img.lz4"
data_image="${datalz4%.lz4}"
lz4 -df "${datalz4}" "${data_image}"
pubsys \
--infra-config-path "${PUBLISH_INFRA_CONFIG_PATH}" \
\
Expand Down

0 comments on commit 4d549bf

Please sign in to comment.