*: rework update and generation scripts

This is necessary in order to have proper generation of variant and
version-based Dockerfiles from a single template.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai 2017-01-13 20:31:57 +11:00
parent ff52578e4f
commit c34d30fb49
No known key found for this signature in database
GPG Key ID: 4A7BE7BF70DE9B9F
2 changed files with 108 additions and 22 deletions

View File

@ -1,16 +1,81 @@
#!/bin/bash #!/bin/bash
set -e set -e
self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
url='git://github.com/nextcloud/docker' # Get the most recent commit which modified any of "$@".
fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
}
commit="$(git log -1 --format='format:%H' -- Dockerfile $(awk 'toupper($1) == "COPY" { for (i = 2; i < NF; i++) { print $i } }' Dockerfile))" # Get the most recent commit which modified "$1/Dockerfile" or any file that
fullVersion="$(grep -m1 'ENV NEXTCLOUD_VERSION ' ./Dockerfile | cut -d' ' -f3)" # the Dockerfile copies into the rootfs (with COPY).
dockerfileCommit() {
local dir="$1"; shift
(
cd "$dir";
fileCommit Dockerfile \
$(git show HEAD:./Dockerfile | awk '
toupper($1) == "COPY" {
for (i = 2; i < NF; i++)
print $i;
}
')
)
}
echo '# maintainer: docker@nextcloud.com' # Header.
echo cat <<-EOH
echo "$fullVersion: ${url}@${commit}" # This file is generated via https://github.com/nextcloud/docker/blob/$(fileCommit "$self")/$self
echo "${fullVersion%.*}: ${url}@${commit}"
echo "${fullVersion%.*.*}: ${url}@${commit}" Maintainers: Nextcloud <docker@nextcloud.com> (@nextcloud),
echo "latest: ${url}@${commit}" Pierre Ozoux <pierre@ozoux.net> (@pierreozoux)
GitRepo: https://github.com/nextcloud/docker.git
EOH
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
latest=$(curl -sSL 'https://nextcloud.com/changelog/' |tac|tac \
| grep -o "\(Version\|Release\)\s\+[[:digit:]]\+\(.[[:digit:]]\+\)\+" \
| awk '{ print $2 }' \
| sort -uV \
| tail -1)
# Generate each of the tags.
versions=( */ )
versions=( "${versions[@]%/}" )
for version in "${versions[@]}"; do
variants=( $version/*/ )
variants=( $(for variant in "${variants[@]%/}"; do
echo "$(basename "$variant")"
done) )
for variant in "${variants[@]}"; do
commit="$(dockerfileCommit "$version/$variant")"
fullversion="$(git show "$commit":"$version/$variant/Dockerfile" | awk '$1 == "ENV" && $2 == "NEXTCLOUD_VERSION" { print $3; exit }')"
versionAliases=( "$fullversion" "${fullversion%.*}" "${fullversion%.*.*}" )
if [ "$fullversion" = "$latest" ]; then
versionAliases+=( "latest" )
fi
variantAliases=( "${versionAliases[@]/%/-$variant}" )
variantAliases=( "${variantAliases[@]//latest-}" )
if [ "$variant" = "apache" ]; then
variantAliases+=( "${versionAliases[@]}" )
fi
cat <<-EOE
Tags: $(join ', ' "${variantAliases[@]}")
GitCommit: $commit
Directory: $version/$variant
EOE
done
done

View File

@ -1,17 +1,38 @@
#!/bin/bash #!/bin/bash
set -eo pipefail set -eo pipefail
current="$( declare -A cmd=(
git ls-remote --tags https://github.com/nextcloud/server.git \ [apache]='apache2-foreground'
| awk -F 'refs/tags/' ' [fpm]='php-fpm'
$2 ~ /^v?[0-9]/ { )
gsub(/^v|\^.*/, "", $2);
print $2;
}
' \
| sort -uV \
| tail -1
)"
set -x latests=( $(curl -sSL 'https://nextcloud.com/changelog/' |tac|tac| \
sed -ri 's/^(ENV NEXTCLOUD_VERSION) .*/\1 '"$current"'/;' ./Dockerfile grep -o "\(Version\|Release\)\s\+[[:digit:]]\+\(\.[[:digit:]]\+\)\+" | \
awk '{ print $2 }' | sort -V ) )
for latest in "${latests[@]}"; do
version=$(echo "$latest" | cut -d. -f1-2)
for variant in apache fpm; do
# Create the version+variant directory with a Dockerfile.
mkdir -p "$version/$variant"
cp Dockerfile.template "$version/$variant/Dockerfile"
echo "updating $latest [$version] $variant"
# Replace the variables.
sed -ri -e '
s/%%VARIANT%%/'"$variant"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/g;
' "$version/$variant/Dockerfile"
# Remove Apache commands if we're not an Apache variant.
if [ "$variant" != "apache" ]; then
sed -ri -e '/a2enmod/d' "$version/$variant/Dockerfile"
fi
# Copy the docker-entrypoint.
cp docker-entrypoint.sh "$version/$variant/docker-entrypoint.sh"
done
done