-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.sh
executable file
·149 lines (119 loc) · 4.71 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
#!/bin/bash
set -eo pipefail
declare -A base=(
[alpine]='alpine'
)
declare -A version_suffixes=(
[3]='-stable'
[4]='-stable'
[5]='-stable'
[6]=''
)
declare -A dockerVariant=(
[buster]='debian'
[buster-slim]='debian-slim'
[alpine]='alpine'
)
variants=(
alpine
)
min_version='4.2'
dockerLatest='6.0'
dockerDefaultVariant='alpine'
# 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-taiga-front-base"
latests=( $( curl -fsSL 'https://api.github.com/repos/taigaio/taiga-front-dist/tags' |tac|tac| \
grep -oE '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | \
sort -urV )
4.2.14 )
# Remove existing images
echo "reset docker images"
rm -rf ./images/
mkdir ./images/
echo "update docker images"
readmeTags=
githubEnv=
travisEnv=
for latest in "${latests[@]}"; do
version=$(echo "$latest" | cut -d. -f1-2)
major=$(echo "$latest" | cut -d. -f1-1)
# Only add versions >= "$min_version"
if version_greater_or_equal "$version" "$min_version"; then
for variant in "${variants[@]}"; do
# Create the version+variant directory with a Dockerfile.
dir="images/$version/$variant"
if [ -d "$dir" ]; then
continue
fi
echo "generating $latest [$version] $variant"
mkdir -p "$dir"
template="Dockerfile.${base[$variant]}"
cp "template/$template" "$dir/Dockerfile"
# Copy the scripts
for name in entrypoint.sh .env docker-compose.test.yml .dockerignore; do
cp "template/$name" "$dir/$name"
chmod 755 "$dir/$name"
done
# Copy the configuration
cp -r "template/conf" "$dir"
cp -r "template/hooks" "$dir/"
cp -r "template/test" "$dir/"
# Replace the variables.
sed -ri -e '
s/%%VERSION_SUFFIX%%/'"${version_suffixes[$major]}"'/g;
s/%%VARIANT%%/'"$variant"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%MAJOR_VERSION%%/'"$version"'/g;
' "$dir/Dockerfile" "$dir/docker-compose.test.yml"
sed -ri -e '
s|DOCKER_TAG=.*|DOCKER_TAG='"$version"'|g;
s|DOCKER_REPO=.*|DOCKER_REPO='"$dockerRepo"'|g;
' "$dir/hooks/run"
# Create a list of "alias" tags for DockerHub post_push
tagVariant=${dockerVariant[$variant]}
if [ "$version" = "$dockerLatest" ]; then
if [ "$tagVariant" = "$dockerDefaultVariant" ]; then
export DOCKER_TAGS="$latest-$tagVariant $version-$tagVariant $tagVariant $latest $version latest "
else
export DOCKER_TAGS="$latest-$tagVariant $version-$tagVariant $tagVariant "
fi
elif [ "$version" = "$latest" ]; then
if [ "$tagVariant" = "$dockerDefaultVariant" ]; then
export DOCKER_TAGS="$latest-$tagVariant $latest "
else
export DOCKER_TAGS="$latest-$tagVariant "
fi
else
if [ "$tagVariant" = "$dockerDefaultVariant" ]; then
export DOCKER_TAGS="$latest-$tagVariant $version-$tagVariant $latest $version "
else
export DOCKER_TAGS="$latest-$tagVariant $version-$tagVariant "
fi
fi
echo "${DOCKER_TAGS} " > "$dir/.dockertags"
# Add README tags
readmeTags="$readmeTags\n- ${DOCKER_TAGS} (\`$dir/Dockerfile\`)"
# Add GitHub Actions env var
githubEnv="'$version', $githubEnv"
# Add Travis-CI env var
travisEnv='\n - VERSION='"$version"' VARIANT='"$variant$travisEnv"
if [[ $1 == 'build' ]]; then
tag="$version-$variant"
echo "Build Dockerfile for ${tag}"
docker build -t "${dockerRepo}:${tag}" "${dir}"
fi
done
fi
done
# update README.md
sed '/^<!-- >Docker Tags -->/,/^<!-- <Docker Tags -->/{/^<!-- >Docker Tags -->/!{/^<!-- <Docker Tags -->/!d}}' README.md > README.md.tmp
sed -e "s|<!-- >Docker Tags -->|<!-- >Docker Tags -->\n$readmeTags\n|g" README.md.tmp > README.md
rm README.md.tmp
# update .github workflows
sed -i -e "s|version: \[.*\]|version: [${githubEnv}]|g" .github/workflows/hooks.yml
# 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