-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·118 lines (94 loc) · 2.64 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# Build script to build all docker images.
#
# This script needs some more love.
set -e
# WHAT can be native, amd64, arm or both
# If both is set then the images are ushed to the registry
export WHAT=$1
if [ -z $2 ]
then
export VERSIONS_TO_BUILD="81 82 83"
else
export VERSIONS_TO_BUILD="$2"
fi
if [ -z $3 ]
then
export SUFFiX=""
else
export SUFFIX="-$3"
fi
case $WHAT in
native)
export BUILD_CMD="docker build "
;;
amd64)
export PLATFORMS=linux/amd64
export BUILD_CMD="docker buildx build --push "
;;
arm64)
export PLATFORMS=linux/arm64
export BUILD_CMD="docker buildx build --push "
;;
both)
export PLATFORMS=linux/amd64,linux/arm64
export BUILD_CMD="docker buildx build --push --platform $PLATFORMS"
;;
*)
echo "Unknown what, should be native, amd64, arm64 or both."
echo "Run:"
echo "./build.sh <native|amd64|arm64|both> <versions-separated-by-spaces> <suffix>"
echo ""
echo "Example ./build.sh native 80 test, this will build php8.0 and tag it with test-suffix"
exit
;;
esac
function build_and_push_image() {
local php_version=$1
local base_image_tag=$2
local tag=$3
echo -e "\n\n\n--------"
echo "Building php $php_version with suffix $suffix and tag it with $tag ..."
echo -e "--------\n\n\n"
$BUILD_CMD \
--build-arg BASE_IMAGE_TAG=$base_image_tag \
-t factorial/drupal-docker:$tag \
-f Dockerfile.php-$php_version \
.
}
function build_node_and_push_image() {
local php_version=$1
local base_image_tag=$2
local suffix=$3
local node_versions=("12" "14" "16")
for node_version in "${node_versions[@]}"
do
local tag=php-$php_version-node-$node_version$suffix
echo -e "\n\n\n--------"
echo "Building node $node_version together with php $php_version with suffix $suffix and tag it with $tag ..."
echo -e "--------\n\n\n"
$BUILD_CMD \
--build-arg BASE_IMAGE_TAG=$base_image_tag \
--build-arg NODE_VERSION=$node_version \
-t factorial/drupal-docker:$tag \
-f Dockerfile.php-$php_version \
.
done
}
function build_version() {
local php_version=$1
local suffix=$2
echo "Building $php_version and tagging it with suffix $suffix"
cd php
build_and_push_image $php_version php-$1 php-$1$suffix
cd ../php-xdebug
build_and_push_image $php_version php-$1$suffix php-$php_version-xdebug$suffix
cd ../php-wkhtmltopdf
build_and_push_image $php_version php-$1$suffix php-$php_version-wkhtmltopdf$suffix
cd ../php-node
build_node_and_push_image $php_version php-$1$suffix $suffix
cd ..
}
for version in $VERSIONS_TO_BUILD; do
build_version $version $SUFFIX
done