3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
22 # The build has two stages: "docker" and "test"
23 # The "docker" stage is meant to rebuild the docker images
24 # if needed. If we cannot push that result however then
25 # there is no reason to do anything.
26 # The "test" stage is an actual test job. Even if the docker
27 # image doesn't match what's in the repo, we still build
28 # the image so the build job can run properly.
33 SCRIPT_DIR
="$(cd "$
(dirname "${BASH_SOURCE[0]}")" && pwd)"
34 DOCKER_TAG
=$DOCKER_REPO:$DISTRO
36 function dockerfile_changed
{
37 # image may not exist yet, so we have to let it fail silently:
38 docker pull
$DOCKER_TAG || true
39 docker run
$DOCKER_TAG bash
-c 'cd .. && sha512sum Dockerfile' > .Dockerfile.sha512
40 sha512sum
-c .Dockerfile.sha512
44 # If this build has no DOCKER_PASS and it is in the docker stage
45 # then there's no reason to do any processing because we cannot
46 # push the result if the Dockerfile changed.
49 if [[ "$TRAVIS_BUILD_STAGE" == "docker" ]] && [[ -z "$DOCKER_PASS" ]]; then
50 echo Detected docker stage build and no defined DOCKER_PASS
, this build job will be skipped.
51 echo Subsequent
jobs in the
test stage may each rebuild the docker image.
56 pushd ${SCRIPT_DIR}/$DISTRO
57 if dockerfile_changed
; then
58 echo Dockerfile has not changed. No need to rebuild.
61 echo Dockerfile has changed.
66 # Dockerfile has changed - rebuild it for the current build job.
67 # If it is a "docker" stage build then we want to push it back
68 # to the DOCKER_REPO. If it is a "test" stage build then we do
69 # not. If nobody defined a DOCKER_PASS then it doesn't matter.
72 echo Rebuilding docker image
$DISTRO
73 docker build
--tag $DOCKER_TAG build
/docker
/$DISTRO
75 if [[ "$TRAVIS_BUILD_STAGE" == "docker" ]] && [[ ! -z "$DOCKER_USER" ]] && [[ ! -z "$DOCKER_PASS" ]]; then
76 echo Pushing docker image
$DOCKER_TAG
77 docker login
-u $DOCKER_USER -p $DOCKER_PASS
78 docker push
$DOCKER_TAG
80 echo Not pushing docker image
: either not a docker stage build job
, or one of DOCKER_USER or DOCKER_PASS is undefined.