-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·159 lines (134 loc) · 4.46 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
152
153
154
155
156
157
158
159
#!/bin/bash
set -Eeo pipefail
release=$1
_template() {
sed -e 's/\\/\\\\/g' $1 | sed -E ':a;N;$!ba;s/\r{0,1}\n/%0A/g'
}
minVersion=0
variants="apache fpm fpm-alpine"
versions="$minVersion main"
declare -A php_version=(
[default]='8.0'
)
declare -A install=(
[default]=$(_template .templates/Dockerfile-install.template)
[main]=$(_template .templates/Dockerfile-install-main.template)
)
declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
)
declare -A base=(
[apache]='debian'
[fpm]='debian'
[fpm-alpine]='alpine'
)
declare -A document=(
[apache]=$(_template .templates/Dockerfile-apache.template)
[fpm]=''
[fpm-alpine]=''
)
declare -A fetchDeps=(
[debian]="gnupg"
[alpine]="bzip2 gnupg"
)
label=$(_template .templates/Dockerfile-label.template)
echo Initialisation
apcu_version="$(
git ls-remote --tags https://github.com/krakjoe/apcu.git \
| cut -d/ -f3 \
| grep -vE -- '-rc|-b' \
| sed -E 's/^v//' \
| sort -V \
| tail -1
)"
echo " APCu version: $apcu_version"
memcached_version="$(
git ls-remote --tags https://github.com/php-memcached-dev/php-memcached.git \
| cut -d/ -f3 \
| grep -vE -- '-rc|-b' \
| sed -E 's/^[rv]//' \
| sort -V \
| tail -1
)"
echo " Memcached version: $memcached_version"
redis_version="$(
git ls-remote --tags https://github.com/phpredis/phpredis.git \
| cut -d/ -f3 \
| grep -viE '[a-z]' \
| tr -d '^{}' \
| sort -V \
| tail -1
)"
echo " Redis version: $redis_version"
declare -A pecl_versions=(
[APCu]="$apcu_version"
[memcached]="$memcached_version"
[redis]="$redis_version"
)
_githubapi() {
if [ -n "${GITHUB_TOKEN:-}" ]; then
curl -fsSL -H "Authorization: token $GITHUB_TOKEN" $1;
else
curl -fsSL $1;
fi
}
if [ -z "$release" ]; then
release="$(_githubapi 'https://api.github.com/repos/officelifehq/officelife/releases/latest' | jq -r '.tag_name' || _githubapi 'https://api.github.com/repos/officelifehq/officelife/releases' | jq -r '.[0].tag_name')"
fi
echo " OfficeLife version: $release"
commit="$(_githubapi 'https://api.github.com/repos/officelifehq/officelife/tags' | jq -r 'map(select(.name | contains ("'$release'"))) | .[].commit.sha')"
echo " Commit: $commit"
head=$(_template .templates/Dockerfile-head.template)
foot=$(_template .templates/Dockerfile-foot.template)
extra=$(_template .templates/Dockerfile-extra.template)
install=$(_template .templates/Dockerfile-install.template)
postinstall=$(_template .templates/Dockerfile-postinstall.template)
for version in $versions; do
if [ "$version" != "main" ]; then
echo ${release#v} > $version/version
fi
for variant in $variants; do
echo Generating $version/$variant variant...
rm -rf $version/$variant
mkdir -p $version/$variant
basev=${base[$variant]}
phpVersion=${php_version[$version]-${php_version[default]}}
inst=${install[$version]-${install[default]}}
fetchDep=${fetchDeps[$basev]}
extra_install=$extra
officelife_version=$release
officelife_commit=$commit
if [ "$version" == "main" ]; then
officelife_version="main"
officelife_commit=""
extra_install="$extra_install%0ACOPY officelife-\${OFFICELIFE_VERSION}.tar.bz2 ."
fi
template="Dockerfile-$basev.template"
sed -e '
s@&&@&&@;
s@%%HEAD%%@'"$head"'@;
s@%%FOOT%%@'"$foot"'@;
s@%%EXTRA_INSTALL%%@'"$extra_install"'@;
s@%%INSTALL%%@'"$inst"'@;
s@%%POSTINSTALL%%@'"$postinstall"'@;
s@%%FETCHDEPS%%@'"$fetchDep"'@;
s/%%VARIANT%%/'"$variant"'/;
s/%%PHP_VERSION%%/'"$phpVersion"'/;
s#%%LABEL%%#'"$label"'#;
s/%%VERSION%%/'"$officelife_version"'/g;
s/%%COMMIT%%/'"$officelife_commit"'/;
s/%%CMD%%/'"${cmd[$variant]}"'/;
s#%%APACHE_DOCUMENT%%#'"${document[$variant]}"'#;
s/%%APCU_VERSION%%/'"${pecl_versions[APCu]}"'/;
s/%%MEMCACHED_VERSION%%/'"${pecl_versions[memcached]}"'/;
s/%%REDIS_VERSION%%/'"${pecl_versions[redis]}"'/;
' \
-e "s/%0A/\n/g;" \
$template > "$version/$variant/Dockerfile"
for file in entrypoint cron queue; do
cp docker-$file.sh $version/$variant/$file.sh
done
done
done