cloud / internal-packages / installer / container / pack-stack.shmain at aacbc74
#!/bin/bash
# pack-stack.sh — FILLS container/stack/ WITH THE STACK'S SOURCE, the tree of one git ref of this
# repo, for the deploy image (Dockerfile) to copy in. The image then clones nothing at run time.
# It writes the ref's commit id to stack/COMMIT, which a finished run answers as its `commit`.
# It writes the ref's whole history to stack/COMMITS, one commit id a line: what this image can update.
#
# internal-packages/installer/container/pack-stack.sh [git ref] (default: origin/main)
set -euo pipefail
ref="${1:-origin/main}"
here="$(cd "$(dirname "$0")" && pwd)"
top="$(git -C "$here" rev-parse --show-toplevel)"
commit="$(git -C "$top" rev-parse --verify "$ref^{commit}")"
rm -rf "$here/stack"
mkdir -p "$here/stack"
# from the top: run in a subfolder, git archive takes only that subfolder
git -C "$top" archive "$commit" | tar -x -C "$here/stack"
echo "$commit" > "$here/stack/COMMIT"
# every commit the ref has behind it, itself first: the run and the Cloud's Worker refuse to update
# a stack whose own commit is not one of them (run.sh `not_unknown_stack`, worker/stack-commits.js)
# A shallow clone has a part of the history alone: its list would refuse stacks that it should update.
[ "$(git -C "$top" rev-parse --is-shallow-repository)" = false ] || { echo "this clone is shallow: pack the stack from a full clone"; exit 1; }
git -C "$top" rev-list "$commit" > "$here/stack/COMMITS"
[ "$(head -1 "$here/stack/COMMITS")" = "$commit" ] || { echo "the list of commits does not start at $commit"; exit 1; }
echo "stack/ holds $ref at $commit"