forked from pimcore/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·145 lines (116 loc) · 6.83 KB
/
update.sh
File metadata and controls
executable file
·145 lines (116 loc) · 6.83 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
set -Eeuo pipefail
buildDir=build/php
versions=( $buildDir/* )
versions=( "${versions[@]%/}" )
infoHeader="#\n# NOTE: THIS DOCKERFILE IS GENERATED VIA update.sh\n#\n# PLEASE DO NOT EDIT IT DIRECTLY.\n#"
for version in "${versions[@]}"; do
version=$(basename ${version})
rcVersion="${version%-rc}"
echo $version
#continue
# "7", "5", etc
majorVersion="${rcVersion%%.*}"
# "2", "1", "6", etc
minorVersion="${rcVersion#$majorVersion.}"
minorVersion="${minorVersion%%.*}"
dockerfiles=()
baseDockerfile=Dockerfile.template
for variant in cli fpm; do
[ -d "$buildDir/$version/$variant" ] || continue
for distribution in buster bullseye; do
[ -d "$buildDir/$version/$variant/$distribution" ] || continue
for debug in debug no-debug; do
cp $baseDockerfile "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
envBlock="$variant"
variantEnvVar="${version}-${variant}-env-Dockerfile-block-1"
if [ -f $variantEnvVar ]; then
envBlock="${version}-${variant}"
fi
echo "Generating $buildDir/$version/$variant/$distribution/$debug/Dockerfile from $baseDockerfile + $envBlock-env-Dockerfile-block-*"
gawk -i inplace -v env="$envBlock" '
$1 == "##</env>##" { ia = 0 }
!ia { print }
$1 == "##<env>##" { ia = 1; ab++; ac = 0; if (system("test -f " env "-env-Dockerfile-block-" ab) != 0) { ia = 0 } }
ia { ac++ }
ia && ac == 1 { system("cat " env "-env-Dockerfile-block-" ab) }
' "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
echo "Generating $buildDir/$version/$variant/$distribution/$debug/Dockerfile from $baseDockerfile + $variant-Dockerfile-block-*"
gawk -i inplace -v variant="$variant" '
$1 == "##</autogenerated>##" { ia = 0 }
!ia { print }
$1 == "##<autogenerated>##" { ia = 1; ab++; ac = 0; if (system("test -f " variant "-Dockerfile-block-" ab) != 0) { ia = 0 } }
ia { ac++ }
ia && ac == 1 { system("cat " variant "-Dockerfile-block-" ab) }
' "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
echo "Generating $buildDir/$version/$variant/$distribution/$debug/Dockerfile from $baseDockerfile + $version-Dockerfile-block-*"
gawk -i inplace -v variant="$version" '
$1 == "##</version>##" { ia = 0 }
!ia { print }
$1 == "##<version>##" { ia = 1; ab++; ac = 0; if (system("test -f " variant "-Dockerfile-block-" ab) != 0) { ia = 0 } }
ia { ac++ }
ia && ac == 1 { system("cat " variant "-Dockerfile-block-" ab) }
' "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
debugBlock="$debug"
if [ debug = 'debug' ]; then
versionDebugFile="${debug}-${version}-Dockerfile-block-1"
if [ -f $versionDebugFile ]; then
debugBlock="${debug}-${version}"
else
debugBlock="$debug"
fi
fi
echo "Generating $buildDir/$version/$variant/$distribution/$debug/Dockerfile from $baseDockerfile + $debugBlock-Dockerfile-block-*"
gawk -i inplace -v variant="$debugBlock" '
$1 == "##</debug>##" { ia = 0 }
!ia { print }
$1 == "##<debug>##" { ia = 1; ab++; ac = 0; if (system("test -f " variant "-Dockerfile-block-" ab) != 0) { ia = 0 } }
ia { ac++ }
ia && ac == 1 { system("cat " variant "-Dockerfile-block-" ab) }
' "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
echo "Generating $buildDir/$version/$variant/$distribution/$debug/Dockerfile from $baseDockerfile + $distribution-Dockerfile-block-*"
gawk -i inplace -v distribution="$distribution" '
$1 == "##</distribution>##" { ia = 0 }
!ia { print }
$1 == "##<distribution>##" { ia = 1; ab++; ac = 0; if (system("test -f " variant "-Dockerfile-block-" ab) != 0) { ia = 0 } }
ia { ac++ }
ia && ac == 1 { system("cat " variant "-Dockerfile-block-" ab) }
' "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
if [ -d "files/$variant/" ]; then
echo "Copy from files/$variant to $buildDir/$version/$variant/$distribution/$debug"
cp -rf "files/$variant/." $buildDir/$version/$variant/$distribution/$debug/
fi
if [ -d "files/$debug/" ]; then
echo "Copy from files/$debug to $buildDir/$version/$variant/$distribution/$debug"
cp -rf "files/$debug/." $buildDir/$version/$variant/$distribution/$debug/
fi
if [ -d "files/$distribution/$debug/" ]; then
echo "Copy from files/$distribution/$debug to $buildDir/$version/$variant/$distribution/$debug"
cp -rf "files/$distribution/$debug/." $buildDir/$version/$variant/$distribution/$debug/
fi
if [ -d "files/$version/$debug/" ]; then
echo "Copy from files/$version/$debug to $buildDir/$version/$variant/$distribution/$debug"
cp -rf "files/$version/$debug/." $buildDir/$version/$variant/$distribution/$debug/
fi
if [ -d "files/$version/$variant/" ]; then
echo "Copy from files/$version/$variant to $buildDir/$version/$variant/$distribution/$debug"
cp -rf "files/$version/$variant/." $buildDir/$version/$variant/$distribution/$debug/
fi
# remove any _extra_ blank lines created by the deletions above
awk '
NF > 0 { blank = 0 }
NF == 0 { ++blank }
blank < 2 { print }
' "$buildDir/$version/$variant/$distribution/$debug/Dockerfile" > "$buildDir/$version/$variant/$distribution/$debug/Dockerfile.new"
mv "$buildDir/$version/$variant/$distribution/$debug/Dockerfile.new" "$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
sed -i "s/#%%INFO_HEADER%%/${infoHeader}/" "$buildDir/$version/$variant/$distribution/$debug/"*
sed -ri \
-e 's!%%PHP_TAG%%!'"$version"'!' \
-e 's!%%IMAGE_VARIANT%%!'"$variant"'!' \
-e 's!%%DISTRIBUTION%%!'"$distribution"'!' \
"$buildDir/$version/$variant/$distribution/$debug/Dockerfile"
dockerfiles+=( "$buildDir/$version/$variant/$distribution/$debug/Dockerfile" )
done
done
done
done