From 14f53333e9202a767b3a3d171f5e8d2b4f6dacd0 Mon Sep 17 00:00:00 2001 From: Petr OspalĂ˝ Date: Fri, 18 Jan 2019 10:34:27 +0100 Subject: Enable to build ansible image out of git directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inside the build_ansible_image.sh is a variable (label for docker image) which is set to git commit hash. This is fine but you can just copy and move ansible directory elsewhere out of git and this script breaks because of this. This change preserve previous functionality but only if the script is run inside a git repository otherwise it will skip setting the label for the built docker image. Change-Id: I23f828542efddde21d1c96116de7b20272ef23ef Issue-ID: OOM-1575 Signed-off-by: Petr OspalĂ˝ --- ansible/docker/build_ansible_image.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'ansible/docker') diff --git a/ansible/docker/build_ansible_image.sh b/ansible/docker/build_ansible_image.sh index d54ddc43..49833be5 100755 --- a/ansible/docker/build_ansible_image.sh +++ b/ansible/docker/build_ansible_image.sh @@ -27,14 +27,12 @@ image_name="${2:-ansible:latest}" script_path=$(readlink -f "$0") script_dir=$(dirname "$script_path") -git_commit=$(git rev-parse --revs-only HEAD) +git_commit=$(git rev-parse --revs-only HEAD || true) build_date=$(date -I) -if [ -z "$ansible_version" ]; then - docker build "$script_dir" -t "${image_name}" --label "git-commit=$git_commit" --label "build-date=$build_date" -else - docker build "$script_dir" -t "${image_name}" --label "git-commit=$git_commit" --label "build-date=$build_date" --build-arg ansible_version="$ansible_version" -fi +docker build "$script_dir" -t "${image_name}" --label "build-date=$build_date" \ + ${git_commit:+--label git-commit=${git_commit}} \ + ${ansible_version:+--build-arg ansible_version=${ansible_version}} # Export docker image into chroot and tararchive it. It takes ~40M of space and is packaged together with sw. if "${script_dir}"/create_docker_chroot.sh convert "${image_name}" "${script_dir}"/ansible_chroot ; then -- cgit 1.2.3-korg