2017-07-31 19:48:09 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
2014-08-14 14:58:13 -04:00
|
|
|
|
|
|
|
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
|
|
|
|
|
|
|
|
versions=( "$@" )
|
|
|
|
if [ ${#versions[@]} -eq 0 ]; then
|
|
|
|
versions=( */ )
|
|
|
|
fi
|
|
|
|
versions=( "${versions[@]%/}" )
|
2016-12-30 19:55:35 -05:00
|
|
|
releasePage="$(curl -fsSL 'https://www.ruby-lang.org/en/downloads/releases/')"
|
2014-08-14 14:58:13 -04:00
|
|
|
|
2015-08-04 12:42:09 -04:00
|
|
|
latest_gem_version() {
|
2016-12-30 19:55:35 -05:00
|
|
|
curl -fsSL "https://rubygems.org/api/v1/gems/$1.json" | sed -r 's/^.*"version":"([^"]+)".*$/\1/'
|
2015-08-04 12:42:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rubygems="$(latest_gem_version rubygems-update)"
|
|
|
|
bundler="$(latest_gem_version bundler)"
|
2015-06-12 14:06:36 -04:00
|
|
|
|
2016-01-29 13:39:48 -05:00
|
|
|
travisEnv=
|
2014-08-14 14:58:13 -04:00
|
|
|
for version in "${versions[@]}"; do
|
2016-12-05 13:31:07 -05:00
|
|
|
rcGrepV='-v'
|
|
|
|
rcVersion="${version%-rc}"
|
|
|
|
if [ "$rcVersion" != "$version" ]; then
|
|
|
|
rcGrepV=
|
|
|
|
fi
|
2017-07-31 19:48:09 -04:00
|
|
|
|
2016-03-31 20:13:29 -04:00
|
|
|
IFS=$'\n'; allVersions=(
|
2016-12-30 19:55:35 -05:00
|
|
|
$(curl -fsSL --compressed "https://cache.ruby-lang.org/pub/ruby/$rcVersion/" \
|
|
|
|
| grep -E '<a href="ruby-'"$rcVersion"'.[^"]+\.tar\.xz' \
|
2016-12-05 13:31:07 -05:00
|
|
|
| grep $rcGrepV -E 'preview|rc' \
|
2016-12-30 19:55:35 -05:00
|
|
|
| sed -r 's!.*<a href="ruby-([^"]+)\.tar\.xz.*!\1!' \
|
2016-03-31 20:13:29 -04:00
|
|
|
| sort -rV)
|
|
|
|
); unset IFS
|
|
|
|
|
|
|
|
fullVersion=
|
|
|
|
for tryVersion in "${allVersions[@]}"; do
|
2016-12-23 08:14:28 -05:00
|
|
|
if echo "$releasePage" | grep -q "Ruby ${tryVersion}<"; then
|
2016-03-31 20:13:29 -04:00
|
|
|
fullVersion="$tryVersion"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$fullVersion" ]; then
|
|
|
|
echo >&2 "warning: cannot determine sha for $version (tried all of ${allVersions[*]}); skipping"
|
|
|
|
continue
|
|
|
|
fi
|
2016-12-30 19:55:35 -05:00
|
|
|
versionReleasePage="$(echo "$releasePage" | grep "<td>Ruby $fullVersion</td>" -A 2 | awk -F '"' '$1 == "<td><a href=" { print $2; exit }')"
|
|
|
|
shaVal="$(curl -fsSL "https://www.ruby-lang.org/$versionReleasePage" |tac|tac| grep "ruby-$fullVersion.tar.xz" -A 5 | awk '/^SHA256:/ { print $2; exit }')"
|
2016-02-03 15:11:16 -05:00
|
|
|
|
2016-12-30 19:55:35 -05:00
|
|
|
echo "$version: $fullVersion; rubygems $rubygems, bundler $bundler; $shaVal"
|
2017-07-31 19:48:09 -04:00
|
|
|
|
|
|
|
for v in \
|
|
|
|
alpine{3.4,3.6} \
|
|
|
|
{jessie,stretch}{/slim,/onbuild,} \
|
|
|
|
; do
|
|
|
|
dir="$version/$v"
|
|
|
|
variant="$(basename "$v")"
|
|
|
|
|
|
|
|
[ -d "$dir" ] || continue
|
|
|
|
|
|
|
|
case "$variant" in
|
|
|
|
slim|onbuild|windowsservercore) template="$variant"; tag="$(basename "$(dirname "$dir")")" ;;
|
|
|
|
alpine*) template='alpine'; tag="${variant#alpine}" ;;
|
|
|
|
*) template='debian'; tag="$variant" ;;
|
|
|
|
esac
|
|
|
|
template="Dockerfile-${template}.template"
|
|
|
|
|
|
|
|
sed -r \
|
|
|
|
-e 's!%%VERSION%%!'"$version"'!g' \
|
|
|
|
-e 's!%%FULL_VERSION%%!'"$fullVersion"'!g' \
|
|
|
|
-e 's!%%SHA256%%!'"$shaVal"'!g' \
|
|
|
|
-e 's!%%RUBYGEMS%%!'"$rubygems"'!g' \
|
|
|
|
-e 's!%%BUNDLER%%!'"$bundler"'!g' \
|
|
|
|
-e 's/^(FROM (debian|buildpack-deps|alpine)):.*/\1:'"$tag"'/' \
|
|
|
|
"$template" > "$dir/Dockerfile"
|
|
|
|
|
|
|
|
case "$v" in
|
|
|
|
*/onbuild) ;;
|
|
|
|
*)
|
|
|
|
travisEnv='\n - VERSION='"$version VARIANT=$v$travisEnv"
|
|
|
|
;;
|
|
|
|
esac
|
2016-01-29 13:39:48 -05:00
|
|
|
done
|
2014-08-14 14:58:13 -04:00
|
|
|
done
|
2016-01-29 13:39:48 -05:00
|
|
|
|
|
|
|
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
|
|
|
|
echo "$travis" > .travis.yml
|