kas-container: make container image variables overwritable

This patch introduces new and improved ways to overwrite kas-container
variables that specify which image should be used.

`KAS_CONTAINER_IMAGE_PREFIX`: can be used to overwrite image sources.
For instance if podman is used, the default value `docker://` is used as
a prefix. But it still allows to overwrite it, by setting a custom
variable.

`KAS_CONTAINER_IMAGE_PATH`: can be used to customize the image source
path.

`KAS_CONTAINER_IMAGE_NAME`: can be set to change the container image
name.  For instance if `--isar` is used, the default value is
`kas-isar`, as with `KAS_CONTAINER_IMAGE_PREFIX` this default value can
still be overwritten by setting a custom value.

And last `KAS_IMAGE_VERSION`: It was possible to overwrite this value
before this patch and its still possible. The default value is the
current release version. Setting it for instance to `latest`, would
allow to used the most recent version of the image.

Signed-off-by: Claudius Heine <ch@denx.de>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Claudius Heine 2020-09-28 09:02:15 +02:00 committed by Jan Kiszka
parent 8d24d00bb3
commit 503cf183b1
2 changed files with 16 additions and 7 deletions

View File

@ -63,11 +63,18 @@ trace()
"$@"
}
if [ -z "${KAS_IMAGE_VERSION}" ]; then
KAS_IMAGE_VERSION="2.2"
fi
KAS_IMAGE_VERSION_DEFAULT="2.2"
KAS_CONTAINER_IMAGE_PATH_DEFAULT="ghcr.io/siemens/kas"
KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas"
KAS_CONTAINER_IMAGE_PREFIX_DEFAULT=""
KAS_CONTAINER_IMAGE=ghcr.io/siemens/kas/kas:${KAS_IMAGE_VERSION}
set_container_image_var() {
KAS_IMAGE_VERSION="${KAS_IMAGE_VERSION:-${KAS_IMAGE_VERSION_DEFAULT}}"
KAS_CONTAINER_IMAGE_NAME="${KAS_CONTAINER_IMAGE_NAME:-${KAS_CONTAINER_IMAGE_NAME_DEFAULT}}"
KAS_CONTAINER_IMAGE_PATH="${KAS_CONTAINER_IMAGE_PATH:-${KAS_CONTAINER_IMAGE_PATH_DEFAULT}}"
KAS_CONTAINER_IMAGE_PREFIX="${KAS_CONTAINER_IMAGE_PREFIX:-${KAS_CONTAINER_IMAGE_PREFIX_DEFAULT}}"
KAS_CONTAINER_IMAGE="${KAS_CONTAINER_IMAGE_PREFIX}${KAS_CONTAINER_IMAGE_PATH}/${KAS_CONTAINER_IMAGE_NAME}:${KAS_IMAGE_VERSION}"
}
if [ -n "${KAS_WORK_DIR}" ]; then
KAS_WORK_DIR=$(readlink -f "${KAS_WORK_DIR}")
@ -94,7 +101,7 @@ docker)
;;
podman)
KAS_CONTAINER_COMMAND="podman"
KAS_CONTAINER_IMAGE="docker://${KAS_CONTAINER_IMAGE}"
KAS_CONTAINER_IMAGE_PREFIX_DEFAULT="docker://"
KAS_RUNTIME_ARGS="--userns=keep-id --security-opt label=disable"
;;
*)
@ -107,7 +114,7 @@ esac
while [ $# -gt 0 ]; do
case "$1" in
--isar)
KAS_CONTAINER_IMAGE="$(echo "${KAS_CONTAINER_IMAGE}" | sed 's|ghcr.io/siemens/kas/kas|ghcr.io/siemens/kas/kas-isar|g')"
KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas-isar"
KAS_ISAR_ARGS="--privileged"
case "${KAS_CONTAINER_ENGINE}" in
@ -175,6 +182,7 @@ while [ $# -gt 0 ]; do
[ $# -eq 1 ] || usage
KAS_CLEAN_DIR=build/tmp
if [ -n "${KAS_ISAR_ARGS}" ]; then
set_container_image_var
trace ${KAS_CONTAINER_COMMAND} run -v "${KAS_WORK_DIR}":/work:rw \
--workdir=/work --rm ${KAS_ISAR_ARGS} \
${KAS_CONTAINER_IMAGE} \
@ -198,6 +206,7 @@ done
[ -n "${KAS_CMD}" ] || usage
KAS_EXTRA_BITBAKE_ARGS=0
set_container_image_var
# parse kas sub-command (build or shell) options
while [ $# -gt 0 ] && [ $KAS_EXTRA_BITBAKE_ARGS -eq 0 ]; do

View File

@ -31,7 +31,7 @@ fi
mv newchangelog CHANGELOG.md
sed -i "s,\(__version__ =\).*,\1 \'$NEW_VERSION\'," kas/__version__.py
sed -i "s,\( KAS_IMAGE_VERSION=\).*,\1\"$NEW_VERSION\"," kas-container
sed -i "s,\( KAS_IMAGE_VERSION_DEFAULT=\).*,\1\"$NEW_VERSION\"," kas-container
git add CHANGELOG.md
git add kas/__version__.py