-
Notifications
You must be signed in to change notification settings - Fork 75
/
build.sh
executable file
·65 lines (51 loc) · 1.42 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
#!/bin/bash
set -euo pipefail
set -x
# important: images are automatically built from a different script,
# see .gitlab-ci/generate-jobs-file.sh
. build.env
basebuildargs="--build-arg BASE_USER=$BASE_USER"
basebuildargs+=" --build-arg MAINTAINER=$MAINTAINER"
user=${BUILD_USER:-olbat}
dir=${IMAGE:-*}
dir=${dir%/}
function build_and_push_docker_image {
local imagename=$1
local tag=$2
local dirname=$3
local buildargs=$4
buildargs+=" --build-arg BASE_TAG=$tag"
timeout 300 docker build $buildargs -t $imagename:$tag $dirname/
if [ ${PUSH_IMAGES:-} ]
then
docker push $imagename:$tag
today=$(date +%Y-%m-%d)
if [ "$tag" == "latest" ]
then
docker tag $imagename:$tag $imagename:$today
docker push $imagename:$today
else
docker tag $imagename:$tag $imagename:$tag-$today
docker push $imagename:$tag-$today
fi
fi
}
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 $basebuildargs"
if [ -f $dirname/tags.env -a $filename == "Dockerfile" ]
then
BASE_TAGS=
. $dirname/tags.env
for tag in $BASE_TAGS
do
build_and_push_docker_image $user/$dirname $tag $dirname "$args"
done
else
[ "$filename" == "Dockerfile" ] && tag=latest || tag=${filename##*.}
build_and_push_docker_image $user/$dirname $tag $dirname "$args"
fi
done