Skip to content

Commit 6018b4d

Browse files
committed
replace rvm with rbenv and ruby-build
- user `rvm` no longer exists, replaced by `rubyuser` - `rvm` has been replaced by `rbenv` and `ruby-build` - no longer applying the sendfile patches to Ruby - no longer updating gems belonging to the bootstrap rubies
1 parent ab92523 commit 6018b4d

File tree

9 files changed

+140
-186
lines changed

9 files changed

+140
-186
lines changed

Dockerfile.jruby

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,65 @@ FROM ubuntu:20.04
22

33
ENV DEBIAN_FRONTEND noninteractive
44
RUN apt-get -y update && \
5-
apt-get install -y curl git-core xz-utils wget unzip sudo gpg dirmngr openjdk-11-jdk-headless maven && \
5+
apt-get install -y sudo wget curl git-core build-essential xz-utils unzip dirmngr && \
6+
apt-get install -y openjdk-11-jdk-headless maven && \
67
rm -rf /var/lib/apt/lists/*
78

8-
# Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000
9-
RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm && \
10-
echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc
11-
USER rvm
9+
##
10+
## install rbenv and ruby-build
11+
##
12+
RUN groupadd -r rubyuser && useradd -r -g rubyuser -G sudo -p "" --create-home rubyuser
1213

13-
RUN mkdir ~/.gnupg && \
14-
echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
14+
ENV RBENV_ROOT=/usr/local/rbenv RBENV_RUBIES="jruby-9.4.0.0"
1515

16-
# install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts
17-
RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \
18-
(curl -L http://get.rvm.io | sudo bash) && \
19-
bash -c " \
20-
source /etc/rubybashrc && \
21-
rvmsudo rvm cleanup all "
16+
# chown after running `rbenv init` because that command creates some subdirectories
17+
RUN git clone https://github.com/rbenv/rbenv.git ${RBENV_ROOT} && \
18+
git clone https://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build && \
19+
\
20+
echo "export RBENV_ROOT=/usr/local/rbenv" >> /etc/rubybashrc && \
21+
echo "export PATH=$RBENV_ROOT/bin:\$PATH" >> /etc/rubybashrc && \
22+
$RBENV_ROOT/bin/rbenv init - --no-rehash bash >> /etc/rubybashrc && \
23+
echo "source /etc/rubybashrc" >> /etc/bashrc && \
24+
echo "source /etc/rubybashrc" >> /etc/bash.bashrc && \
25+
\
26+
chown -R rubyuser:rubyuser ${RBENV_ROOT} && \
27+
find ${RBENV_ROOT} -type d -print0 | sudo xargs -0 chmod g+sw
28+
ENV BASH_ENV=/etc/rubybashrc
2229

23-
# Import patch files for ruby and gems
24-
COPY build/patches /home/rvm/patches/
25-
ENV BASH_ENV /etc/rubybashrc
2630

27-
# install rubies and fix permissions on
31+
##
32+
## set up rake-compiler and install bootstrap rubies
33+
##
34+
USER rubyuser
35+
36+
# Install the bootstrap rubies
2837
RUN bash -c " \
38+
echo 'gem: --no-ri --no-rdoc --no-document' >> ~/.gemrc && \
2939
export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \
30-
for v in jruby-9.4.0.0 ; do \
31-
rvm install --binary \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \
40+
for v in ${RBENV_RUBIES} ; do \
41+
rbenv install \$v -- --disable-install-doc ; \
3242
done && \
33-
rvm cleanup all && \
34-
find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw \
43+
find ${RBENV_ROOT} -type d -print0 | sudo xargs -0 chmod g+w \
3544
"
3645

46+
# Install rake-compiler and patch it to build and install static libraries for Linux rubies
47+
COPY build/patches2 /home/rubyuser/patches
3748
RUN bash -c " \
38-
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
39-
rvm all do gem update --system --no-document && \
40-
rvm all do gem update --no-document && \
41-
rvm all do gem install bundler --no-document && \
42-
rvm all do gem install --no-document rake-compiler:1.2.5 && \
43-
find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw \
49+
for v in ${RBENV_RUBIES} ; do \
50+
rbenv shell \$v && \
51+
gem install rake-compiler -v1.2.5 && \
52+
cd ${RBENV_ROOT}/versions/\$v/lib/ruby/gems/*/gems/rake-compiler-1.2.5 && \
53+
patch -p1 < /home/rubyuser/patches/rake-compiler-1.2.5/*.patch ; \
54+
done \
4455
"
4556

4657
# Install rake-compiler's cross rubies in global dir instead of /root
4758
RUN sudo mkdir -p /usr/local/rake-compiler && \
48-
sudo chown rvm.rvm /usr/local/rake-compiler && \
59+
sudo chown rubyuser.rubyuser /usr/local/rake-compiler && \
4960
ln -s /usr/local/rake-compiler ~/.rake-compiler
5061

51-
USER root
52-
53-
RUN bash -c "rvm alias create default jruby-9.4.0.0"
54-
RUN echo "rvm use jruby-9.4.0.0 > /dev/null" >> /etc/rubybashrc
5562

56-
# Add rvm to the global bashrc
57-
RUN echo "source /etc/profile.d/rvm.sh" >> /etc/bash.bashrc
63+
USER root
5864

5965
# Install SIGINT forwarder
6066
COPY build/sigfw.c /root/
@@ -66,4 +72,6 @@ COPY build/runas /usr/local/bin/
6672
# Install sudoers configuration
6773
COPY build/sudoers /etc/sudoers.d/rake-compiler-dock
6874

75+
RUN bash -c "rbenv global jruby-9.4.0.0"
76+
6977
CMD bash

Dockerfile.mri.erb

Lines changed: 77 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,24 @@ manylinux = !!(image =~ /manylinux/)
99
FROM <%= image %>
1010

1111
##
12-
## RVM and native rubies
12+
## Install required base packages for compiling ruby
1313
##
14-
# Install packages which rvm will require
1514
<% if manylinux %>
1615
RUN yum install -y sudo ruby less git wget curl autoconf libtool cmake gcc-c++ xz readline-devel sqlite-devel openssl-devel libffi-devel libyaml-devel
1716

18-
# Prepare sudo and delete sudo as alias to gosu
19-
RUN rm -f /usr/local/bin/sudo && \
20-
groupadd -r sudo && \
21-
echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers
2217
<% else %>
2318
ENV DEBIAN_FRONTEND noninteractive
2419
RUN apt-get -y update && \
25-
apt-get install -y sudo wget autoconf cmake curl git-core pkg-config build-essential xz-utils unzip gnupg2 dirmngr zlib1g-dev libreadline-dev libsqlite0-dev libssl-dev libyaml-dev libffi-dev && \
20+
apt-get install -y sudo wget curl git-core build-essential xz-utils unzip dirmngr && \
21+
apt-get install -y autoconf cmake pkg-config zlib1g-dev libreadline-dev libsqlite0-dev libssl-dev libyaml-dev libffi-dev && \
2622
rm -rf /var/lib/apt/lists/*
2723
<% end %>
2824

29-
# Add "rvm" as system group, to avoid conflicts with host GIDs typically starting with 1000
30-
RUN groupadd -r rvm && useradd -r -g rvm -G sudo -p "" --create-home rvm
31-
32-
# Make sure rvm and later settings are available in interactive and non-interactive shells
33-
RUN echo "source /etc/profile.d/rvm.sh" >> /etc/rubybashrc && \
34-
echo "source /etc/rubybashrc" >> /etc/bashrc && \
35-
echo "source /etc/rubybashrc" >> /etc/bash.bashrc
36-
ENV BASH_ENV /etc/rubybashrc
37-
38-
USER rvm
39-
40-
RUN mkdir ~/.gnupg && \
41-
chmod 700 ~/.gnupg && \
42-
echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf
43-
44-
# install rvm, RVM 1.26.0+ has signed releases, source rvm for usage outside of package scripts
45-
RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \
46-
(curl -L http://get.rvm.io | sudo bash) && \
47-
bash -c " \
48-
source /etc/rubybashrc && \
49-
rvm autolibs disable && \
50-
rvmsudo rvm cleanup all \
51-
"
52-
53-
# Install native rubies and fix permissions
54-
COPY build/patches /home/rvm/patches/
55-
ENV RVM_RUBIES 2.5.9 3.1.3
56-
RUN bash -c " \
57-
export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \
58-
for v in ${RVM_RUBIES} ; do \
59-
rvm install \$v --patch \$(echo ~/patches/ruby-\$v/* | tr ' ' ','); \
60-
done && \
61-
rvm cleanup all && \
62-
find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw \
63-
"
64-
65-
RUN bash -c " \
66-
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
67-
rvm all do gem update --system --no-document && \
68-
rvm all do gem update --no-document && \
69-
rvm all do gem install bundler --no-document && \
70-
find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw \
71-
"
7225

7326
##
74-
## Cross compilers
27+
## Install cross compilers
7528
##
76-
USER root
77-
78-
<% if platform=~/x64-mingw-ucrt/ %>
29+
<% if platform =~ /x64-mingw-ucrt/ %>
7930
COPY --from=larskanis/mingw64-ucrt:20.04 \
8031
/build/binutils-mingw-w64-x86-64_2.34-6ubuntu1.3+8.8_amd64.deb \
8132
/build/g++-mingw-w64-x86-64_9.3.0-17ubuntu1~20.04+22~exp1ubuntu4_amd64.deb \
@@ -89,48 +40,84 @@ RUN dpkg -i /debs/*.deb
8940
<% elsif !manylinux %>
9041
RUN apt-get -y update && \
9142
apt-get install -y <%
92-
if platform=~/darwin/ %> clang python lzma-dev libxml2-dev libssl-dev libc++-10-dev <% end %><%
93-
if platform=~/aarch64-linux/ %> gcc-aarch64-linux-gnu g++-aarch64-linux-gnu <% end %><%
94-
if platform=~/arm-linux/ %> gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf <% end %><%
95-
if platform=~/x86-mingw32/ %> gcc-mingw-w64-i686 g++-mingw-w64-i686 <% end %><%
96-
if platform=~/x64-mingw32/ %> gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 <% end %> && \
43+
if platform =~ /darwin/ %> clang python lzma-dev libxml2-dev libssl-dev libc++-10-dev <% end %><%
44+
if platform =~ /aarch64-linux/ %> gcc-aarch64-linux-gnu g++-aarch64-linux-gnu <% end %><%
45+
if platform =~ /arm-linux/ %> gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf <% end %><%
46+
if platform =~ /x86-mingw32/ %> gcc-mingw-w64-i686 g++-mingw-w64-i686 <% end %><%
47+
if platform =~ /x64-mingw32/ %> gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 <% end %> && \
9748
rm -rf /var/lib/apt/lists/*
9849
<% end %>
9950

10051
<% if manylinux %>
10152
# Create dev tools x86-linux-*
10253
COPY build/mk_i686.rb /root/
10354
RUN /root/mk_i686.rb
55+
56+
## Prepare sudo
57+
RUN rm -f /usr/local/bin/sudo && \
58+
groupadd -r sudo && \
59+
echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers
10460
<% end %>
10561

106-
<% if platform=~/darwin/ %>
107-
COPY build/mk_osxcross.sh /home/rvm
108-
RUN /home/rvm/mk_osxcross.sh
62+
<% if platform =~ /darwin/ %>
63+
COPY build/mk_osxcross.sh /tmp
64+
RUN /tmp/mk_osxcross.sh
10965
<% end %>
11066

11167

11268
##
113-
## Cross-compile rubies
69+
## install rbenv and ruby-build
11470
##
115-
USER rvm
71+
RUN groupadd -r rubyuser && useradd -r -g rubyuser -G sudo -p "" --create-home rubyuser
11672

117-
RUN bash -c "rvm all do gem install --no-document rake-compiler:1.2.5"
73+
ENV RBENV_ROOT=/usr/local/rbenv RBENV_RUBIES="2.5.9 3.1.3"
11874

119-
# Install rake-compiler's cross rubies in global dir instead of /root
120-
RUN sudo mkdir -p /usr/local/rake-compiler && \
121-
sudo chown rvm.rvm /usr/local/rake-compiler && \
122-
ln -s /usr/local/rake-compiler ~/.rake-compiler
75+
# chown after running `rbenv init` because that command creates some subdirectories
76+
RUN git clone https://github.com/rbenv/rbenv.git ${RBENV_ROOT} && \
77+
git clone https://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build && \
78+
\
79+
echo "export RBENV_ROOT=/usr/local/rbenv" >> /etc/rubybashrc && \
80+
echo "export PATH=$RBENV_ROOT/bin:\$PATH" >> /etc/rubybashrc && \
81+
$RBENV_ROOT/bin/rbenv init - --no-rehash bash >> /etc/rubybashrc && \
82+
echo "source /etc/rubybashrc" >> /etc/bashrc && \
83+
echo "source /etc/rubybashrc" >> /etc/bash.bashrc && \
84+
\
85+
chown -R rubyuser:rubyuser ${RBENV_ROOT} && \
86+
find ${RBENV_ROOT} -type d -print0 | sudo xargs -0 chmod g+sw
87+
ENV BASH_ENV=/etc/rubybashrc
12388

124-
# Patch rake-compiler to build and install static libraries for Linux rubies
125-
COPY build/patches2 /home/rvm/patches/
89+
90+
##
91+
## set up rake-compiler and install bootstrap rubies
92+
##
93+
USER rubyuser
94+
95+
# Install the bootstrap rubies
12696
RUN bash -c " \
127-
for v in ${RVM_RUBIES} ; do \
128-
cd /usr/local/rvm/gems/ruby-\$v/gems/rake-compiler-1.2.5 && \
129-
echo applying patches to ruby-\$v /home/rvm/patches/rake-compiler-1.2.5/*.patch && \
130-
( git apply /home/rvm/patches/rake-compiler-1.2.5/*.patch || true ) \
97+
echo 'gem: --no-ri --no-rdoc --no-document' >> ~/.gemrc && \
98+
export CFLAGS='-s -O3 -fno-fast-math -fPIC' && \
99+
for v in ${RBENV_RUBIES} ; do \
100+
rbenv install \$v -- --disable-install-doc ; \
101+
done && \
102+
find ${RBENV_ROOT} -type d -print0 | sudo xargs -0 chmod g+w \
103+
"
104+
105+
# Install rake-compiler and patch it to build and install static libraries for Linux rubies
106+
COPY build/patches2 /home/rubyuser/patches
107+
RUN bash -c " \
108+
for v in ${RBENV_RUBIES} ; do \
109+
rbenv shell \$v && \
110+
gem install rake-compiler -v1.2.5 && \
111+
cd ${RBENV_ROOT}/versions/\$v/lib/ruby/gems/*/gems/rake-compiler-1.2.5 && \
112+
patch -p1 < /home/rubyuser/patches/rake-compiler-1.2.5/*.patch ; \
131113
done \
132114
"
133115

116+
# Install rake-compiler's cross rubies in global dir instead of /root
117+
RUN sudo mkdir -p /usr/local/rake-compiler && \
118+
sudo chown rubyuser.rubyuser /usr/local/rake-compiler && \
119+
ln -s /usr/local/rake-compiler ~/.rake-compiler
120+
134121
<%
135122
#
136123
# Build ruby versions prior to ruby2_keywords using ruby-2.5
@@ -139,7 +126,7 @@ RUN bash -c " \
139126
# Note that parallel builds of ruby with make flag `-j` are often flaky, see
140127
# https://bugs.ruby-lang.org/issues/18506
141128
#
142-
axrubies = if platform =~ /x64-mingw-ucrt/
129+
xrubies_build_plan = if platform =~ /x64-mingw-ucrt/
143130
[
144131
# Rubyinstaller-3.1.0+ is platform x64-mingw-ucrt
145132
["3.3.0-rc1:3.2.0:3.1.0", "3.1.3"],
@@ -157,35 +144,35 @@ else
157144
]
158145
end
159146

160-
axrubies.each do |xrubies, rvm| %>
147+
xrubies_build_plan.each do |xrubies, bootstrap_ruby_version| %>
161148
ENV XRUBIES <%= xrubies %>
162149

163150
<% strip = '-s' if platform !~ /darwin/ %>
164151
# Build xruby versions, then cleanup all build artifacts
165152
RUN bash -c " \
166-
rvm use <%= rvm %> && \
167-
export CPPFLAGS='<%= "-D__USE_MINGW_ANSI_STDIO=1" if platform=~/x64-mingw-ucrt/ %>' && \
153+
rbenv shell <%= bootstrap_ruby_version %> && \
154+
export CPPFLAGS='<%= "-D__USE_MINGW_ANSI_STDIO=1" if platform =~ /x64-mingw-ucrt/ %>' && \
168155
export CFLAGS='-O1 -fno-omit-frame-pointer -fno-fast-math -fstack-protector-strong <%= strip %>' && \
169156
export LDFLAGS='-pipe <%= strip %>' && \
170157
<%= "export LIBS='-l:libssp.a' &&" if platform =~ /mingw/ %> \
171158
<%= "export CC=#{target}-clang &&" if platform =~ /darwin/ %> \
172159
export MAKE='make V=1' && \
173160
rake-compiler cross-ruby VERSION=$XRUBIES HOST=<%= target %> && \
174-
rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources && \
175-
find /usr/local/rvm -type d -print0 | sudo xargs -0 chmod g+sw \
161+
rm -rf ~/.rake-compiler/builds ~/.rake-compiler/sources \
176162
"
177163
<% end %>
164+
# "
178165

179-
<% if platform=~/linux/ %>
166+
<% if platform =~ /linux/ %>
180167
# Avoid linking against libruby shared object.
181168
# See also https://github.com/rake-compiler/rake-compiler-dock/issues/13
182169
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby.so | xargs rm
183170
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby-static.a | while read f ; do cp $f `echo $f | sed s/-static//` ; done
184171
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name libruby.a | while read f ; do ar t $f | xargs ar d $f ; done
185-
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name mkmf.rb | while read f ; do sed -i ':a;N;$!ba;s/TRY_LINK = [^\n]*\n[^\n]*\n[^\n]*LOCAL_LIBS)/& -lruby-static -lpthread -lrt -ldl <% if platform=~/x86/ %> -lcrypt <% end %>/' $f ; done
172+
RUN find /usr/local/rake-compiler/ruby/*linux*/ -name mkmf.rb | while read f ; do sed -i ':a;N;$!ba;s/TRY_LINK = [^\n]*\n[^\n]*\n[^\n]*LOCAL_LIBS)/& -lruby-static -lpthread -lrt -ldl <% if platform =~ /x86/ %> -lcrypt <% end %>/' $f ; done
186173
<% end %>
187174

188-
<% if platform=~/mingw/ %>
175+
<% if platform =~ /mingw/ %>
189176
# RubyInstaller doesn't install libgcc -> link it static.
190177
RUN find /usr/local/rake-compiler/ruby/*mingw*/ -name rbconfig.rb | while read f ; do sed -i 's/."LDFLAGS". = "/&-static-libgcc /' $f ; done
191178
# Raise Windows-API to Vista (affects ruby < 2.6 only)
@@ -197,7 +184,7 @@ RUN find /usr/local/rake-compiler/ruby -name lib*-ruby*.dll.a | while read f ; d
197184
# ruby-2.5 links to libcrypt, which isn't necessary for extensions
198185
RUN find /usr/local/rake-compiler/ruby -name rbconfig.rb | while read f ; do sed -i 's/-lcrypt//' $f ; done
199186

200-
<% if platform=~/darwin/ %>
187+
<% if platform =~ /darwin/ %>
201188
# ruby-3.2+ on darwin links with `-bundle_loader`,
202189
# - see https://github.com/rake-compiler/rake-compiler-dock/issues/87
203190
# - note that we do this for "3.[2-9].0" to match rubies 3.2 and later
@@ -206,15 +193,13 @@ RUN find /usr/local/rake-compiler/ruby/*/*/lib/ruby/3.[2-9].0* -name rbconfig.rb
206193
while read f ; do sed -i 's/\["EXTDLDFLAGS"\] = "/&-Wl,-flat_namespace /' $f ; done
207194
<% end %>
208195
196+
209197
##
210198
## Final adjustments
211199
##
212200
USER root
213201
214-
# Fix paths in rake-compiler/config.yml
215-
RUN sed -i -- "s:/root/.rake-compiler:/usr/local/rake-compiler:g" /usr/local/rake-compiler/config.yml
216-
217-
<% if platform=~/mingw/ %>
202+
<% if platform =~ /mingw/ %>
218203
# Install wrappers for strip commands as a workaround for "Protocol error" in boot2docker.
219204
COPY build/strip_wrapper_vbox /root/
220205
RUN mv /usr/bin/<%= target %>-strip /usr/bin/<%= target %>-strip.bin && \
@@ -247,7 +232,7 @@ RUN cd /usr/include/ && \
247232
patch -p1 < /root/math_h.patch
248233
<% end %>
249234

250-
<% if platform=~/arm64-darwin/ %>
235+
<% if platform =~ /arm64-darwin/ %>
251236
# Add a arm64 darwin target as alternative to aarch64
252237
RUN grep -E 'rbconfig-aarch64-darwin' /usr/local/rake-compiler/config.yml | sed 's/rbconfig-[a-z0-9_]*-darwin/rbconfig-<%= platform %>/' >> /usr/local/rake-compiler/config.yml
253238
<% end %>
@@ -259,15 +244,12 @@ RUN gcc $HOME/sigfw.c -o /usr/bin/sigfw
259244
# Install user mapper
260245
COPY build/runas /usr/bin/
261246
COPY build/rcd-env.sh /etc/profile.d/
262-
RUN echo "source /etc/profile.d/rcd-env.sh" >> /etc/rubybashrc
247+
RUN echo 'source /etc/profile.d/rcd-env.sh' >> /etc/rubybashrc
263248

264249
# Install sudoers configuration
265250
COPY build/sudoers /etc/sudoers.d/rake-compiler-dock
266251

267-
RUN bash -c " \
268-
rvm alias create default 3.1.3 && \
269-
rvm use default \
270-
"
252+
RUN bash -c "rbenv global 3.1.3"
271253

272254
ENV RUBY_CC_VERSION 3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0:2.4.0
273255

0 commit comments

Comments
 (0)