Skip to content

Commit 0637540

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 712634c commit 0637540

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
@@ -23,10 +23,11 @@ Usage: coreos-assembler build-with-buildah
2323
--skip-prune Skip pruning previous builds.
2424
--strict Only allow installing locked packages when using lockfiles.
2525
--parent-build=VERSION This option does nothing and is provided for backwards compatibility.
26-
--force This option does nothing and is provided for backwards compatibility.
26+
--force Import a new build even if inputhash has not changed.
2727
EOF
2828
}
2929

30+
FORCE=
3031
VERSION=
3132
VERSIONARY=
3233
DIRECT=
@@ -70,6 +71,7 @@ while true; do
7071
shift
7172
;;
7273
--force)
74+
FORCE=1
7375
;;
7476
--)
7577
shift
@@ -123,6 +125,15 @@ build_with_buildah() {
123125
exit 0
124126
fi
125127

128+
previous_inputhash=
129+
if [ -f "builds/latest/${arch}/meta.json" ]; then
130+
previous_inputhash=$(jq -r '.["coreos-assembler.oci-imported-labels"]["com.coreos.inputhash"] // ""' \
131+
"builds/latest/${arch}/meta.json")
132+
if [ -n "${previous_inputhash}" ]; then
133+
echo "Previous input hash: ${previous_inputhash}"
134+
fi
135+
fi
136+
126137
# Apply autolock from another build for this version (or for another version if
127138
# explicitly provided via --autolock) if no base lockfile exists.
128139
lockfile="manifest-lock.${arch}.json"
@@ -207,7 +218,19 @@ build_with_buildah() {
207218
env -C "${tempdir}/src" TMPDIR="$(realpath cache)" buildah "$@"
208219
fi
209220

210-
/usr/lib/coreos-assembler/cmd-import "${final_ref}" ${SKIP_PRUNE:+--skip-prune}
221+
new_inputhash=$(skopeo inspect "${final_ref}" | jq -r '.Labels."com.coreos.inputhash"')
222+
if [ -n "${previous_inputhash}" ] && [ "$previous_inputhash" = "$new_inputhash" ]; then
223+
echo "Input hash unchanged ($new_inputhash)"
224+
if [ -z "$FORCE" ]; then
225+
skip_import=1
226+
else
227+
echo "Importing new build anyway (--force)"
228+
fi
229+
fi
230+
231+
if [ -z "${skip_import:-}" ]; then
232+
/usr/lib/coreos-assembler/cmd-import "${final_ref}" ${SKIP_PRUNE:+--skip-prune}
233+
fi
211234

212235
rm -rf "${tempdir}"
213236
}

0 commit comments

Comments
 (0)