forked from neomantra/docker-onload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_build_and_push_flavor.sh
More file actions
executable file
·55 lines (43 loc) · 1.28 KB
/
docker_build_and_push_flavor.sh
File metadata and controls
executable file
·55 lines (43 loc) · 1.28 KB
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
#!/bin/bash -x
# Builds and pushes flavors, with image names based on TRAVIS variables
#
# ./docker_build_and_push_flavor.sh FLAVOR [DOCKERFILE_PATH] [BUILD PARAMS]
#
# Environment Variables
# DOCKER_ORG
# DOCKER_PASSFILE
# IMAGE_NAME
# TRAVIS_BRANCH
# TRAVIS_TAG
#
# Docker password is read from DOCKER_PASSFILE
# We do his because this script uses -x for build transparency
# and we don't want to leak passwords
set -e
if [ -z "$DOCKER_ORG" ] ; then
echo "missing env DOCKER_ORG" >&2
exit 1
fi
FLAVOR="$1"
shift
DOCKERFILE_PATH=${1:-$FLAVOR/Dockerfile}
shift
DOCKER_BUILD_PARAMS="$@"
IMAGE_NAME="${IMAGE_NAME:-onload}"
docker_login_from_file () {
if [ -f "$DOCKER_PASSFILE" ] ; then
cat "$DOCKER_PASSFILE" | docker login -u="$DOCKER_USERNAME" --password-stdin
fi
}
docker_login_from_file
docker build -t $IMAGE_NAME:$FLAVOR -f $DOCKERFILE_PATH $DOCKER_BUILD_PARAMS .
if [[ "$TRAVIS_BRANCH" == "master" ]] ; then
docker_login_from_file &&
docker tag $IMAGE_NAME:$FLAVOR $DOCKER_ORG/$IMAGE_NAME:$FLAVOR &&
docker push $DOCKER_ORG/$IMAGE_NAME:$FLAVOR ;
fi
if [[ "$TRAVIS_TAG" ]] ; then
docker_login_from_file &&
docker tag $IMAGE_NAME:$FLAVOR $DOCKER_ORG/$IMAGE_NAME:$TRAVIS_TAG-$FLAVOR &&
docker push $DOCKER_ORG/$IMAGE_NAME:$TRAVIS_TAG-$FLAVOR ;
fi