|
| 1 | +FROM ubuntu:20.04 |
| 2 | +ENV DEBIAN_FRONTEND noninteractive |
| 3 | +RUN apt-get -y update && \ |
| 4 | + apt-get install -y curl git-core xz-utils build-essential zlib1g-dev libreadline-dev libssl-dev wget unzip sudo gnupg2 dirmngr cmake pkg-config autoconf && \ |
| 5 | + rm -rf /var/lib/apt/lists/* |
| 6 | + |
| 7 | +# Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000 |
| 8 | +RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm |
| 9 | + |
| 10 | +# Make sure rvm and later settings are available in interactive and non-interactive shells |
| 11 | +RUN echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc && \ |
| 12 | + echo "source /etc/rubybashrc" >> /etc/bashrc && \ |
| 13 | + echo "source /etc/rubybashrc" >> /etc/bash.bashrc |
| 14 | +ENV BASH_ENV /etc/rubybashrc |
| 15 | + |
| 16 | +USER rvm |
| 17 | + |
| 18 | +RUN mkdir ~/.gnupg && \ |
| 19 | + chmod 700 ~/.gnupg && \ |
| 20 | + echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf |
| 21 | + |
| 22 | +# install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts |
| 23 | +RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \ |
| 24 | + (curl -L http://get.rvm.io | sudo bash) && \ |
| 25 | + bash -c " \ |
| 26 | + source /etc/rubybashrc && \ |
| 27 | + rvm autolibs disable && \ |
| 28 | + rvmsudo rvm cleanup all " |
| 29 | + |
| 30 | +# Import patch files for ruby and gems |
| 31 | +COPY build/patches /home/rvm/patches/ |
| 32 | + |
| 33 | +# install rubies and fix permissions on |
| 34 | +ENV RVM_RUBIES 2.5.9 3.1.0 |
| 35 | +RUN bash -c " \ |
| 36 | + export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \ |
| 37 | + for v in ${RVM_RUBIES} ; do \ |
| 38 | + rvm install \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \ |
| 39 | + done && \ |
| 40 | + rvm cleanup all && \ |
| 41 | + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " |
| 42 | + |
| 43 | +# Install rake-compiler and typical gems in all Rubies |
| 44 | +# do not generate documentation for gems |
| 45 | +# TODO: stop pinning rubygems to 3.3.20 once https://github.com/rake-compiler/rake-compiler/pull/209 is merged |
| 46 | +RUN echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \ |
| 47 | + bash -c " \ |
| 48 | + rvm all do gem update --system=3.3.20 --no-document && \ |
| 49 | + rvm all do gem install --no-document bundler 'bundler:~>1.16' 'rake-compiler:1.1.6' hoe mini_portile rubygems-tasks mini_portile2 && \ |
| 50 | + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " |
| 51 | + |
| 52 | +# Install rake-compiler's cross rubies in global dir instead of /root |
| 53 | +RUN sudo mkdir -p /usr/local/rake-compiler && \ |
| 54 | + sudo chown rvm.rvm /usr/local/rake-compiler && \ |
| 55 | + ln -s /usr/local/rake-compiler ~/.rake-compiler |
| 56 | + |
| 57 | +# Add cross compilers for Windows and Linux |
| 58 | +USER root |
| 59 | + |
| 60 | +COPY --from=larskanis/mingw64-ucrt:20.04 \ |
| 61 | + /build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_amd64.deb \ |
| 62 | + /build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \ |
| 63 | + /build/gcc-mingw-w64-base_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \ |
| 64 | + /build/gcc-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \ |
| 65 | + /build/mingw-w64-common_7.0.0-2_all.deb \ |
| 66 | + /build/mingw-w64-x86-64-dev_7.0.0-2_all.deb \ |
| 67 | + /debs/ |
| 68 | +RUN dpkg -i /debs/*.deb |
| 69 | + |
| 70 | + |
| 71 | +RUN bash -c " \ |
| 72 | + rvm alias create default 3.1.0 && \ |
| 73 | + rvm use default " |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +# Patch rake-compiler to build and install static libraries for Linux rubies |
| 78 | +USER rvm |
| 79 | +COPY build/patches2 /home/rvm/patches/ |
| 80 | +RUN bash -c " \ |
| 81 | + for v in ${RVM_RUBIES} ; do \ |
| 82 | + cd /usr/local/rvm/gems/ruby-\$v/gems/rake-compiler-1.1.6 && \ |
| 83 | + echo applying patches to ruby-\$v /home/rvm/patches/rake-compiler-1.1.6/*.patch && \ |
| 84 | + ( git apply /home/rvm/patches/rake-compiler-1.1.6/*.patch || true ) \ |
| 85 | + done " |
| 86 | + |
| 87 | +# Patch rubies for cross build |
| 88 | +#USER root |
| 89 | +#RUN bash -c " \ |
| 90 | +# for v in 2.7.0 3.0.0 3.1.0 ; do \ |
| 91 | +# curl -SL http://cache.ruby-lang.org/pub/ruby/\${v:0:3}/ruby-\$v.tar.xz | tar -xJC /root/ && \ |
| 92 | +# cd /root/ruby-\$v && \ |
| 93 | +# git apply /home/rvm/patches/ruby-\$v/*.patch && \ |
| 94 | +# cd .. && \ |
| 95 | +# mkdir -p /usr/local/rake-compiler/sources/ && \ |
| 96 | +# tar cjf /usr/local/rake-compiler/sources/ruby-\$v.tar.bz2 ruby-\$v && \ |
| 97 | +# chown rvm /usr/local/rake-compiler -R && \ |
| 98 | +# rm -rf /root/ruby-\$v ; \ |
| 99 | +# done " |
| 100 | +#USER rvm |
| 101 | + |
| 102 | +ENV XRUBIES 3.2.0-rc1 |
| 103 | +# Build xruby versions in parallel |
| 104 | +# Then cleanup all build artifacts |
| 105 | +RUN bash -c " \ |
| 106 | + rvm use 3.1.0 && \ |
| 107 | + export CPPFLAGS='-D__USE_MINGW_ANSI_STDIO=1' && \ |
| 108 | + export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong -s' && \ |
| 109 | + export LDFLAGS='-pipe -s' && \ |
| 110 | + export LIBS='-l:libssp.a' && \ |
| 111 | + \ |
| 112 | + export MAKE='make V=1 -j`nproc`' && \ |
| 113 | + rake-compiler cross-ruby VERSION=$XRUBIES HOST=x86_64-w64-mingw32 && \ |
| 114 | + rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \ |
| 115 | + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " |
| 116 | +ENV XRUBIES 3.1.0 |
| 117 | +# Build xruby versions in parallel |
| 118 | +# Then cleanup all build artifacts |
| 119 | +RUN bash -c " \ |
| 120 | + rvm use 3.1.0 && \ |
| 121 | + export CPPFLAGS='-D__USE_MINGW_ANSI_STDIO=1' && \ |
| 122 | + export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong -s' && \ |
| 123 | + export LDFLAGS='-pipe -s' && \ |
| 124 | + export LIBS='-l:libssp.a' && \ |
| 125 | + \ |
| 126 | + export MAKE='make V=1 -j`nproc`' && \ |
| 127 | + rake-compiler cross-ruby VERSION=$XRUBIES HOST=x86_64-w64-mingw32 && \ |
| 128 | + rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \ |
| 129 | + find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw " |
| 130 | + |
| 131 | + |
| 132 | +# RubyInstaller doesn't install libgcc -> link it static. |
| 133 | +RUN find /usr/local/rake-compiler/ruby/*mingw*/ -name rbconfig.rb | while read f ; do sed -i 's/."LDFLAGS". = "/&-static-libgcc /' $f ; done |
| 134 | +# Raise Windows-API to Vista (affects ruby < 2.6 only) |
| 135 | +RUN find /usr/local/rake-compiler/ruby -name rbconfig.rb | while read f ; do sed -i 's/0x0501/0x0600/' $f ; done |
| 136 | +# Don't link to static libruby |
| 137 | +RUN find /usr/local/rake-compiler/ruby -name lib*-ruby*.dll.a | while read f ; do n=`echo $f | sed s/.dll//` ; mv $f $n ; done |
| 138 | + |
| 139 | +USER root |
| 140 | + |
| 141 | +# Fix paths in rake-compiler/config.yml |
| 142 | +RUN sed -i -- "s:/root/.rake-compiler:/usr/local/rake-compiler:g" /usr/local/rake-compiler/config.yml |
| 143 | + |
| 144 | + |
| 145 | +# Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker. |
| 146 | +COPY build/strip_wrapper /root/ |
| 147 | +RUN mv /usr/bin/x86_64-w64-mingw32-strip /usr/bin/x86_64-w64-mingw32-strip.bin && \ |
| 148 | + ln /root/strip_wrapper /usr/bin/x86_64-w64-mingw32-strip |
| 149 | + |
| 150 | +# Use posix pthread for mingw so that C++ standard library for thread could be |
| 151 | +# available such as std::thread, std::mutex, so on. |
| 152 | +# https://sourceware.org/pthreads-win32/ |
| 153 | +RUN printf "1\n" | update-alternatives --config x86_64-w64-mingw32-gcc && \ |
| 154 | + printf "1\n" | update-alternatives --config x86_64-w64-mingw32-g++ |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +# Install SIGINT forwarder |
| 159 | +COPY build/sigfw.c /root/ |
| 160 | +RUN gcc $HOME/sigfw.c -o /usr/bin/sigfw |
| 161 | + |
| 162 | +# Install user mapper |
| 163 | +COPY build/runas /usr/bin/ |
| 164 | +COPY build/rcd-env.sh /etc/profile.d/ |
| 165 | +RUN echo "source /etc/profile.d/rcd-env.sh" >> /etc/rubybashrc |
| 166 | + |
| 167 | +# Install sudoers configuration |
| 168 | +COPY build/sudoers /etc/sudoers.d/rake-compiler-dock |
| 169 | + |
| 170 | +ENV RUBY_CC_VERSION 3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0:2.4.0 |
| 171 | + |
| 172 | +CMD bash |
0 commit comments