Truffleruby: Official Docker images of Truffleruby

Created on 5 Nov 2018  路  20Comments  路  Source: oracle/truffleruby

Hello,
I believe for faster adaptation of Truffleruby is offering official Docker images of Truffleruby crucial. They would be similar to Ruby Docker images. Including Alpine versions of the images. I haven't tried Truffleruby under Alpine Linux yet. I have some doubts truffleruby and muslc aren't friends.

Anyway, it'd be nice to have in a project Dockerfile

FROM truffleruby:1.0

RUN bundle install
...

CMD rackup -o 0.0.0.0

馃樅

installing

Most helpful comment

@chrisseaton And what I wanted to say also. I'd like to just replace FROM ruby:2.5.3 for FROM truffleruby:1.0.0 in my Dockerfile. And the whole would be kept in as-is. That would be wonderful and it will help to expand truffleruby. With Oracle Linux is not used much by other Ruby folks. It's better to support ecosystems (Debian/Alpine) which are familiar to more Ruby folks. That's my main point I guess.

All 20 comments

Docker images are here

https://hub.docker.com/r/oracle/graalvm-ce/

It's based on Oracle Linux, because some of our dependencies, especially for building C extensions, are a bit complicated. What does the official Ruby Docker image do for development tools?

Easy of use? Actively maintained? In my context it's Alpine Linux where I see benefit in the size of the final image, then very easy to require development tools. I show one example

FROM ruby:2.5.3-alpine

COPY . /app

WORKDIR /app

RUN apk add --no-cache --virtual .build-deps \
    build-base && \
    bundle install --no-cache --jobs $(nproc) --without development test && \
    apk del .build-deps && \
    rm -rf vendor/bundle/ruby/2.5.0/cache

EXPOSE 9292

CMD rackup -o 0.0.0.0

The size of the final image is just 98 MB in our context. Where we have base OS, ruby, gems, and the app.

BTW: the base Docker image of GraalVM is extremely huge (557 MB). Ruby Alpine based Docker image has only 35 MB.

BTW: the base Docker image of GraalVM is extremely huge (557 MB). Ruby Alpine based Docker image has only 35 MB.

Yes, it does include a lot of things, that's true. It may be worth investigating a pure Ruby Docker image as well.

@chrisseaton And what I wanted to say also. I'd like to just replace FROM ruby:2.5.3 for FROM truffleruby:1.0.0 in my Dockerfile. And the whole would be kept in as-is. That would be wonderful and it will help to expand truffleruby. With Oracle Linux is not used much by other Ruby folks. It's better to support ecosystems (Debian/Alpine) which are familiar to more Ruby folks. That's my main point I guess.

This is obviously not an official image, but here is a minimal TruffleRuby Docker image one can build, based on the release binaries. It's 148MB uncompressed as reported by docker images (ruby:2.5.3-slim is 178MB for comparison).

FROM oraclelinux:7-slim
ENV LANG=en_US.UTF-8
RUN yum install -y zlib-devel openssl-devel && rm -rf /var/cache/yum
ADD truffleruby-1.0.0-rc9-linux-amd64.tar.gz /test
ENV PATH=/test/truffleruby-1.0.0-rc9-linux-amd64/bin:$PATH
RUN ruby --version
CMD bash

It doesn't contain dependencies for compiling C extensions though, so trying to install any C extension will fail. It's also untested.

We have a tool for generating Dockerfiles with all necessary dependencies for testing TruffleRuby, using either ubuntu, fedora or oraclelinux as base image, that can be used like this:

tool/jt.rb docker print --standalone path/to/truffleruby-1.0.0-rc9-linux-amd64.tar.gz

We run those images for testing releases, so these images should work reliably. They are obviously larger, notably because they include LLVM, and they do not try to minimize size.

Using the release binary on alpine doesn't work (/bin/sh: ./truffleruby: not found even though it does exist), and that would likely be a significant effort to compile TruffleRuby and all dependencies on alpine.

@eregon It'd be really worth to support Alpine Linux. There is @jirutka (rubyist and one of the largest package contributor to Alpine). He could help in this if he would interest in that.

BTW: JRuby has an own official Alpine Docker version as well

https://hub.docker.com/_/jruby/

^^ @chrisseaton

FYI, "official" is a little strange here. The JRuby Dockerfiles were created by a (former?) Docker employee. The JRuby team does not and never have maintained their Docker images available on Docker Hub, to the best of my knowledge.

@nirvdrum thanks for clarification about JRuby. I believed they're behind it.

Is it possible, as an intermediate step, to publish the generated Dockerfiles somewhere, so that they can be seen and used without having to install the dev environment and run jt?

(Can't answer that, but do you want me to generate a Dockerfile for you now since I already have the environment set up?)

@chrisseaton Please do. It would be helpful for me too. Thanks a lot!

FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y locales
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
RUN apt-get install -y curl
RUN apt-get install -y libz-dev
RUN apt-get install -y libssl-dev
RUN apt-get install -y make
WORKDIR /test
RUN useradd -ms /bin/bash test
RUN chown test /test
USER test
RUN curl -OL https://github.com/oracle/graal/releases/download/vm-19.2.1.0/graalvm-ce-19.2.1.0-linux-amd64.tar.gz
RUN mkdir /test/graalvm
RUN tar -zxf graalvm-ce-19.2.1.0-linux-amd64.tar.gz -C /test/graalvm --strip-components=1
RUN /test/graalvm/bin/gu install org.graalvm.ruby | tee install.log
RUN grep 'The Ruby openssl C extension needs to be recompiled on your system to work with the installed libssl' install.log
RUN grep '/jre/languages/ruby/lib/truffle/post_install_hook.sh' install.log
RUN /test/graalvm/jre/languages/ruby/lib/truffle/post_install_hook.sh
ENV PATH=/test/graalvm/bin:$PATH
RUN ruby  --version
RUN ruby --jvm --version
RUN ruby --native --version
CMD bash

Feel free to ask any questions.

While not quite official images of just TruffleRuby, Oracle does have an official GraalVM CE image. I haven't tried, but you should be able to use that as a base image and add the step to install TruffleRuby via GraalVM's gu utility.

Quick update: we're looking into this but it takes some time to get official Docker images approved.

Here is a Dockerfile using the standalone to get started in the meanwhile:

FROM oraclelinux:7-slim

ARG GRAALVM_VERSION=20.1.0
ARG TRUFFLERUBY_PKG=https://github.com/oracle/truffleruby/releases/download/vm-$GRAALVM_VERSION/truffleruby-$GRAALVM_VERSION-linux-amd64.tar.gz

RUN yum update -y oraclelinux-release-el7 \
    && yum install -y curl tar gzip zlib openssl-devel gcc make \
    && rm -rf /var/cache/yum

RUN curl --fail --location --retry 3 ${TRUFFLERUBY_PKG} | tar xz -C /opt

ENV LANG=en_US.UTF-8 \
    PATH=/opt/truffleruby-$GRAALVM_VERSION-linux-amd64/bin:$PATH

RUN echo "gem: --no-document" > ~/.gemrc
RUN /opt/truffleruby-$GRAALVM_VERSION-linux-amd64/lib/truffle/post_install_hook.sh

RUN ruby --version

See https://github.com/oracle/truffleruby/blob/master/tool/docker-configs.yaml and https://github.com/oracle/truffleruby/blob/master/README.md#dependencies for the dependencies needed if you want to use another distribution.

You can optimize it a bit more by using ADD, removing curl tar gzip and having the standalone tarball in the directory when running docker build.

It's also possible to use a multi-stage build in order to have a smaller image at the end (which is then no longer able to install C extension gems, so they need to be installed in the first stage):

# Builder image which needs dev tools to run post_install_hook.sh
FROM oraclelinux:7-slim AS builder

ARG GRAALVM_VERSION=20.1.0

RUN yum update -y oraclelinux-release-el7 \
    && yum install -y zlib openssl-devel gcc make \
    && rm -rf /var/cache/yum

ADD truffleruby-$GRAALVM_VERSION-linux-amd64.tar.gz /opt

ENV LANG=en_US.UTF-8 \
    PATH=/opt/truffleruby-$GRAALVM_VERSION-linux-amd64/bin:$PATH

RUN /opt/truffleruby-$GRAALVM_VERSION-linux-amd64/lib/truffle/post_install_hook.sh

COPY Gemfile Gemfile.lock ./
RUN bundle install

# Resulting slim image without dev tools
FROM oraclelinux:7-slim

ARG GRAALVM_VERSION=20.1.0

RUN yum update -y oraclelinux-release-el7 \
    && yum install -y zlib openssl \
    && rm -rf /var/cache/yum

COPY --from=builder /opt/truffleruby-$GRAALVM_VERSION-linux-amd64 /opt/truffleruby-$GRAALVM_VERSION-linux-amd64

ENV LANG=en_US.UTF-8 \
    PATH=/opt/truffleruby-$GRAALVM_VERSION-linux-amd64/bin:$PATH

RUN echo "gem: --no-document" > ~/.gemrc

RUN ruby --version

You can also use the GraalVM image (larger but more possibilities available) and install the TruffleRuby component with:

FROM oracle/graalvm-ce
RUN gu install ruby
RUN $(ruby -e 'print RbConfig::CONFIG["prefix"]')/lib/truffle/post_install_hook.sh
CMD bash

If it's helpful for anyone, I've published some Dockerfiles and have set up Docker Hub to build images:

Possibly of note: This configuration is also publishing nightlies every 24 hours or so.

any news on getting official truffleruby images? I've been using what @flavorjones provided, but these seem not to be coordinated with truffleruby's release schedule.

@ezzarghili Any ETA for official TruffleRuby Docker images?
Note those images would be based on oraclelinux, like the oracle/graalvm-ce image.

I'd suggest filing an issue to https://github.com/flavorjones/docker-truffleruby and discuss there how to keep it up-to-date. Maybe it can be mostly automated?

My images are being generated by dockerhub now! Should be available within the hour.

TruffleRuby now has official Docker images for releases at https://github.com/orgs/graalvm/packages/container/package/truffleruby. These images are based on oraclelinux:7-slim and oraclelinux:8-slim.
They should be relatively small, and there is a -slim variant of the images where only the strict minimum is included (but then you need to use a multi-stage Dockerfile to install C extensions first like in https://github.com/oracle/truffleruby/issues/1449#issuecomment-639006857).

For dev builds/nightlies or for users who prefer a Debian-based image, I can recommend https://github.com/flavorjones/docker-truffleruby which was already mentioned above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thbar picture thbar  路  20Comments

deepj picture deepj  路  16Comments

andrewsheelan picture andrewsheelan  路  22Comments

ashishbista picture ashishbista  路  23Comments

ivoanjo picture ivoanjo  路  31Comments