-
Notifications
You must be signed in to change notification settings - Fork 61
/
update.sh
executable file
·146 lines (120 loc) · 3.57 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
#!/bin/bash
set -e
IFS='
'
_template() {
sed -e 's/\\/\\\\/g' $1 | sed -E ':a;N;$!ba;s/\r{0,1}\n/%0A/g'
}
releases=(
4
5
)
variants=(
apache
fpm
fpm-alpine
)
declare -A php_version=(
[default]='8.3'
[5]='8.3'
[4]='8.2'
)
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]=''
)
label=$(_template .templates/Dockerfile-label.template)
echo Initialisation
apcu_version="$(
git ls-remote --tags https://github.com/krakjoe/apcu.git \
| cut -d/ -f3 \
| grep -viE -- '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 -viE -- '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
}
head=$(_template .templates/Dockerfile-head.template)
extra=$(_template .templates/Dockerfile-extra.template)
install=$(_template .templates/Dockerfile-install.template)
if [ -n "${1:-}" ]; then
releases=( "$1" )
fi
if [ -n "${2:-}" ]; then
variants=( "$2" )
fi
for release in "${releases[@]}"; do
echo "Processing release $release"
version="$(_githubapi 'https://api.github.com/repos/monicahq/monica/releases' | jq -r 'map(select(.tag_name | startswith ("v'$release'"))) | .[0].tag_name')"
echo " Monica version: $version"
commit="$(_githubapi 'https://api.github.com/repos/monicahq/monica/tags' | jq -r 'map(select(.name | contains ("'$version'"))) | .[].commit.sha')"
echo " Commit: $commit"
foot=$(_template .templates/Dockerfile-foot$release.template)
for variant in "${variants[@]}"; do
echo Generating $variant variant...
rm -rf $release/$variant
mkdir -p $release/$variant
phpVersion=${php_version[$release]-${php_version[default]}}
template=".templates/Dockerfile-${base[$variant]}.template"
sed -e '
s@%%HEAD%%@'"$head"'@;
s@%%FOOT%%@'"$foot"'@;
s@%%EXTRA_INSTALL%%@'"$extra"'@;
s@%%INSTALL%%@'"$install"'@;
s/%%VARIANT%%/'"$variant"'/;
s/%%PHP_VERSION%%/'"$phpVersion"'/;
s#%%LABEL%%#'"$label"'#;
s/%%VERSION%%/'"$version"'/g;
s/%%COMMIT%%/'"$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 > "$release/$variant/Dockerfile"
cp .templates/scripts/$release/* $release/$variant/
done
done