2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
8 echo >&2 "usage: $0 [options]"
10 echo >&2 "$0 options:"
11 echo >&2 " -t, --tags version tag for docker"
12 echo >&2 " -u, --upload Upload the images (docker push)"
13 echo >&2 " --no-cache Don't use build cache"
14 echo >&2 " -h, --help Display this help and exit"
16 echo >&2 " If no options are given, just builds the images."
20 # NOTE: This requires GNU getopt (part of the util-linux package on Debian-based distros).
21 TEMP=`getopt -o hut: \
22 --long help,upload,no-cache,tags: \
25 if [ $? != 0 ] ; then echo "Use -h for help"; exit 1 ; fi
26 # Note the quotes around `$TEMP': they are essential!
43 echo "ERROR: --tags needs a parameter";
73 . $WORKSPACE/build/run-library.sh
76 # Sometimes docker push fails; retry it a few times if necessary.
77 for i in `seq 1 5`; do
80 if [[ "$ECODE" == "0" ]]; then
85 if [[ "$ECODE" != "0" ]]; then
86 EXITCODE=$(($EXITCODE + $ECODE))
88 checkexit $ECODE "docker push $*"
92 if ! [[ -n "$WORKSPACE" ]]; then
94 echo >&2 "Error: WORKSPACE environment variable not set"
101 # find the docker binary
102 DOCKER=`which docker.io`
104 if [[ "$DOCKER" == "" ]]; then
105 DOCKER=`which docker`
108 if [[ "$DOCKER" == "" ]]; then
109 title "Error: you need to have docker installed. Could not find the docker executable."
114 title "Starting docker build"
118 # clean up the docker build environment
121 if [[ -z "$ARVADOS_BUILDING_VERSION" ]] && ! [[ -z "$version_tag" ]]; then
122 ARVADOS_BUILDING_VERSION="$version_tag"
123 ARVADOS_BUILDING_ITERATION="1"
126 python_sdk_ts=$(cd sdk/python && timestamp_from_git)
127 cwl_runner_ts=$(cd sdk/cwl && timestamp_from_git)
129 python_sdk_version=$(cd sdk/python && nohash_version_from_git 0.1)
130 cwl_runner_version=$(cd sdk/cwl && nohash_version_from_git 1.0)
132 if [[ $python_sdk_ts -gt $cwl_runner_ts ]]; then
133 cwl_runner_version=$(cd sdk/python && nohash_version_from_git 1.0)
136 echo cwl_runner_version $cwl_runner_version python_sdk_version $python_sdk_version
138 if [[ "${python_sdk_version}" != "${ARVADOS_BUILDING_VERSION}" ]]; then
139 python_sdk_version="${python_sdk_version}-1"
141 python_sdk_version="${ARVADOS_BUILDING_VERSION}-${ARVADOS_BUILDING_ITERATION}"
144 cwl_runner_version_orig=$cwl_runner_version
146 if [[ "${cwl_runner_version}" != "${ARVADOS_BUILDING_VERSION}" ]]; then
147 cwl_runner_version="${cwl_runner_version}-1"
149 cwl_runner_version="${ARVADOS_BUILDING_VERSION}-${ARVADOS_BUILDING_ITERATION}"
153 docker build $NOCACHE \
154 --build-arg python_sdk_version=${python_sdk_version} \
155 --build-arg cwl_runner_version=${cwl_runner_version} \
156 -t arvados/jobs:$cwl_runner_version_orig .
160 if [[ "$ECODE" != "0" ]]; then
161 EXITCODE=$(($EXITCODE + $ECODE))
164 checkexit $ECODE "docker build"
165 title "docker build complete (`timer`)"
167 if [[ "$ECODE" != "0" ]]; then
173 if docker --version |grep " 1\.[0-9]\." ; then
174 # Docker version prior 1.10 require -f flag
175 # -f flag removed in Docker 1.12
178 if ! [[ -z "$version_tag" ]]; then
179 docker tag $FORCE arvados/jobs:$cwl_runner_version_orig arvados/jobs:"$version_tag"
181 docker tag $FORCE arvados/jobs:$cwl_runner_version_orig arvados/jobs:latest
186 if [[ "$ECODE" != "0" ]]; then
187 EXITCODE=$(($EXITCODE + $ECODE))
190 checkexit $ECODE "docker tag"
191 title "docker tag complete (`timer`)"
193 title "uploading images"
197 if [[ "$ECODE" != "0" ]]; then
198 title "upload arvados images SKIPPED because build or tag failed"
200 if [[ $upload == true ]]; then
201 ## 20150526 nico -- *sometimes* dockerhub needs re-login
202 ## even though credentials are already in .dockercfg
203 docker login -u arvados
204 if ! [[ -z "$version_tag" ]]; then
205 docker_push arvados/jobs:"$version_tag"
207 docker_push arvados/jobs:$cwl_runner_version_orig
208 docker_push arvados/jobs:latest
210 title "upload arvados images finished (`timer`)"
212 title "upload arvados images SKIPPED because no --upload option set (`timer`)"