forked from colinhoglund/docker-fpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·85 lines (71 loc) · 2.19 KB
/
build.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
GIT_ROOT=$(git rev-parse --show-toplevel)
function usage {
echo "Usage: $0 -a|-c|-tdockerfile
Options:
-a, --all Build all Docker images
-c, --changed Build Docker images that have changed since previous git revision
-h, --help Show this help message
-p, --publish Publish containers"
}
function update_travis_build_matrix {
travis_file=$GIT_ROOT/.travis.yml
touch $travis_file
# .travis.yml pre-config
echo 'sudo: required
# skip language installation steps for docker builds
install: true
services:
- docker
env:' > $travis_file
# append images/scripts to test
travis_tests=$(git ls-files | egrep 'Dockerfile|build_scripts')
for t in $travis_tests; do
echo " - TEST: ${t}" >> $travis_file
done
# .travis.yml post-config
printf "\nscript: ./tests.sh\n" >> $travis_file
}
# get images to build based on command line flag
for var in $@; do
case $var in
-a|--all)
# get all Dockerfiles
IMAGES=$(git ls-files *Dockerfile)
shift
;;
-c|--changed)
# get all Dockerfiles that have changed since previous revision
IMAGES=$(git diff --diff-filter=ACMR --name-only HEAD^ *Dockerfile)
shift
;;
-h|--help)
usage
exit 0
;;
-p|--publish)
PUBLISH=0
shift
;;
*)
shift
;;
esac
done
if [ -n $IMAGES ]; then
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
fi
for i in $IMAGES; do
# replace / with - to get the docker tag value
tag=$(dirname $i | sed 's/\//-/g')
# build each newly changed Dockerfile
echo "Building fpm:${tag} image from ${i}:"
cd $(dirname ${GIT_ROOT}/${i})
docker build -t fpm:${tag} .
echo "Publish: $PUBLISH"
if [ $PUBLISH ]; then
echo "Publishing ${tag}"
docker tag fpm:${tag} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/fpm:${tag}
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/fpm:${tag}
fi
done