Petr Ospalý | 6b44f82 | 2018-12-19 12:47:27 +0100 | [diff] [blame] | 1 | #! /usr/bin/env bash |
| 2 | |
| 3 | # COPYRIGHT NOTICE STARTS HERE |
| 4 | |
| 5 | # Copyright 2018 © Samsung Electronics Co., Ltd. |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | |
| 19 | # COPYRIGHT NOTICE ENDS HERE |
| 20 | |
| 21 | |
| 22 | set -e |
| 23 | |
| 24 | ansible_version="$1" |
| 25 | image_name="${2:-ansible:latest}" |
| 26 | |
| 27 | script_path=$(readlink -f "$0") |
| 28 | script_dir=$(dirname "$script_path") |
| 29 | |
Petr Ospalý | 14f5333 | 2019-01-18 10:34:27 +0100 | [diff] [blame^] | 30 | git_commit=$(git rev-parse --revs-only HEAD || true) |
Petr Ospalý | 6b44f82 | 2018-12-19 12:47:27 +0100 | [diff] [blame] | 31 | build_date=$(date -I) |
| 32 | |
Petr Ospalý | 14f5333 | 2019-01-18 10:34:27 +0100 | [diff] [blame^] | 33 | docker build "$script_dir" -t "${image_name}" --label "build-date=$build_date" \ |
| 34 | ${git_commit:+--label git-commit=${git_commit}} \ |
| 35 | ${ansible_version:+--build-arg ansible_version=${ansible_version}} |
Petr Ospalý | 6b44f82 | 2018-12-19 12:47:27 +0100 | [diff] [blame] | 36 | |
| 37 | # Export docker image into chroot and tararchive it. It takes ~40M of space and is packaged together with sw. |
| 38 | if "${script_dir}"/create_docker_chroot.sh convert "${image_name}" "${script_dir}"/ansible_chroot ; then |
| 39 | cd "$script_dir" |
| 40 | echo INFO: "Tarring and zipping the chroot directory..." >&2 |
| 41 | tar -czf ansible_chroot.tgz ansible_chroot |
| 42 | rm -rf "${script_dir}"/ansible_chroot |
| 43 | echo INFO: "Finished: ${script_dir}/ansible_chroot.tgz" >&2 |
| 44 | cd - |
| 45 | else |
| 46 | echo ERROR: "I failed to create a chroot environment" >&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | exit 0 |