summaryrefslogtreecommitdiffstats
path: root/hack/build-images.sh
blob: 6e6d360bfc297c93a75b53553be2a7fc2d78bed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

STARTTIME=$(date +%s)
source_root=$(dirname "${0}")/..

prefix="openshift/origin-ansible"
version="latest"
verbose=false
options="-f images/installer/Dockerfile"
help=false

for args in "$@"
do
  case $args in
      --prefix=*)
        prefix="${args#*=}"
        ;;
      --version=*)
        version="${args#*=}"
        ;;
      --no-cache)
        options="${options} --no-cache"
        ;;
      --verbose)
        verbose=true
        ;;
     --help)
        help=true
        ;;
  esac
done

# allow ENV to take precedent over switches
prefix="${PREFIX:-$prefix}"
version="${OS_TAG:-$version}" 

if [ "$help" = true ]; then
  echo "Builds the docker images for openshift-ansible"
  echo
  echo "Options: "
  echo "  --prefix=PREFIX"
  echo "  The prefix to use for the image names."
  echo "  default: openshift/origin-ansible"
  echo
  echo "  --version=VERSION"
  echo "  The version used to tag the image (can be a comma-separated list)"
  echo "  default: latest"
  echo 
  echo "  --no-cache"
  echo "  If set will perform the build without a cache."
  echo
  echo "  --verbose"
  echo "  Enables printing of the commands as they run."
  echo
  echo "  --help"
  echo "  Prints this help message"
  echo
  exit 0
fi


if [ "$verbose" = true ]; then
  set -x
fi

BUILD_STARTTIME=$(date +%s)
comp_path=$source_root/

# turn comma-separated versions into -t args for docker build
IFS=',' read -r -a version_arr <<< "$version"
docker_tags=()
for tag in "${version_arr[@]}"; do
  docker_tags+=("-t" "${prefix}:${tag}")
done

echo
echo
echo "--- Building component '$comp_path' with docker tag(s) '$version' ---"
docker build ${options} "${docker_tags[@]}" $comp_path
BUILD_ENDTIME=$(date +%s); echo "--- ${version} took $(($BUILD_ENDTIME - $BUILD_STARTTIME)) seconds ---"
echo
echo

echo
echo
echo "++ Active images"
docker images | grep ${prefix} | sort
echo


ret=$?; ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds"; exit "$ret"