forked from olbat/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·37 lines (32 loc) · 950 Bytes
/
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
#!/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
tag=${filename##*.}
[ "$filename" == "$tag" ] && tag=latest # no file extension
args+=" --build-arg BASE_TAG=$tag"
timeout 300 docker build $args -t $user/$dirname:$tag $dirname/
[ $PUSH ] && docker push $user/$dirname:$tag
fi
done