forked from pimcore/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·151 lines (123 loc) · 6.49 KB
/
update.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
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
146
147
148
149
150
151
#!/usr/bin/env bash
set -Eeuo pipefail
versions=( */ )
versions=( "${versions[@]%/}" )
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
for version in "${versions[@]}"; do
if [[ "$version" == "files" ]]; then
continue
fi
rcVersion="${version%-rc}"
echo $version
# "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 "$version/$variant" ] || continue
for distribution in buster bullseye; do
[ -d "$version/$variant/$distribution" ] || continue
for debug in debug no-debug; do
{ generated_warning; cat "$baseDockerfile"; } > "$version/$variant/$distribution/$debug/Dockerfile"
envBlock="$variant"
variantEnvVar="${version}-${variant}-env-Dockerfile-block-1"
if [ -f $variantEnvVar ]; then
envBlock="${version}-${variant}"
fi
echo "Generating $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) }
' "$version/$variant/$distribution/$debug/Dockerfile"
echo "Generating $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) }
' "$version/$variant/$distribution/$debug/Dockerfile"
echo "Generating $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) }
' "$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 $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) }
' "$version/$variant/$distribution/$debug/Dockerfile"
echo "Generating $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) }
' "$version/$variant/$distribution/$debug/Dockerfile"
if [ -d "files/$variant/" ]; then
echo "Copy from files/$variant to $version/$variant/$distribution/$debug"
cp -rf "files/$variant/." $version/$variant/$distribution/$debug/
fi
if [ -d "files/$debug/" ]; then
echo "Copy from files/$debug to $version/$variant/$distribution/$debug"
cp -rf "files/$debug/." $version/$variant/$distribution/$debug/
fi
if [ -d "files/$distribution/$debug/" ]; then
echo "Copy from files/$distribution/$debug to $version/$variant/$distribution/$debug"
cp -rf "files/$distribution/$debug/." $version/$variant/$distribution/$debug/
fi
if [ -d "files/$version/$debug/" ]; then
echo "Copy from files/$version/$debug to $version/$variant/$distribution/$debug"
cp -rf "files/$version/$debug/." $version/$variant/$distribution/$debug/
fi
if [ -d "files/$version/$variant/" ]; then
echo "Copy from files/$version/$variant to $version/$variant/$distribution/$debug"
cp -rf "files/$version/$variant/." $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 }
' "$version/$variant/$distribution/$debug/Dockerfile" > "$version/$variant/$distribution/$debug/Dockerfile.new"
mv "$version/$variant/$distribution/$debug/Dockerfile.new" "$version/$variant/$distribution/$debug/Dockerfile"
sed -ri \
-e 's!%%PHP_TAG%%!'"$version"'!' \
-e 's!%%IMAGE_VARIANT%%!'"$variant"'!' \
-e 's!%%DISTRIBUTION%%!'"$distribution"'!' \
"$version/$variant/$distribution/$debug/Dockerfile"
dockerfiles+=( "$version/$variant/$distribution/$debug/Dockerfile" )
done
done
done
done