forked from monicahq/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·124 lines (105 loc) · 3.24 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
#!/bin/bash
set -e
version=$1
IFS='
'
_template() {
sed -e 's/\\/\\\\/g' $1 | sed -E ':a;N;$!ba;s/\r{0,1}\n/%0A/g'
}
declare -A php_version=(
[default]='8.1'
)
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 -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 "$version" ]; then
version="$(_githubapi 'https://api.github.com/repos/monicahq/monica/releases/latest' | jq -r '.tag_name' || _githubapi 'https://api.github.com/repos/monicahq/monica/releases' | jq -r '.[0].tag_name')"
fi
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"
head=$(_template .templates/Dockerfile-head.template)
foot=$(_template .templates/Dockerfile-foot.template)
extra=$(_template .templates/Dockerfile-extra.template)
install=$(_template .templates/Dockerfile-install.template)
for variant in apache fpm fpm-alpine; do
echo Generating $variant variant...
rm -rf $variant
mkdir -p $variant
phpVersion=${php_version[$version]-${php_version[default]}}
template="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 > "$variant/Dockerfile"
for file in entrypoint cron queue; do
cp docker-$file.sh $variant/$file.sh
done
done