|
| 1 | +FROM alpine:3.13 |
| 2 | + |
| 3 | +RUN apk add --no-cache \ |
| 4 | + gmp-dev |
| 5 | + |
| 6 | +# skip installing gem documentation |
| 7 | +RUN set -eux; \ |
| 8 | + mkdir -p /usr/local/etc; \ |
| 9 | + { \ |
| 10 | + echo 'install: --no-document'; \ |
| 11 | + echo 'update: --no-document'; \ |
| 12 | + } >> /usr/local/etc/gemrc |
| 13 | + |
| 14 | +ENV LANG C.UTF-8 |
| 15 | +ENV RUBY_MAJOR 3.0 |
| 16 | +ENV RUBY_VERSION 3.0.0 |
| 17 | +ENV RUBY_DOWNLOAD_SHA256 68bfaeef027b6ccd0032504a68ae69721a70e97d921ff328c0c8836c798f6cb1 |
| 18 | + |
| 19 | +# some of ruby's build scripts are written in ruby |
| 20 | +# we purge system ruby later to make sure our final image uses what we just built |
| 21 | +# readline-dev vs libedit-dev: https://bugs.ruby-lang.org/issues/11869 and https://github.com/docker-library/ruby/issues/75 |
| 22 | +RUN set -eux; \ |
| 23 | + \ |
| 24 | + apk add --no-cache --virtual .ruby-builddeps \ |
| 25 | + autoconf \ |
| 26 | + bison \ |
| 27 | + bzip2 \ |
| 28 | + bzip2-dev \ |
| 29 | + ca-certificates \ |
| 30 | + coreutils \ |
| 31 | + dpkg-dev dpkg \ |
| 32 | + gcc \ |
| 33 | + gdbm-dev \ |
| 34 | + glib-dev \ |
| 35 | + libc-dev \ |
| 36 | + libffi-dev \ |
| 37 | + libxml2-dev \ |
| 38 | + libxslt-dev \ |
| 39 | + linux-headers \ |
| 40 | + make \ |
| 41 | + ncurses-dev \ |
| 42 | + openssl \ |
| 43 | + openssl-dev \ |
| 44 | + patch \ |
| 45 | + procps \ |
| 46 | + readline-dev \ |
| 47 | + ruby \ |
| 48 | + tar \ |
| 49 | + xz \ |
| 50 | + yaml-dev \ |
| 51 | + zlib-dev \ |
| 52 | + ; \ |
| 53 | + \ |
| 54 | + wget -O ruby.tar.xz "https://cache.ruby-lang.org/pub/ruby/${RUBY_MAJOR%-rc}/ruby-$RUBY_VERSION.tar.xz"; \ |
| 55 | + echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \ |
| 56 | + \ |
| 57 | + mkdir -p /usr/src/ruby; \ |
| 58 | + tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \ |
| 59 | + rm ruby.tar.xz; \ |
| 60 | + \ |
| 61 | + cd /usr/src/ruby; \ |
| 62 | + \ |
| 63 | +# https://github.com/docker-library/ruby/issues/196 |
| 64 | +# https://bugs.ruby-lang.org/issues/14387#note-13 (patch source) |
| 65 | +# https://bugs.ruby-lang.org/issues/14387#note-16 ("Therefore ncopa's patch looks good for me in general." -- only breaks glibc which doesn't matter here) |
| 66 | + wget -O 'thread-stack-fix.patch' 'https://bugs.ruby-lang.org/attachments/download/7081/0001-thread_pthread.c-make-get_main_stack-portable-on-lin.patch'; \ |
| 67 | + echo '3ab628a51d92fdf0d2b5835e93564857aea73e0c1de00313864a94a6255cb645 *thread-stack-fix.patch' | sha256sum --check --strict; \ |
| 68 | + patch -p1 -i thread-stack-fix.patch; \ |
| 69 | + rm thread-stack-fix.patch; \ |
| 70 | + \ |
| 71 | +# hack in "ENABLE_PATH_CHECK" disabling to suppress: |
| 72 | +# warning: Insecure world writable dir |
| 73 | + { \ |
| 74 | + echo '#define ENABLE_PATH_CHECK 0'; \ |
| 75 | + echo; \ |
| 76 | + cat file.c; \ |
| 77 | + } > file.c.new; \ |
| 78 | + mv file.c.new file.c; \ |
| 79 | + \ |
| 80 | + autoconf; \ |
| 81 | + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ |
| 82 | +# the configure script does not detect isnan/isinf as macros |
| 83 | + export ac_cv_func_isnan=yes ac_cv_func_isinf=yes; \ |
| 84 | + ./configure \ |
| 85 | + --build="$gnuArch" \ |
| 86 | + --disable-install-doc \ |
| 87 | + --enable-shared \ |
| 88 | + ; \ |
| 89 | + make -j "$(nproc)"; \ |
| 90 | + make install; \ |
| 91 | + \ |
| 92 | + runDeps="$( \ |
| 93 | + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \ |
| 94 | + | tr ',' '\n' \ |
| 95 | + | sort -u \ |
| 96 | + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ |
| 97 | + )"; \ |
| 98 | + apk add --no-network --virtual .ruby-rundeps \ |
| 99 | + $runDeps \ |
| 100 | + bzip2 \ |
| 101 | + ca-certificates \ |
| 102 | + libffi-dev \ |
| 103 | + procps \ |
| 104 | + yaml-dev \ |
| 105 | + zlib-dev \ |
| 106 | + ; \ |
| 107 | + apk del --no-network .ruby-builddeps; \ |
| 108 | + \ |
| 109 | + cd /; \ |
| 110 | + rm -r /usr/src/ruby; \ |
| 111 | +# verify we have no "ruby" packages installed |
| 112 | + ! apk --no-network list --installed \ |
| 113 | + | grep -v '^[.]ruby-rundeps' \ |
| 114 | + | grep -i ruby \ |
| 115 | + ; \ |
| 116 | + [ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \ |
| 117 | +# rough smoke test |
| 118 | + ruby --version; \ |
| 119 | + gem --version; \ |
| 120 | + bundle --version |
| 121 | + |
| 122 | +# don't create ".bundle" in all our apps |
| 123 | +ENV GEM_HOME /usr/local/bundle |
| 124 | +ENV BUNDLE_SILENCE_ROOT_WARNING=1 \ |
| 125 | + BUNDLE_APP_CONFIG="$GEM_HOME" |
| 126 | +ENV PATH $GEM_HOME/bin:$PATH |
| 127 | +# adjust permissions of a few directories for running "gem install" as an arbitrary user |
| 128 | +RUN mkdir -p "$GEM_HOME" && chmod 777 "$GEM_HOME" |
| 129 | + |
| 130 | +CMD [ "irb" ] |
0 commit comments