Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 81287b9

Browse files
committed
CI: Re-use the built docker image between stages
1 parent d32171d commit 81287b9

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

.travis.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,34 @@ env:
2828

2929
jobs:
3030
include:
31+
- stage: Docker build (re-use in stages)
32+
env: step=build_push
33+
script:
34+
- travis_retry ./test/before_install_build
35+
3136
- stage: Integration and Unit Tests
3237
env: test=scenario_basic__restart
3338
script:
34-
- travis_retry ./test/before_install_build
39+
- travis_retry ./test/before_install_pull
3540
- travis_retry ./test/script_scenario_basic
3641
- travis_retry ./test/script_scenario_restart
3742

3843
- env: test=scenario_node_dies
3944
script:
40-
- travis_retry ./test/before_install_build
45+
- travis_retry ./test/before_install_pull
4146
- travis_retry ./test/script_scenario_node_dies
4247

4348
- env: test=scenario_make
4449
script:
45-
- travis_retry ./test/before_install_build
50+
- travis_retry ./test/before_install_pull
4651
- travis_retry ./test/script_scenario_make
4752

4853
- env: test=scenario_compose_N_N
4954
script:
50-
- travis_retry ./test/before_install_build
55+
- travis_retry ./test/before_install_pull
5156
- travis_retry ./test/script_scenario_compose_N_N
5257

5358
- stage: Push Image (only with a tag) & Git push
5459
script:
55-
- travis_retry ./test/before_install_build
60+
- travis_retry ./test/before_install_pull
5661
- ./test/script_push

test/before_install_build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ docker-compose --version
1111

1212
docker build -t selenium .
1313
docker images selenium
14+
15+
if [ "${TRAVIS_BUILD_NUMBER}" != "" ]; then
16+
# Let's push this image to re-use it in TravisCI stages
17+
# in order to speed up the build
18+
docker tag selenium:latest elgalu/build_selenium:${TRAVIS_BUILD_NUMBER}
19+
20+
[ "${DOCKER_USERNAME}" == "" ] && die "Need env var DOCKER_USERNAME to push to docker"
21+
[ "${DOCKER_PASSWORD}" == "" ] && die "Need env var DOCKER_PASSWORD to push to docker"
22+
23+
docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}"
24+
echo "Logged in to docker with user '${DOCKER_USERNAME}'"
25+
26+
docker push elgalu/build_selenium:${TRAVIS_BUILD_NUMBER}
27+
fi

test/before_install_pull

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# set -e: exit asap if a command exits with a non-zero status
4+
# set -x: print each command right before it is executed
5+
set -xe
6+
7+
echoerr() { printf "%s\n" "$*" >&2; }
8+
9+
# print error and exit
10+
die () {
11+
echoerr "ERROR: $1"
12+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "150"
13+
errnum=${2-133}
14+
exit $errnum
15+
}
16+
17+
docker --version
18+
docker-compose --version
19+
20+
[ "${TRAVIS_BUILD_NUMBER}" == "" ] && die "Need env var TRAVIS_BUILD_NUMBER to know where to pull from"
21+
22+
docker pull elgalu/build_selenium:${TRAVIS_BUILD_NUMBER}
23+
docker tag elgalu/build_selenium:${TRAVIS_BUILD_NUMBER} selenium:latest
24+
docker images selenium

test/script_push

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ die () {
2323
#######################################
2424
docker_login_tag_push() {
2525
echo "script_push::docker_login_tag_push"
26+
27+
[ "${DOCKER_USERNAME}" == "" ] && die "Need env var DOCKER_USERNAME to push to docker"
28+
[ "${DOCKER_PASSWORD}" == "" ] && die "Need env var DOCKER_PASSWORD to push to docker"
29+
2630
# -e="$DOCKER_EMAIL"
27-
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
31+
docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}"
2832
echo "Logged in to docker with user '${DOCKER_USERNAME}'"
2933
echo "docker tag and docker push using TRAVIS_TAG=${TRAVIS_TAG}"
3034
docker tag selenium:latest elgalu/selenium:${TRAVIS_TAG}

0 commit comments

Comments
 (0)