Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:

outputs:
ruby_sha: ${{ steps.ruby_sha.outputs.ruby_sha }}
variants: ${{ steps.variants.outputs.variants }}

steps:
- name: Resolve ruby_sha
Expand All @@ -53,13 +54,22 @@ jobs:
fi
echo "ruby_sha=$ruby_sha" >> "$GITHUB_OUTPUT"

- name: Select image variants
id: variants
run: |-
if [ "$ruby_version" = master ]; then
echo 'variants=["", "-debug", "-modular-gc"]' >> "$GITHUB_OUTPUT"
else
echo 'variants=["", "-debug"]' >> "$GITHUB_OUTPUT"
fi

build:
needs: prepare

strategy:
fail-fast: false
matrix:
debug_suffix: ['', '-debug']
variant_suffix: ${{ fromJSON(needs.prepare.outputs.variants) }}
ubuntu_version:
- resolute
- noble
Expand All @@ -71,7 +81,7 @@ jobs:
env:
ruby_sha: ${{ needs.prepare.outputs.ruby_sha }}
ubuntu_version: "${{ matrix.ubuntu_version }}"
debug_suffix: ${{ matrix.debug_suffix }}
variant_suffix: ${{ matrix.variant_suffix }}

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -90,10 +100,15 @@ jobs:
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

- run: |
if [ "${{ env.debug_suffix }}" = "-debug" ]; then
echo "cppflags=-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" >> $GITHUB_ENV
echo "optflags=-O3 -fno-inline" >> $GITHUB_ENV
fi
case "${{ env.variant_suffix }}" in
-debug)
echo "cppflags=-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" >> $GITHUB_ENV
echo "optflags=-O3 -fno-inline" >> $GITHUB_ENV
;;
-modular-gc)
echo "modular_gc=mmtk" >> $GITHUB_ENV
;;
esac

- name: Build and push docker images
run: |-
Expand All @@ -105,6 +120,7 @@ jobs:
arch=linux/${{ matrix.arch }} \
optflags="${{ env.optflags }}" \
cppflags="${{ env.cppflags }}" \
modular_gc="${{ env.modular_gc }}" \
target=$target \
push_registries="rubylang ghcr.io/ruby" \
metadata_file="$RUNNER_TEMP/$target.json" && break
Expand All @@ -116,7 +132,7 @@ jobs:

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: digests${{ matrix.debug_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }}
name: digests${{ matrix.variant_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
Expand All @@ -126,7 +142,7 @@ jobs:
payload: |
{
"attachments": [{
"text": "build ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.arch }} ${{ matrix.debug_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>",
"text": "build ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.arch }} ${{ matrix.variant_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>",
"color": "danger"
}]
}
Expand All @@ -138,7 +154,7 @@ jobs:
strategy:
fail-fast: false
matrix:
debug_suffix: ['', '-debug']
variant_suffix: ${{ fromJSON(needs.prepare.outputs.variants) }}
ubuntu_version:
- resolute
- noble
Expand Down Expand Up @@ -169,7 +185,7 @@ jobs:

- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: digests${{ matrix.debug_suffix }}-${{ matrix.ubuntu_version }}-*
pattern: digests${{ matrix.variant_suffix }}-${{ matrix.ubuntu_version }}-*
path: ${{ runner.temp }}/digests
merge-multiple: true

Expand All @@ -183,7 +199,7 @@ jobs:
registry_name="$registry_name" \
ruby_version="${{ env.ruby_version }}" \
ubuntu_version="${{ matrix.ubuntu_version }}" \
image_version_suffix=${{ matrix.debug_suffix }}$dev_suffix \
image_version_suffix=${{ matrix.variant_suffix }}$dev_suffix \
digests="$digests"
done
done
Expand All @@ -193,7 +209,7 @@ jobs:
payload: |
{
"attachments": [{
"text": "deploy_multiarch ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.debug_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>",
"text": "deploy_multiarch ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.variant_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>",
"color": "danger"
}]
}
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ COPY tmp/ruby /usr/src/ruby
ARG optflags
ARG debugflags
ARG cppflags
ARG modular_gc

RUN set -ex && \
# skip installing gem documentation
Expand Down Expand Up @@ -159,6 +160,12 @@ COPY --from=build \
# Verify that the built/copied ruby can at least run (has necessary OS dependencies, etc).
RUN /usr/local/bin/ruby -v

ARG modular_gc
RUN set -ex && \
for gc in $modular_gc; do \
RUBY_GC_LIBRARY=$gc /usr/local/bin/ruby -v -e 'GC.start'; \
done

### development ###
FROM ruby AS development

Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ FROM rubylang/ruby:4.0.9-resolute@sha256:<digest>
- `rubylang/ruby:master-dev-resolute`
- `rubylang/ruby:master-debug-resolute`
- `rubylang/ruby:master-debug-dev-resolute`
- `rubylang/ruby:master-modular-gc-resolute`
- `rubylang/ruby:master-modular-gc-dev-resolute`
- 4.0
- **`rubylang/ruby:latest`**
- `rubylang/ruby:4.0-resolute`
Expand All @@ -59,6 +61,8 @@ FROM rubylang/ruby:4.0.9-resolute@sha256:<digest>
- `rubylang/ruby:master-dev-noble`
- `rubylang/ruby:master-debug-noble`
- `rubylang/ruby:master-debug-dev-noble`
- `rubylang/ruby:master-modular-gc-noble`
- `rubylang/ruby:master-modular-gc-dev-noble`
- 4.0
- `rubylang/ruby:4.0-noble`
- `rubylang/ruby:4.0.9-noble`
Expand All @@ -76,6 +80,8 @@ FROM rubylang/ruby:4.0.9-resolute@sha256:<digest>
- `rubylang/ruby:master-dev-jammy`
- `rubylang/ruby:master-debug-jammy`
- `rubylang/ruby:master-debug-dev-jammy`
- `rubylang/ruby:master-modular-gc-jammy`
- `rubylang/ruby:master-modular-gc-dev-jammy`
- 4.0
- `rubylang/ruby:4.0-jammy`
- `rubylang/ruby:4.0.9-jammy`
Expand All @@ -95,6 +101,24 @@ Additional images are published for special purposes:
- Nightly debug builds of master (e.g. `rubylang/ruby:master-debug-nightly-noble`)
- EOL versions, for compatibility use only (e.g. `rubylang/ruby:3.2.11-noble`)

## Modular GC

The `master-modular-gc` images contain Ruby master built with `--with-modular-gc=/usr/local/lib/ruby/gc` and the [MMTk](https://www.mmtk.io/) GC library. Ruby uses the built-in GC when `RUBY_GC_LIBRARY` is not set. Set `RUBY_GC_LIBRARY` to a library name to load that library:

```
docker run --rm -e RUBY_GC_LIBRARY=mmtk rubylang/ruby:master-modular-gc-resolute ruby -v
```

To use a custom GC, copy `librubygc.<name>.so` into `/usr/local/lib/ruby/gc/` and set `RUBY_GC_LIBRARY=<name>`:

```
FROM rubylang/ruby:master-modular-gc-resolute
COPY librubygc.mygc.so /usr/local/lib/ruby/gc/
ENV RUBY_GC_LIBRARY=mygc
```

The modular GC interface is internal to Ruby. Build the library from the same Ruby commit as the image. The `master-modular-gc-<commit>-resolute` tag names that commit. Configure the Ruby source with `--with-modular-gc`, then run `make modular-gc MODULAR_GC=<name>` in the build directory. This command writes `gc/<name>/librubygc.<name>.so` in the build directory.

## Contributing

The Dockerfile and build scripts live in the [ruby/docker-images](https://github.com/ruby/docker-images) repository.
Expand All @@ -111,6 +135,12 @@ You can also specify a specific revision on the master branch:
rake docker:build ruby_version=master:ce798d08de
```

To build an image with modular GC enabled, list the GC libraries from Ruby's `gc/` directory in `modular_gc`:

```
rake docker:build ruby_version=master image_version_suffix=-modular-gc modular_gc=mmtk
```

### Triggering a build

Builds can be triggered via GitHub Actions `workflow_dispatch`. Open the Actions tab, select the "Build Docker image with multi-arch" workflow, and run it with a `ruby_version` parameter (e.g. `4.0.9` or `master`).
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace :docker do
return ruby_version, tags
end

desc "Build Docker image for Ruby (env: ruby_version, ubuntu_version, arch, image_version_suffix, tag_suffix, tag, cppflags, optflags, target, push_registries, metadata_file)"
desc "Build Docker image for Ruby (env: ruby_version, ubuntu_version, arch, image_version_suffix, tag_suffix, tag, cppflags, optflags, modular_gc, target, push_registries, metadata_file)"
task :build do
ruby_version = default_ruby_version
unless ruby_version_exist?(ruby_version)
Expand Down Expand Up @@ -317,7 +317,7 @@ namespace :docker do
ruby_so_suffix = ruby_version.match(/\A(\d+\.\d+\.\d+)/)[1]
build_args << "RUBY_SO_SUFFIX=#{ruby_so_suffix}"
end
%w(cppflags optflags).each do |name|
%w(cppflags optflags modular_gc).each do |name|
build_args << %Q(#{name}=#{ENV[name]}) if ENV.key?(name)
end

Expand Down
8 changes: 8 additions & 0 deletions install_ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ fi
--enable-zjit
)

if [ -n "$modular_gc" ]; then
configure_args+=(--with-modular-gc="$PREFIX/lib/ruby/gc")
fi

if [ -n "$cppflags" ]; then
export cppflags=$cppflags
else
Expand Down Expand Up @@ -129,6 +133,10 @@ fi
make -j "$(nproc)"
make install

for gc in $modular_gc; do
MMTK_LTO=0 make install-modular-gc MODULAR_GC="$gc" MMTK_BUILD=release
done

popd
rm -rf /tmp/ruby-build
)
Expand Down