blob: 20a443b351b8cde3c4773f410e589dd4d394e6e0 [file] [log] [blame]
James E. King, III0ad20bd2017-09-30 15:44:16 -07001#!/bin/bash
2#
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
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
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
18# under the License.
19#
20
21#
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.
29#
30
31set -e
32
33SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
34. $SCRIPT_DIR/vars.sh
35
36function 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
41}
42
43#
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.
47#
48
49if [[ "$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.
52 exit 0
53fi
54
55
56pushd ${SCRIPT_DIR}/$DISTRO
57if dockerfile_changed; then
58 echo Dockerfile has not changed. No need to rebuild.
59 exit 0
60else
61 echo Dockerfile has changed.
62fi
63popd
64
65#
66# Dockerfile has changed
67#
68
69echo Rebuilding docker image $DISTRO
70docker build --tag $DOCKER_TAG build/docker/$DISTRO
71
72if [[ ! -z "$DOCKER_PASS" ]]; then
73 echo Pushing docker image $DOCKER_TAG
74 docker login -u $DOCKER_USER -p $DOCKER_PASS
75 docker push $DOCKER_TAG
76fi
77