forked from ambientum/ambientum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·85 lines (70 loc) · 2.14 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
#!/usr/bin/env bash
set -e
# source env only when not on travis-ci.
if [[ -z $TRAVIS ]]; then
# if there is a env file, source it
if [ -f "./.env" ]; then
source ./.env
# source example else
else
source ./.env.example
fi
fi
# enabled repositories for the build
REPOSITORIES=$1
# enable all repositories if any specified
if [[ -z $REPOSITORIES ]]; then
REPOSITORIES="mkcert php beanstalkd node"
fi
# for returning later to the main directory
ROOT_DIRECTORY=`pwd`
# function for building images
function build_repository {
# repository is the first argument.
REPOSITORY=$1;
# build mode is the second arg (--push|--load)
MODE=${2:-"--load"};
# target platform is the third arg (comma delimited).
PLATFORM=${3:-linux/amd64,linux/arm64};
# show building platforms.
echo "Build mode: ${MODE}";
echo "Building for platforms: ${PLATFORM}";
# read repository configuration
# shellcheck disable=SC1090
source $ROOT_DIRECTORY/$REPOSITORY/buildvars
# build all enabled versions
for TAG in $TAGS; do
# some verbose
echo $'\n\n'"--> Building $NAMESPACE/$REPOSITORY:$TAG"$'\n'
cd $ROOT_DIRECTORY/$REPOSITORY/$TAG
if [ $USE_CACHE == true ]; then
# build using cache
docker buildx build --platform $PLATFORM $MODE -t $NAMESPACE/$REPOSITORY:$TAG .
else
docker buildx build --platform $PLATFORM $MODE --no-cache -t $NAMESPACE/$REPOSITORY:$TAG .
fi
done
}
# 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
done
}
# for each enabled repository
for REPOSITORY in $REPOSITORIES; do
# If publishing is enabled
if [ $PUBLISH == true ]; then
# build the repository
build_repository $REPOSITORY "--push" $DOCKER_PLATFORM
else
# build the repository
build_repository $REPOSITORY "--load" $DOCKER_PLATFORM
fi
done