|
| 1 | +# To create an image for a version of ruby, run e.g.: |
| 2 | + |
| 3 | +# docker build -t udi278 --build-arg ruby_version=2.7.8 --build-arg activerecord_version=5.2 . |
| 4 | +# docker run --name udc278 -dit udi278 |
| 5 | +# docker exec -it udc278 bash --login |
| 6 | +# docker stop udc278 && docker remove udc278 |
| 7 | + |
| 8 | +# (Any bundler_version is okay as long as its required_ruby_version is not >= 3.0.0.) |
| 9 | + |
| 10 | +FROM debian:bookworm |
| 11 | +SHELL ["/bin/bash", "-c"] |
| 12 | +ENV WORKDIR=/app |
| 13 | +WORKDIR ${WORKDIR} |
| 14 | +RUN apt update && \ |
| 15 | + apt upgrade -qy && \ |
| 16 | + apt install -qy default-mysql-client postgresql-client libyaml-dev git less procps vim && \ |
| 17 | + apt install -qy rbenv && \ |
| 18 | + rm -rf /var/lib/apt/lists/* |
| 19 | + |
| 20 | +ARG ruby_version=3.1.2 |
| 21 | +ARG activerecord_version=7.0 |
| 22 | +ARG bundler_version=2.4.22 |
| 23 | +ENV BUNDLE_GEMFILE="${WORKDIR}/gemfiles/activerecord_${activerecord_version}.gemfile" |
| 24 | + |
| 25 | +# We install rbenv, which also installs ruby-build as well as all the dependencies they |
| 26 | +# require. But debian's version of ruby-build, even in the latest bookworm, is old (2022). |
| 27 | +# Luckily rbenv basically uses ruby-build as a plugin. We remove apt's ruby-build then |
| 28 | +# install ruby-build from its main branch. That way all ruby versions are available. |
| 29 | +RUN apt remove -qy ruby-build && \ |
| 30 | + git clone --branch v20231114 https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build && \ |
| 31 | + "$(rbenv root)"/plugins/ruby-build/install.sh && \ |
| 32 | + echo 'eval "$(rbenv init -)"' >> /root/.profile && \ |
| 33 | + chmod 700 /root/.profile && \ |
| 34 | + rm -rf /var/lib/apt/lists/* |
| 35 | + |
| 36 | +# Ensure the rbenv init script in /root/.profile, added above, gets processed |
| 37 | +# before each RUN from now on, even though the bash shells are non-interactive. |
| 38 | +SHELL ["/bin/bash", "--login", "-c"] |
| 39 | + |
| 40 | +RUN rbenv install $ruby_version && \ |
| 41 | + rbenv global $ruby_version |
| 42 | +RUN gem install -v 2.4.22 bundler && \ |
| 43 | + bundle config --local build.mysql2 -- $(ruby -r rbconfig -e 'puts RbConfig::CONFIG["configure_args"]' | xargs -n1 | grep with-openssl-dir) |
| 44 | + |
| 45 | +ADD . ${WORKDIR} |
| 46 | +RUN bundle install |
0 commit comments