forked from olbat/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·48 lines (40 loc) · 1.09 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
#!/bin/bash
set -e
set -x
. build.env
buildargs="--build-arg BASE_USER=$BASE_USER"
buildargs+=" --build-arg MAINTAINER=$MAINTAINER"
user=${BUILD_USER:-olbat}
dir=${IMAGE%/}
for dockerfile in ${dir:-*}/Dockerfile*
do
[ -e $dockerfile ] || (echo "ERROR: file not found $dockerfile"; exit 1)
dirname=$(dirname "$dockerfile")
filename=$(basename "$dockerfile")
args="--pull -f $dockerfile $buildargs"
if [ -f $dirname/tags.env -a $filename == "Dockerfile" ]
then
BASE_TAGS=
. $dirname/tags.env
for tag in $BASE_TAGS
do
args+=" --build-arg BASE_TAG=$tag"
timeout 300 docker build $args -t $user/$dirname:$tag $dirname/
[ $PUSH ] && docker push $user/$dirname:$tag
done
else
[ "$filename" == "Dockerfile" ] && tag=latest || tag=${filename##*.}
args+=" --build-arg BASE_TAG=$tag"
timeout 300 docker build $args -t $user/$dirname:$tag $dirname/
if [ $PUSH ]
then
docker push $user/$dirname:$tag
if [ "$tag" == "latest" ]
then
today=$(date +%Y-%m-%d)
docker tag $user/$dirname:$tag $user/$dirname:$today
docker push $user/$dirname:$today
fi
fi
fi
done