Skip to content

Commit 407a23c

Browse files
committed
cmd-build-with-buildah: add change detection
Use the new inputhash label to tell if there was a meaningful change since the previous build. If not, just no-op. Unless `--force` is passed. See also: coreos/fedora-coreos-config#3758
1 parent cb3ea70 commit 407a23c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/cmd-build-with-buildah

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ Usage: coreos-assembler build-with-buildah
2222
non-strict build.
2323
--skip-prune Skip prunning previous builds
2424
--parent-build=VERSION This option does nothing and is provided for backwards compatibility.
25-
--force This option does nothing and is provided for backwards compatibility.
25+
--force Import a new build even if inputhash has not changed.
2626
EOF
2727
}
2828

29+
FORCE=
2930
VERSION=
3031
VERSIONARY=
3132
DIRECT=
@@ -65,6 +66,7 @@ while true; do
6566
shift
6667
;;
6768
--force)
69+
FORCE=1
6870
;;
6971
--)
7072
shift
@@ -118,6 +120,15 @@ build_with_buildah() {
118120
exit 0
119121
fi
120122

123+
previous_inputhash=
124+
if [ -f "builds/latest/${arch}/meta.json" ]; then
125+
previous_inputhash=$(jq -r '.["coreos-assembler.oci-imported-labels"]["com.coreos.inputhash"] // ""' \
126+
"builds/latest/${arch}/meta.json")
127+
if [ -n "${previous_inputhash}" ]; then
128+
echo "Previous input hash: ${previous_inputhash}"
129+
fi
130+
fi
131+
121132
# Apply autolock from another build for this version (or for another version if
122133
# explicitly provided via --autolock) if no base lockfile exists.
123134
lockfile="manifest-lock.${arch}.json"
@@ -198,7 +209,19 @@ build_with_buildah() {
198209
env -C "${tempdir}/src" TMPDIR="$(realpath cache)" buildah "$@"
199210
fi
200211

201-
/usr/lib/coreos-assembler/cmd-import "${final_ref}" ${SKIP_PRUNE:+--skip-prune}
212+
new_inputhash=$(skopeo inspect "${final_ref}" | jq -r '.Labels."com.coreos.inputhash"')
213+
if [ -n "${previous_inputhash}" ] && [ "$previous_inputhash" = "$new_inputhash" ]; then
214+
echo "Input hash unchanged ($new_inputhash)"
215+
if [ -z "$FORCE" ]; then
216+
skip_import=1
217+
else
218+
echo "Importing new build anyway (--force)"
219+
fi
220+
fi
221+
222+
if [ -z "${skip_import:-}" ]; then
223+
/usr/lib/coreos-assembler/cmd-import "${final_ref}" ${SKIP_PRUNE:+--skip-prune}
224+
fi
202225

203226
rm -rf "${tempdir}"
204227
}

0 commit comments

Comments
 (0)