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