generated from Monogramm/docker-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·84 lines (66 loc) · 2.47 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
#!/bin/bash
set -eo pipefail
declare -A base=(
[debian]='debian'
[alpine]='alpine'
)
variants=(
debian
alpine
)
min_version='1.8.0'
# version_greater_or_equal A B returns whether A >= B
function version_greater_or_equal() {
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" || "$1" == "$2" ]];
}
dockerRepo="monogramm/docker-etherpad"
# Retrieve automatically the latest versions
latests=( $( curl -fsSL 'https://api.github.com/repos/ether/etherpad-lite/tags' |tac|tac| \
grep -oE '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | \
sort -urV )
master
develop )
# Remove existing images
echo "reset docker images"
#find ./images -maxdepth 1 -type d -regextype sed -regex '\./images/[[:digit:]]\+\.[[:digit:]]\+' -exec rm -r '{}' \;
rm -rf ./images/*
echo "update docker images"
travisEnv=
for latest in "${latests[@]}"; do
# Only add versions >= "$min_version"
if version_greater_or_equal "$latest" "$min_version"; then
for variant in "${variants[@]}"; do
echo "Updating $latest [$latest-$variant]"
# Create the version directory with a Dockerfile.
dir="images/$latest/$variant"
mkdir -p "$dir"
template="Dockerfile.${base[$variant]}"
cp "template/$template" "$dir/Dockerfile"
cp "template/.dockerignore" "$dir/.dockerignore"
cp "template/settings.json" "$dir/settings.json"
cp -r "template/hooks" "$dir/"
cp -r "template/test" "$dir/"
cp "template/.env" "$dir/.env"
cp template/*.sh "$dir/"
cp "template/docker-compose_mysql.yml" "$dir/docker-compose_mysql.test.yml"
cp "template/docker-compose_postgresql.yml" "$dir/docker-compose_postgresql.test.yml"
cp "template/docker-compose_sqlite.yml" "$dir/docker-compose_sqlite.test.yml"
# Replace the variables.
sed -ri -e '
s/ETHERPAD_VERSION=.*/ETHERPAD_VERSION='"$latest"'/g;
' "$dir/Dockerfile"
# Add Travis-CI env var
travisEnv='\n - VERSION='"$latest"' VARIANT='"$variant"' DATABASE=mysql'"$travisEnv"
travisEnv='\n - VERSION='"$latest"' VARIANT='"$variant"' DATABASE=postgresql'"$travisEnv"
travisEnv='\n - VERSION='"$latest"' VARIANT='"$variant"' DATABASE=sqlite'"$travisEnv"
if [[ $1 == 'build' ]]; then
tag="$latest-$variant"
echo "Build Dockerfile for ${tag}"
docker build -t "${dockerRepo}:${tag}" "$dir"
fi
done
fi
done
# update .travis.yml
travis="$(awk -v 'RS=\n\n' '$1 == "env:" && $2 == "#" && $3 == "Environments" { $0 = "env: # Environments'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml