forked from edbizarro/gitlab-ci-pipeline-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·81 lines (65 loc) · 2.36 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
#!/bin/bash
# resulting images namespace on docker hub
NAMESPACE=edbizarro/gitlab-ci-pipeline
# publish the built images
PUBLISH=true
# enabled repositories for the build
REPOSITORIES=$1
# enable all repositories if any specified
if [[ -z $REPOSITORIES ]]; then
REPOSITORIES="php"
fi
# for returning later to the main directory
ROOT_DIRECTORY=`pwd`
# function for building images
function build_repository {
# read repository configuration
source $ROOT_DIRECTORY/$REPOSITORY/buildvars
# build all enabled versions
for TAG in $TAGS; do
# some verbose
echo $'\n\n'"--> Building $NAMESPACE-$REPOSITORY:$TAG"$'\n'
docker build -t $NAMESPACE-$REPOSITORY:$TAG -f $ROOT_DIRECTORY/$REPOSITORY/$TAG/Dockerfile .
for VARI in $VARIANT; do
if [ -d "$ROOT_DIRECTORY/$REPOSITORY/$TAG/$VARI" ]; then
echo $'\n\n'"--> Building variant $NAMESPACE-$REPOSITORY:$TAG-$VARI"$'\n'
docker build -t $NAMESPACE-$REPOSITORY:$TAG-$VARI -f $ROOT_DIRECTORY/$REPOSITORY/$TAG/$VARI/Dockerfile .
fi
done
done
# create the latest tag
echo $'\n\n'"--> Aliasing $LATEST as 'latest'"$'\n'
docker tag $NAMESPACE-$REPOSITORY:$LATEST $NAMESPACE-$REPOSITORY:latest
}
# function for publishing images
function publish_repository {
# read repository configuration
source $ROOT_DIRECTORY/$REPOSITORY/buildvars
# publish all enabled versions
for TAG in $TAGS; do
# some verbose
echo $'\n\n'"--> Publishing $NAMESPACE-$REPOSITORY:$TAG"$'\n'
# publish
docker push $NAMESPACE-$REPOSITORY:$TAG
for VARI in $VARIANT; do
if [ -d "$ROOT_DIRECTORY/$REPOSITORY/$TAG/$VARI" ]; then
echo $'\n\n'"--> Building variant $NAMESPACE-$REPOSITORY:$TAG-$VARI"$'\n'
docker push $NAMESPACE-$REPOSITORY:$TAG-$VARI
fi
done
done
# create the latest tag
echo $'\n\n'"--> Publishing $NAMESPACE-$REPOSITORY:latest (from $LATEST)"$'\n'
docker push $NAMESPACE-$REPOSITORY:latest
}
# for each enabled repository
for REPOSITORY in $REPOSITORIES; do
# build the repository
build_repository $REPOSITORY
# If publishing is enabled
if [ $PUBLISH == true ]; then
# Push the built image
publish_repository $REPOSITORY
fi
done
curl -XPOST https://hooks.microbadger.com/images/edbizarro/gitlab-ci-pipeline-php/rDYTTzaY7CxoUFxH5jqjPLS3Lyk=