|
| 1 | +FROM debian:buster-slim |
| 2 | + |
| 3 | +RUN set -eux; \ |
| 4 | + apt-get update; \ |
| 5 | + apt-get install -y --no-install-recommends \ |
| 6 | + bzip2 \ |
| 7 | + ca-certificates \ |
| 8 | + libffi-dev \ |
| 9 | + libgmp-dev \ |
| 10 | + libssl-dev \ |
| 11 | + libyaml-dev \ |
| 12 | + procps \ |
| 13 | + zlib1g-dev \ |
| 14 | + ; \ |
| 15 | + rm -rf /var/lib/apt/lists/* |
| 16 | + |
| 17 | +# skip installing gem documentation |
| 18 | +RUN set -eux; \ |
| 19 | + mkdir -p /usr/local/etc; \ |
| 20 | + { \ |
| 21 | + echo 'install: --no-document'; \ |
| 22 | + echo 'update: --no-document'; \ |
| 23 | + } >> /usr/local/etc/gemrc |
| 24 | + |
| 25 | +ENV RUBY_MAJOR 2.5 |
| 26 | +ENV RUBY_VERSION 2.5.5 |
| 27 | +ENV RUBY_DOWNLOAD_SHA256 9bf6370aaa82c284f193264cc7ca56f202171c32367deceb3599a4f354175d7d |
| 28 | +ENV RUBYGEMS_VERSION 3.0.3 |
| 29 | + |
| 30 | +# some of ruby's build scripts are written in ruby |
| 31 | +# we purge system ruby later to make sure our final image uses what we just built |
| 32 | +RUN set -eux; \ |
| 33 | + \ |
| 34 | + savedAptMark="$(apt-mark showmanual)"; \ |
| 35 | + apt-get update; \ |
| 36 | + apt-get install -y --no-install-recommends \ |
| 37 | + autoconf \ |
| 38 | + bison \ |
| 39 | + dpkg-dev \ |
| 40 | + gcc \ |
| 41 | + libbz2-dev \ |
| 42 | + libgdbm-compat-dev \ |
| 43 | + libgdbm-dev \ |
| 44 | + libglib2.0-dev \ |
| 45 | + libncurses-dev \ |
| 46 | + libreadline-dev \ |
| 47 | + libxml2-dev \ |
| 48 | + libxslt-dev \ |
| 49 | + make \ |
| 50 | + ruby \ |
| 51 | + wget \ |
| 52 | + xz-utils \ |
| 53 | + ; \ |
| 54 | + rm -rf /var/lib/apt/lists/*; \ |
| 55 | + \ |
| 56 | + wget -O ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz"; \ |
| 57 | + echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \ |
| 58 | + \ |
| 59 | + mkdir -p /usr/src/ruby; \ |
| 60 | + tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \ |
| 61 | + rm ruby.tar.xz; \ |
| 62 | + \ |
| 63 | + cd /usr/src/ruby; \ |
| 64 | + \ |
| 65 | +# hack in "ENABLE_PATH_CHECK" disabling to suppress: |
| 66 | +# warning: Insecure world writable dir |
| 67 | + { \ |
| 68 | + echo '#define ENABLE_PATH_CHECK 0'; \ |
| 69 | + echo; \ |
| 70 | + cat file.c; \ |
| 71 | + } > file.c.new; \ |
| 72 | + mv file.c.new file.c; \ |
| 73 | + \ |
| 74 | + autoconf; \ |
| 75 | + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 76 | + ./configure \ |
| 77 | + --build="$gnuArch" \ |
| 78 | + --disable-install-doc \ |
| 79 | + --enable-shared \ |
| 80 | + ; \ |
| 81 | + make -j "$(nproc)"; \ |
| 82 | + make install; \ |
| 83 | + \ |
| 84 | + apt-mark auto '.*' > /dev/null; \ |
| 85 | + apt-mark manual $savedAptMark > /dev/null; \ |
| 86 | + find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \ |
| 87 | + | awk '/=>/ { print $(NF-1) }' \ |
| 88 | + | sort -u \ |
| 89 | + | xargs -r dpkg-query --search \ |
| 90 | + | cut -d: -f1 \ |
| 91 | + | sort -u \ |
| 92 | + | xargs -r apt-mark manual \ |
| 93 | + ; \ |
| 94 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 95 | + \ |
| 96 | + cd /; \ |
| 97 | + rm -r /usr/src/ruby; \ |
| 98 | +# make sure bundled "rubygems" is older than RUBYGEMS_VERSION (https://github.com/docker-library/ruby/issues/246) |
| 99 | + ruby -e 'exit(Gem::Version.create(ENV["RUBYGEMS_VERSION"]) > Gem::Version.create(Gem::VERSION))'; \ |
| 100 | + gem update --system "$RUBYGEMS_VERSION" && rm -r /root/.gem/; \ |
| 101 | +# verify we have no "ruby" packages installed |
| 102 | + ! dpkg -l | grep -i ruby; \ |
| 103 | + [ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \ |
| 104 | +# rough smoke test |
| 105 | + ruby --version; \ |
| 106 | + gem --version; \ |
| 107 | + bundle --version |
| 108 | + |
| 109 | +# install things globally, for great justice |
| 110 | +# and don't create ".bundle" in all our apps |
| 111 | +ENV GEM_HOME /usr/local/bundle |
| 112 | +ENV BUNDLE_PATH__SYSTEM=true \ |
| 113 | + BUNDLE_SILENCE_ROOT_WARNING=1 \ |
| 114 | + BUNDLE_APP_CONFIG="$GEM_HOME" |
| 115 | +# path recommendation: https://github.com/bundler/bundler/pull/6469#issuecomment-383235438 |
| 116 | +ENV PATH $GEM_HOME/bin:$BUNDLE_PATH/gems/bin:$PATH |
| 117 | +# adjust permissions of a few directories for running "gem install" as an arbitrary user |
| 118 | +RUN mkdir -p "$GEM_HOME" && chmod 777 "$GEM_HOME" |
| 119 | +# (BUNDLE_PATH = GEM_HOME, no need to mkdir/chown both) |
| 120 | + |
| 121 | +CMD [ "irb" ] |
0 commit comments