Skip to content

Commit eeafb93

Browse files
PeaceRebeljlebon
authored andcommitted
Fail early if build exists and use versionary by default
1 parent 8558b70 commit eeafb93

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/cmd-build-with-buildah

100644100755
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ Usage: coreos-assembler build-with-buildah
1414
`cosa build` will pivot to this script when the environment variable `COREOS_ASSEMBLER_BUILD_WITH_BUILDAH` is set.
1515
1616
The following options are supported:
17-
--versionary Use the versionary script from the source config to drive version.
18-
--direct Run buildah directly rather than within supermin.
17+
--version Use the versionary script from the source config to drive version.
18+
--direct Run buildah directly rather than within supermin.
1919
EOF
2020
}
2121

22-
VERSIONARY=
2322
VERSION=
2423
DIRECT=
2524
rc=0
26-
options=$(getopt --options h,v,d --longoptions help,versionary,direct -- "$@") || rc=$?
25+
options=$(getopt --options h,v,d --longoptions help,version:,direct -- "$@") || rc=$?
2726
[ $rc -eq 0 ] || {
2827
print_help
2928
exit 1
@@ -35,8 +34,9 @@ while true; do
3534
print_help
3635
exit 0
3736
;;
38-
-v | --versionary)
39-
VERSIONARY=1
37+
-v | --version)
38+
shift
39+
VERSION=$1
4040
;;
4141
-d | --direct)
4242
DIRECT=1
@@ -55,15 +55,13 @@ while true; do
5555
shift
5656
done
5757

58-
if [ -n "${VERSIONARY}" ]; then
58+
if [ -z "${VERSION}" ]; then
5959
# let error out if file does not exist
6060
VERSION=$(src/config/versionary)
61-
echo "New version will be ${VERSION}"
6261
fi
6362

6463
build_with_buildah() {
65-
VERSION=$1
66-
echo "Building with container runtime (buildah)..."
64+
echo "Building with container runtime (buildah) with VERSION=${VERSION}..."
6765

6866
tempdir=$(mktemp -d --tmpdir=tmp "build-with-buildah.XXXXXXXX")
6967

@@ -77,14 +75,16 @@ build_with_buildah() {
7775
argsfile=build-args-${variant}.conf
7876
fi
7977

78+
if [ "$(check_build_exists "${VERSION}")" == "True" ]; then
79+
echo "Build ${VERSION} already exists"
80+
exit 0
81+
fi
82+
8083
set -- build --security-opt=label=disable --cap-add=all --device /dev/fuse \
8184
--build-arg-file "$argsfile" -v "$(realpath "${tempdir}/src")":/run/src \
85+
--build-arg VERSION="${VERSION}" \
8286
-t oci-archive:"${tmp_oci_archive_path}"
8387

84-
if [ -n "${VERSION}" ]; then
85-
set -- "$@" --build-arg VERSION="${VERSION}"
86-
fi
87-
8888
if [ -n "$DIRECT" ]; then
8989
# turn on layer caching in the direct case; it wouldn't hurt in the
9090
# supermin path, but it'd be a waste of space on the rootfs
@@ -99,4 +99,4 @@ build_with_buildah() {
9999
rm -rf "${tempdir}"
100100
}
101101

102-
build_with_buildah "$VERSION"
102+
build_with_buildah

src/cmdlib.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,17 @@ cmdlib.import_ostree_commit(workdir, builddir, buildmeta, extract_json=('${extra
11051105
")
11061106
}
11071107

1108+
check_build_exists() {
1109+
local buildid=$1; shift
1110+
(python3 -c "
1111+
import sys
1112+
sys.path.insert(0, '${DIR}')
1113+
from cosalib.builds import Builds
1114+
builds = Builds('${workdir:-$(pwd)}')
1115+
print(builds.has('${buildid}'))
1116+
")
1117+
}
1118+
11081119
# Extract the value of NAME from os-release
11091120
extract_osrelease_name() {
11101121
local buildid=$1; shift

0 commit comments

Comments
 (0)