Skip to content

Commit 244e6de

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 215f222 commit 244e6de

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/cmd-build-with-buildah

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

104-
tmp_oci_archive_path=$(realpath "${tempdir}/out.ociarchive")
105-
106104
initconfig="src/config.json"
107105
if [ -f "${initconfig}" ]; then
108106
variant="$(jq --raw-output '."coreos-assembler.config-variant"' "${initconfig}")"
@@ -169,31 +167,34 @@ build_with_buildah() {
169167
fi
170168
fi
171169

172-
if [ -n "$DIRECT" ]; then
173-
# output to a tag since it's more convenient for development;
174-
# buildah doesn't support doing both at once
175-
# shellcheck disable=SC1090
176-
osname=$(source "src/config/${argsfile}"; echo "${NAME}")
177-
final_ref="containers-storage:localhost/${osname}:${VERSION}"
178-
else
179-
# In the supermin path ensure the ociarchive gets compressed
180-
set -- "$@" --disable-compression=false
181-
final_ref="oci-archive:${tmp_oci_archive_path}"
182-
fi
170+
# We'll also copy to an intermediate ociarchive file before
171+
# passing that ociarchive to cosa import
172+
tmp_oci_archive="oci-archive:$(realpath "${tempdir}/out.ociarchive")"
183173

184-
# and finally, add the tag and context dir
185-
set -- "$@" -t "${final_ref}" .
174+
# Set the output tag to be something unique
175+
# shellcheck disable=SC1090
176+
osname=$(source "src/config/${argsfile}"; echo "${NAME}")
177+
final_ref="containers-storage:localhost/${osname}:${VERSION}"
178+
# and add the unique tag and context dir to the command
179+
set -- "$@" --tag "${final_ref}" .
186180

187181
echo "Running:" buildah "$@"
188182
if [ -n "$DIRECT" ]; then
189-
env -C "${tempdir}/src" buildah "$@"
183+
cmd="bash"
190184
else
191-
/usr/lib/coreos-assembler/cmd-supermin-run --cache \
192-
env -C "${tempdir}/src" TMPDIR="$(realpath cache)" buildah "$@"
185+
cmd="/usr/lib/coreos-assembler/cmd-supermin-run --cache"
193186
fi
187+
cat <<EOF > "${tempdir}/build-with-buildah-script.sh"
188+
set -euxo pipefail
189+
env -C ${tempdir}/src TMPDIR=$(realpath cache) buildah $@
190+
skopeo copy --quiet "${final_ref}" "${tmp_oci_archive}"
191+
EOF
192+
chmod +x "${tempdir}/build-with-buildah-script.sh"
193+
$cmd "${tempdir}/build-with-buildah-script.sh"
194194

195-
/usr/lib/coreos-assembler/cmd-import "${final_ref}" ${SKIP_PRUNE:+--skip-prune}
196-
195+
# Finally import the ociarchive
196+
/usr/lib/coreos-assembler/cmd-import \
197+
"${tmp_oci_archive}" ${SKIP_PRUNE:+--skip-prune}
197198
rm -rf "${tempdir}"
198199
}
199200

0 commit comments

Comments
 (0)