diff options
author | Petr Ospalý <p.ospaly@partner.samsung.com> | 2019-01-18 10:34:27 +0100 |
---|---|---|
committer | Petr Ospalý <p.ospaly@partner.samsung.com> | 2019-01-24 15:22:46 +0100 |
commit | 14f53333e9202a767b3a3d171f5e8d2b4f6dacd0 (patch) | |
tree | 51431c23214442ccc514b17a159e55119c7148a3 /ansible/docker | |
parent | a2382319684880aabd05678ed1c5ce63363ca1a9 (diff) |
Enable to build ansible image out of git directory
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ý <p.ospaly@partner.samsung.com>
Diffstat (limited to 'ansible/docker')
-rwxr-xr-x | ansible/docker/build_ansible_image.sh | 10 |
1 files changed, 4 insertions, 6 deletions
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 |