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 [@]%/ } " )
2017-09-15 10:58:44 -04:00
releasesPage = " $( curl -fsSL 'https://www.ruby-lang.org/en/downloads/releases/' ) "
2017-09-15 13:53:33 -04:00
newsPage = " $( curl -fsSL 'https://www.ruby-lang.org/en/news/' ) " # occasionally, releases don't show up on the Releases page (see https://github.com/ruby/www.ruby-lang.org/blob/master/_data/releases.yml)
# TODO consider parsing https://github.com/ruby/www.ruby-lang.org/blob/master/_data/downloads.yml as well
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
}
2018-12-31 19:59:56 -05:00
# https://github.com/docker-library/ruby/issues/246
2019-03-05 21:09:36 -05:00
rubygems = '3.0.3'
2018-12-31 19:59:56 -05:00
declare -A newEnoughRubygems = (
2019-05-30 16:23:26 -04:00
[ 2.6] = 1 # 2.6.3 => gems 3.0.3 (https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems.rb#L12)
[ 2.7] = 1 # 2.7.0-preview1 => gems 3.1.0.pre1 (https://github.com/ruby/ruby/blob/v2_7_0_preview1/lib/rubygems.rb#L12)
2018-12-31 19:59:56 -05:00
)
# TODO once all versions are in this family of "new enough", remove RUBYGEMS_VERSION code entirely
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
2018-07-09 19:38:17 -04:00
IFS = $'\n' ; allVersions = ( $(
curl -fsSL --compressed " https://cache.ruby-lang.org/pub/ruby/ $rcVersion / " \
| grep -oE '["/]ruby-' " $rcVersion " '.[^"]+\.tar\.xz' \
| sed -r 's!^["/]ruby-([^"]+)[.]tar[.]xz!\1!' \
2016-12-05 13:31:07 -05:00
| grep $rcGrepV -E 'preview|rc' \
2018-07-09 19:38:17 -04:00
| sort -ruV
) ) ; unset IFS
2016-03-31 20:13:29 -04:00
fullVersion =
2017-09-15 10:58:44 -04:00
shaVal =
2016-03-31 20:13:29 -04:00
for tryVersion in " ${ allVersions [@] } " ; do
2017-09-15 10:58:44 -04:00
if \
{
2019-04-02 17:51:34 -04:00
versionReleasePage = " $( grep " <td>Ruby $tryVersion </td> " -A 2 <<< " $releasesPage " | awk -F '"' '$1 == "<td><a href=" { print $2; exit }' ) " \
2017-12-14 22:56:14 -05:00
&& [ " $versionReleasePage " ] \
2019-04-02 17:51:34 -04:00
&& shaVal = " $( curl -fsSL " https://www.ruby-lang.org/ $versionReleasePage " | tac| tac| grep " ruby- $tryVersion .tar.xz " -A 5 | awk '$1 == "SHA256:" { print $2; exit }' ) " \
2017-12-14 22:56:14 -05:00
&& [ " $shaVal " ]
2017-09-15 10:58:44 -04:00
} \
|| {
versionReleasePage = " $( echo " $newsPage " | grep -oE '<a href="[^"]+">Ruby ' " $tryVersion " ' Released</a>' | cut -d'"' -f2) " \
2017-12-14 22:56:14 -05:00
&& [ " $versionReleasePage " ] \
2019-04-02 17:51:34 -04:00
&& shaVal = " $( curl -fsSL " https://www.ruby-lang.org/ $versionReleasePage " | tac| tac| grep " ruby- $tryVersion .tar.xz " -A 5 | awk '$1 == "SHA256:" { print $2; exit }' ) " \
2017-12-14 22:56:14 -05:00
&& [ " $shaVal " ]
2017-09-15 10:58:44 -04:00
} \
; then
2017-12-14 22:56:14 -05:00
fullVersion = " $tryVersion "
break
2016-03-31 20:13:29 -04:00
fi
done
if [ -z " $fullVersion " ] ; then
echo >& 2 " warning: cannot determine sha for $version (tried all of ${ allVersions [*] } ); skipping "
continue
fi
2016-02-03 15:11:16 -05:00
2018-12-31 19:59:56 -05:00
echo " $version : $fullVersion ; $shaVal "
2017-07-31 19:48:09 -04:00
for v in \
2019-06-20 09:15:30 -04:00
alpine{ 3.9,3.10} \
2019-06-24 18:09:34 -04:00
{ jessie,stretch,buster} { /slim,} \
2017-07-31 19:48:09 -04:00
; do
dir = " $version / $v "
variant = " $( basename " $v " ) "
[ -d " $dir " ] || continue
case " $variant " in
2018-07-20 16:32:43 -04:00
slim| windowsservercore) template = " $variant " ; tag = " $( basename " $( dirname " $dir " ) " ) " ; ;
2017-07-31 19:48:09 -04:00
alpine*) template = 'alpine' ; tag = " ${ variant #alpine } " ; ;
*) template = 'debian' ; tag = " $variant " ; ;
esac
template = " Dockerfile- ${ template } .template "
2019-01-04 18:53:12 -05:00
if [ " $variant " = 'slim' ] ; then
tag += '-slim'
fi
2017-07-31 19:48:09 -04:00
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/^(FROM (debian|buildpack-deps|alpine)):.*/\1:' " $tag " '/' \
" $template " > " $dir /Dockerfile "
2019-06-25 15:40:06 -04:00
case " $v " in
# https://packages.debian.org/sid/libgdbm-compat-dev (needed for "dbm" core module, but only in Buster+)
jessie/slim | stretch/slim)
sed -i -e '/libgdbm-compat-dev/d' " $dir /Dockerfile "
; ;
esac
2019-05-30 16:23:26 -04:00
if [ -n " ${ newEnoughRubygems [ $rcVersion ] :- } " ] ; then
2018-12-31 19:59:56 -05:00
sed -ri -e '/RUBYGEMS_VERSION/d' " $dir /Dockerfile "
fi
2018-07-20 16:32:43 -04:00
travisEnv = '\n - VERSION=' " $version VARIANT= $v $travisEnv "
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