Created
October 26, 2017 07:36
-
-
Save omerlh/cfe6394754788b2b0b9f836c6c238be7 to your computer and use it in GitHub Desktop.
Use this script in Dockerfile to install specific ruby version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Source: oficial ruby docker image | |
set -ex | |
mkdir -p /usr/local/etc \ | |
&& { \ | |
echo 'install: --no-document'; \ | |
echo 'update: --no-document'; \ | |
} >> /usr/local/etc/gemrc | |
buildDeps=' \ | |
bison \ | |
dpkg-dev \ | |
libgdbm-dev \ | |
ruby \ | |
' \ | |
apt-get update | |
apt-get install -y --no-install-recommends $buildDeps | |
rm -rf /var/lib/apt/lists/* | |
wget -O ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz" | |
echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum -c - | |
mkdir -p /usr/src/ruby | |
tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1 | |
rm ruby.tar.xz | |
cd /usr/src/ruby | |
# hack in "ENABLE_PATH_CHECK" disabling to suppress: | |
# warning: Insecure world writable dir | |
{ \ | |
echo '#define ENABLE_PATH_CHECK 0'; \ | |
echo; \ | |
cat file.c; \ | |
} > file.c.new | |
mv file.c.new file.c | |
autoconf | |
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" | |
./configure \ | |
--build="$gnuArch" \ | |
--disable-install-doc \ | |
--enable-shared | |
make -j "$(nproc)" | |
make install | |
apt-get purge -y --auto-remove $buildDeps | |
cd / | |
rm -r /usr/src/ruby | |
gem update --system "$RUBYGEMS_VERSION" | |
gem install bundler --version "$BUNDLER_VERSION" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use the script you need to set the following environment variables:
Checkout the official ruby image, or this repo for a sample usage.