Skip to content

Build Docker image with multi-arch #153

Build Docker image with multi-arch

Build Docker image with multi-arch #153

Workflow file for this run

name: Build Docker image with multi-arch
on:
schedule:
- cron: '15 */8 * * *'
repository_dispatch:
types:
- build
workflow_dispatch:
inputs:
ruby_version:
required: true
default: master
description: '"master" or version nunmber ("3.1.2")'
env:
ruby_version: ${{ github.event.inputs.ruby_version || github.event.client_payload.ruby_version || 'master' }}
jobs:
build:
strategy:
fail-fast: false
matrix:
ubuntu_version:
- noble
- jammy
- focal
dev_suffix: [ '', '-dev' ]
debug_suffix: ['', '-debug']
arch: ['amd64', 'arm64']
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
env:
nightly: false
push: false
ubuntu_version: "${{ matrix.ubuntu_version }}"
tag_suffix: "-${{ matrix.arch }}-${{ github.sha }}"
push_tags: ${{ inputs.ruby_version || 'master' }}${{ matrix.debug_suffix }}${{ matrix.dev_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }}-${{ github.sha }}
dev_suffix: ${{ matrix.dev_suffix }}
debug_suffix: ${{ matrix.debug_suffix }}
steps:
- uses: actions/[email protected]
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_ACCESS_TOKEN }}
- run: |
if [ "${{ env.dev_suffix }}" = "-dev" ]; then
echo "target=development" >> $GITHUB_ENV
else
echo "target=ruby" >> $GITHUB_ENV
fi
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
- name: Build docker image
run: |-
rake docker:build ruby_version=${{ env.ruby_version }} \
ubuntu_version=${{ env.ubuntu_version }} \
arch=linux/${{ matrix.arch }} \
image_version_suffix=${{ env.debug_suffix }}${{ env.dev_suffix }} \
nightly=${{ env.nightly }} \
tag_suffix=${{ env.tag_suffix }} \
optflags="${{ env.optflags }}" \
cppflags="${{ env.cppflags }}" \
target=${{ env.target }} \
- name: List images
run: docker images
- name: Push docker image to rubylang
if: "${{ env.push_tags }}"
run: |-
push_tags="${{ env.push_tags }}"
for tag in $push_tags; do
docker push rubylang/ruby:$tag
done
- name: Push docker image to ghcr.io/ruby
if: "${{ env.push_tags }}"
run: |-
push_tags="${{ env.push_tags }}"
for tag in $push_tags; do
docker tag rubylang/ruby:$tag ghcr.io/ruby/ruby:$tag
docker push ghcr.io/ruby/ruby:$tag
done
deploy_multiarch:
strategy:
matrix:
registry_name: [ rubylang, ghcr.io/ruby ]
ubuntu_version:
- noble
- jammy
- focal
image_version_suffix: [ '', '-dev', '-debug', '-debug-dev' ]
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/[email protected]
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
if: ${{ matrix.registry_name == 'rubylang' }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_ACCESS_TOKEN }}
if: ${{ matrix.registry_name == 'ghcr.io/ruby' }}
- name: Create manifest for ${{ matrix.registry_name }}
run: |-
rake docker:manifest:create \
registry_name="${{ matrix.registry_name }}" \
ruby_version="${{ env.ruby_version }}" \
ubuntu_version="${{ matrix.ubuntu_version }}" \
architectures="amd64 arm64" \
manifest_suffix=${{ github.sha }} \
image_version_suffix=${{ matrix.image_version_suffix }}
- name: Push manifest to ${{ matrix.registry_name }}
run: |-
rake docker:manifest:push \
registry_name="${{ matrix.registry_name }}" \
ruby_version="${{ env.ruby_version }}" \
ubuntu_version="${{ matrix.ubuntu_version }}" \
image_version_suffix=${{ matrix.image_version_suffix }}