kas-container: create KAS_WORK_DIR if it not exists

If KAS_WORK_DIR is set in the executing shell
and does not exists kas-container fails silently
during readlink -f on KAS_BUILD_DIR if the default
"${KAS_WORK_DIR}/build" is used.

Create KAS_WORK_DIR to ensure the subsequent
code execution.

This can be tested by setting KAS_WORK_DIR, e.g.

```
KAS_WORK_DIR="$(pwd)/kas_work" kas-container ...
```

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Quirin Gylstorff 2021-11-05 16:09:23 +01:00 committed by Jan Kiszka
parent 3ad03d1590
commit 9b9bb00c56

View File

@ -101,7 +101,10 @@ set_container_image_var() {
}
KAS_WORK_DIR=$(readlink -f "${KAS_WORK_DIR:-$(pwd)}")
# KAS_WORK_DIR needs to exist for the subsequent code
trace mkdir -p "${KAS_WORK_DIR}"
KAS_BUILD_DIR=$(readlink -f "${KAS_BUILD_DIR:-${KAS_WORK_DIR}/build}")
trace mkdir -p "${KAS_BUILD_DIR}"
KAS_CONTAINER_ENGINE="${KAS_CONTAINER_ENGINE:-${KAS_DOCKER_ENGINE}}"
if [ -z "${KAS_CONTAINER_ENGINE}" ]; then
@ -328,9 +331,6 @@ KAS_REPO_MOUNT_OPT="${KAS_REPO_MOUNT_OPT:-${KAS_REPO_MOUNT_OPT_DEFAULT}}"
KAS_FILES="$(echo "${KAS_FILES}" | sed 's|'"${KAS_REPO_DIR}"'/|/repo/|g')"
trace mkdir -p "${KAS_WORK_DIR}"
trace mkdir -p "${KAS_BUILD_DIR}"
if [ "$(id -u)" -eq 0 ] && [ "${KAS_ALLOW_ROOT}" != "yes" ] ; then
echo "Error: Running as root - may break certain recipes."
echo "Better give a regular user docker access. Set" \