Skip to content

Commit 95e9829

Browse files
committed
cmd-build-with-buildah: unify more the direct and non-direct paths
We now have persistent containers storage in the supermin VM with the cache. Let's unify the direct and non-direct paths in the code. This does mean we need to skopeo copy to the ociarchive inside the supermin VM (because we don't have access to that containers storage outside of it). Alternatively we could have tried to run the `cosa import` inside the supermin VM as well, but the use of a bare-user repository over a virtiofs share made that option not work.
1 parent ade9134 commit 95e9829

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/cmd-build-with-buildah

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ build_with_buildah() {
111111
# This is analogous to the chmod we do in cmdlib.sh in the legacy path.
112112
chmod -R gu-s "${tempdir}/src"
113113

114-
tmp_oci_archive_path=$(realpath "${tempdir}/out.ociarchive")
115-
116114
initconfig="src/config.json"
117115
if [ -f "${initconfig}" ]; then
118116
variant="$(jq --raw-output '."coreos-assembler.config-variant"' "${initconfig}")"
@@ -197,29 +195,31 @@ build_with_buildah() {
197195
set -- "$@" -v "$(realpath overrides)":/src/overrides
198196
fi
199197

200-
if [ -n "$DIRECT" ]; then
201-
# output to a tag since it's more convenient for development;
202-
# buildah doesn't support doing both at once
203-
osname=$(eval "$(grep 'NAME=' "src/config/${argsfile}")"; echo "${NAME}")
204-
final_ref="containers-storage:localhost/${osname}:${VERSION}"
205-
else
206-
# In the supermin path ensure the ociarchive gets compressed
207-
set -- "$@" --disable-compression=false
208-
final_ref="oci-archive:${tmp_oci_archive_path}"
209-
fi
198+
# We'll also copy to an intermediate ociarchive file before
199+
# passing that ociarchive to cosa import
200+
tmp_oci_archive="oci-archive:$(realpath "${tempdir}/out.ociarchive")"
210201

211-
# and finally, add the tag and context dir
212-
set -- "$@" -t "${final_ref}" .
202+
# Set the output tag to be something unique
203+
osname=$(eval "$(grep 'NAME=' "src/config/${argsfile}")"; echo "${NAME}")
204+
final_ref="containers-storage:localhost/${osname}:${VERSION}"
205+
# and add the unique tag and context dir to the command
206+
set -- "$@" --tag "${final_ref}" .
213207

214208
echo "Running:" buildah "$@"
215209
if [ -n "$DIRECT" ]; then
216-
env -C "${tempdir}/src" buildah "$@"
210+
cmd="bash"
217211
else
218-
/usr/lib/coreos-assembler/cmd-supermin-run --cache \
219-
env -C "${tempdir}/src" TMPDIR="$(realpath cache)" buildah "$@"
212+
cmd="/usr/lib/coreos-assembler/cmd-supermin-run --cache"
220213
fi
214+
cat <<EOF > "${tempdir}/build-with-buildah-script.sh"
215+
set -euxo pipefail
216+
env -C ${tempdir}/src TMPDIR=$(realpath cache) buildah $@
217+
skopeo copy --quiet "${final_ref}" "${tmp_oci_archive}"
218+
EOF
219+
chmod +x "${tempdir}/build-with-buildah-script.sh"
220+
$cmd "${tempdir}/build-with-buildah-script.sh"
221221

222-
new_inputhash=$(skopeo inspect "${final_ref}" | jq -r '.Labels."com.coreos.inputhash"')
222+
new_inputhash=$(skopeo inspect "${tmp_oci_archive}" | jq -r '.Labels."com.coreos.inputhash"')
223223
if [ -n "${previous_inputhash}" ] && [ "$previous_inputhash" = "$new_inputhash" ]; then
224224
echo "Input hash unchanged ($new_inputhash)"
225225
if [ -z "$FORCE" ]; then
@@ -229,8 +229,9 @@ build_with_buildah() {
229229
fi
230230
fi
231231

232+
# Finally import the ociarchive, if we should
232233
if [ -z "${skip_import:-}" ]; then
233-
/usr/lib/coreos-assembler/cmd-import "${final_ref}" \
234+
/usr/lib/coreos-assembler/cmd-import "${tmp_oci_archive}" \
234235
${PARENT_BUILD:+--parent-build=${PARENT_BUILD}} ${SKIP_PRUNE:+--skip-prune}
235236
fi
236237

0 commit comments

Comments
 (0)