Für ein legacy Projekt benötigte ich ruby 2.3 das ich auf dem Apple Silicon bauen kann.

Nach einigem knobeln ergab sich dieses Dockerfile:

# syntax=docker/dockerfile:1

# Debian 11
FROM debian:bullseye-20240812-slim AS base

# --- packages ---

ENV DEBIAN_FRONTEND "noninteractive"
COPY sources.list /etc/apt/

RUN apt-get update -qq && apt-get install --no-install-recommends -y \
    build-essential \
    nodejs \
    libpq-dev \
    libxml2-dev \
    libxslt1-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    git \
    rbenv ruby-build \
    && apt-get autoremove -y \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


# --- openssl for ruby 2.3 ---
FROM base

RUN cd /usr/local/src; \
    curl -L https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz -o openssl-1.0.2u.tar.gz && \
    tar xzf openssl-1.0.2u.tar.gz && rm -f openssl-1.0.2u.tar.gz

RUN cd /usr/local/src/openssl-1.0.2u; \
    CFLAGS=-fPIC ./config shared --prefix=$HOME/.openssl/openssl-1.0.2u --openssldir=$HOME/.openssl/openssl-1.0.2u; \
    make; \
    make install; \
    cd /; rm -Rf /usr/local/src/openssl-1.0.2u

RUN rm -rf $HOME/.openssl/openssl-1.0.2u/certs && \
    ln -s /etc/ssl/certs $HOME/.openssl/openssl-1.0.2u/certs


# --- ruby 2.3 ---

RUN CONFIGURE_OPTS="--with-openssl-dir=$HOME/.openssl/openssl-1.0.2u" \
    RUBY_CONFIGURE_OPTS="--disable-install-doc --with-openssl-dir=$HOME/.openssl/openssl-1.0.2u" rbenv install -v 2.3.8 && \
    rbenv global 2.3.8

RUN echo 'eval "$(rbenv init -)"' >> /etc/profile

CMD ruby -v

Für ruby-2.4.10 war das schon etwas entspannter:

# syntax=docker/dockerfile:1

# Debian 11
FROM debian:bullseye-20241202-slim AS base

# --- packages ---

ENV DEBIAN_FRONTEND "noninteractive"
COPY sources.list /etc/apt/

RUN apt-get update -qq  \
    && apt-get install --no-install-recommends -y \
    build-essential \
    nodejs \
    libpq-dev \
    libxml2-dev \
    libxslt1-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    git \
    rbenv ruby-build \
    && apt-get autoremove -y \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN rbenv install -v 2.4.10 && \
    rbenv global 2.4.10
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile

CMD ruby -v

sources.list

# deb http://snapshot.debian.org/archive/debian/20210408T000000Z bullseye main
##deb http://deb.debian.org/debian bullseye main
deb http://ftp.de.debian.org/debian bullseye main

# deb http://snapshot.debian.org/archive/debian-security/20210408T000000Z bullseye-security main
##deb http://security.debian.org/debian-security bullseye-security main
deb http://ftp.de.debian.org/debian-security bullseye-security main

# deb http://snapshot.debian.org/archive/debian/20210408T000000Z bullseye-updates main
##deb http://deb.debian.org/debian bullseye-updates main
deb http://ftp.de.debian.org/debian bullseye-updates main