-
Notifications
You must be signed in to change notification settings - Fork 182
cmd-build-with-buildah: enhance version handling, add yumrepos support, add autolocking #4249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1700819
3654be1
4234907
f1c014e
d208a64
222434f
e427cf4
195cc81
d2b49da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,15 +14,21 @@ Usage: coreos-assembler build-with-buildah | |||||
`cosa build` will pivot to this script when the environment variable `COREOS_ASSEMBLER_BUILD_WITH_BUILDAH` is set. | ||||||
|
||||||
The following options are supported: | ||||||
--version Use the versionary script from the source config to drive version. | ||||||
--version=VERSION Use the given version instead of using versionary. | ||||||
--versionary Generate non-development version using versionary. | ||||||
--direct Run buildah directly rather than within supermin. | ||||||
--autolock=VERSION If no base lockfile used, create one from any arch build of `VERSION`. | ||||||
Note this is automatically enabled when adding to an existing multi-arch | ||||||
non-strict build. | ||||||
EOF | ||||||
} | ||||||
|
||||||
VERSION= | ||||||
VERSIONARY= | ||||||
DIRECT= | ||||||
AUTOLOCK_VERSION= | ||||||
rc=0 | ||||||
options=$(getopt --options h,v,d --longoptions help,version:,direct -- "$@") || rc=$? | ||||||
options=$(getopt --options h,d --longoptions help,version:,versionary,direct,autolock: -- "$@") || rc=$? | ||||||
[ $rc -eq 0 ] || { | ||||||
print_help | ||||||
exit 1 | ||||||
|
@@ -34,13 +40,20 @@ while true; do | |||||
print_help | ||||||
exit 0 | ||||||
;; | ||||||
-v | --version) | ||||||
--version) | ||||||
shift | ||||||
VERSION=$1 | ||||||
;; | ||||||
--versionary) | ||||||
VERSIONARY=1 | ||||||
;; | ||||||
-d | --direct) | ||||||
DIRECT=1 | ||||||
;; | ||||||
--autolock) | ||||||
shift; | ||||||
AUTOLOCK_VERSION=$1 | ||||||
;; | ||||||
--) | ||||||
shift | ||||||
break | ||||||
|
@@ -57,7 +70,11 @@ done | |||||
|
||||||
if [ -z "${VERSION}" ]; then | ||||||
# let error out if file does not exist | ||||||
VERSION=$(src/config/versionary) | ||||||
if [ -z "${VERSIONARY}" ]; then | ||||||
VERSION=$(src/config/versionary --dev) | ||||||
else | ||||||
VERSION=$(src/config/versionary) | ||||||
fi | ||||||
fi | ||||||
|
||||||
build_with_buildah() { | ||||||
|
@@ -70,21 +87,52 @@ build_with_buildah() { | |||||
|
||||||
tmp_oci_archive_path=$(realpath "${tempdir}/out.ociarchive") | ||||||
|
||||||
argsfile=build-args.conf | ||||||
if [ -n "${variant:-}" ]; then | ||||||
initconfig="src/config.json" | ||||||
if [ -f "${initconfig}" ]; then | ||||||
variant="$(jq --raw-output '."coreos-assembler.config-variant"' "${initconfig}")" | ||||||
jlebon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
manifest="src/config/manifest-${variant}.yaml" | ||||||
argsfile=build-args-${variant}.conf | ||||||
else | ||||||
manifest="src/config/manifest.yaml" | ||||||
argsfile=build-args.conf | ||||||
fi | ||||||
|
||||||
if [ "$(check_build_exists "${VERSION}")" == "True" ]; then | ||||||
if [ -e "builds/$VERSION" ]; then | ||||||
echo "Build ${VERSION} already exists" | ||||||
exit 0 | ||||||
fi | ||||||
|
||||||
# Apply autolock from another build for this version (or for another version if | ||||||
# explicitly provided via --autolock) if no base lockfile exists. | ||||||
lockfile="manifest-lock.${arch}.json" | ||||||
if [ ! -f "src/config/${lockfile}" ] && { [ -n "${VERSION}" ] || [ -n "${AUTOLOCK_VERSION}" ]; }; then | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way to do this that avoids the awkward
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree it's awkward. Not sure it's better either. :) That one is mostly copy/pasted from |
||||||
autolockfile=$(tmprepo=tmp/repo; workdir=.; | ||||||
generate_autolock "${AUTOLOCK_VERSION:-${VERSION}}") | ||||||
if [ -n "${autolockfile}" ]; then | ||||||
echo "Injecting autolock-generated ${lockfile}..." | ||||||
cp "${autolockfile}" "${tempdir}/src/${lockfile}" | ||||||
fi | ||||||
fi | ||||||
|
||||||
set -- build --security-opt=label=disable --cap-add=all --device /dev/fuse \ | ||||||
--build-arg-file "$argsfile" -v "$(realpath "${tempdir}/src")":/run/src \ | ||||||
--build-arg VERSION="${VERSION}" \ | ||||||
-t oci-archive:"${tmp_oci_archive_path}" | ||||||
|
||||||
# XXX: Temporary hack until we have https://github.com/coreos/rpm-ostree/pull/5454 | ||||||
# which would allow us to fold this back into the build process. | ||||||
# shellcheck source=/dev/null | ||||||
stream=$(yaml2json "$manifest" /dev/stdout | jq -r '.variables.stream') | ||||||
if [ "${stream}" != null ]; then | ||||||
set -- "$@" --label fedora-coreos.stream="$stream" | ||||||
fi | ||||||
|
||||||
if [ -d "src/yumrepos" ] && [ -e "src/yumrepos/${variant:-}.repo" ]; then | ||||||
set -- "$@" --secret id=yumrepos,src="$(realpath "src/yumrepos/$variant.repo")" \ | ||||||
--secret id=contentsets,src="$(realpath src/yumrepos/content_sets.yaml)" \ | ||||||
-v /etc/pki/ca-trust:/etc/pki/ca-trust:ro | ||||||
fi | ||||||
|
||||||
if [ -n "$DIRECT" ]; then | ||||||
# turn on layer caching in the direct case; it wouldn't hurt in the | ||||||
# supermin path, but it'd be a waste of space on the rootfs | ||||||
|
@@ -99,4 +147,4 @@ build_with_buildah() { | |||||
rm -rf "${tempdir}" | ||||||
} | ||||||
|
||||||
build_with_buildah | ||||||
build_with_buildah |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if another option here in the future is just drop the versionary switch at all and add a
--prod
or--pipeline
switch and we'd just add that when we run in the pipeline similar to how we add--versionary
in the pipeline today.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, absolutely. I mentioned this in the commit message. The
--versionary
switch is awkwardly named now, but trying to keep it "pipeline compatible" to minimize changes that would be needed there. But once we cut over, we could simplify things, yeah.