Skip to content

Commit

Permalink
Fix builds by switching to native arm64 runners (#21)
Browse files Browse the repository at this point in the history
* Update default build to 3.4.1, update rust dependency

* Extend matrix to use platform-specific runners

* Merge builds into multiarch image
  • Loading branch information
lhoBas authored Jan 24, 2025
1 parent 364ab96 commit 81fd1ad
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
69 changes: 59 additions & 10 deletions .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Build-Test-Push

on:
schedule:
- cron: "5 4 * * 3"
Expand All @@ -13,32 +14,34 @@ on:

jobs:
gather-versions:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
versions: ${{ steps.ruby-versions.outputs.versions }}
metadata: ${{ steps.ruby-versions.outputs.metadata }}
steps:
- uses: moritzheiber/ruby-versions-action@v1
name: Fetch latest Ruby versions
id: ruby-versions

build-test-push:
runs-on: ubuntu-22.04
needs: ["gather-versions"]
strategy:
matrix:
version: ${{ fromJSON(needs.gather-versions.outputs.versions) }}
image: ["slim", "ubuntu-22.04", "ubuntu-24.04"]
image: [slim, ubuntu-22.04, ubuntu-24.04]
platform: [amd64, arm64]
include: ${{ fromJSON(needs.gather-versions.outputs.metadata) }}
runs-on: ${{ matrix.platform == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
steps:
- name: Set image_name
id: context
run: |
if [[ "${{ matrix.image }}" == "slim" ]] ; then
echo "image_name=ruby:${{ matrix.version }}-slim" >> ${GITHUB_OUTPUT}
elif [[ "${{ matrix.image }}" == "ubuntu-22.04" ]] ; then
echo "image_name=ubuntu:20.04" >> ${GITHUB_OUTPUT}
elif [[ "${{ matrix.image }}" == "ubuntu-24.04" ]] ; then
echo "image_name=ubuntu:22.04" >> ${GITHUB_OUTPUT}
elif [[ "${{ matrix.image }}" == "ubuntu-24.04" ]] ; then
echo "image_name=ubuntu:24.04" >> ${GITHUB_OUTPUT}
fi
if [[ "${{ startsWith(matrix.version, '3.2') }}" == "true" ]] ; then
Expand All @@ -51,21 +54,67 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.10.6
image=moby/buildkit:v0.19.0
- uses: docker/build-push-action@v6
name: Build
id: build
with:
platforms: linux/amd64,linux/arm64
platforms: linux/${{ matrix.platform }}
push: ${{ github.ref == 'refs/heads/main' }}
cache-from: type=gha
cache-to: type=gha
cache-to: type=gha,mode=max
build-args: |
RUBY_VERSION=${{ matrix.version }}
RUBY_CHECKSUM=${{ matrix.checksum }}
IMAGE_NAME=${{ steps.context.outputs.image_name }}
ADDITIONAL_FLAGS=${{ steps.context.outputs.flags }}
tags: "ghcr.io/moritzheiber/ruby-jemalloc:${{ matrix.version }}-${{ matrix.image }}"
provenance: false
outputs: |
type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,push=${{ github.ref == 'refs/heads/main' }}
- name: Export digest
if: github.ref == 'refs/heads/main'
run: |
mkdir -p /tmp/digests/${{ matrix.version }}-${{ matrix.image }}
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${{ matrix.version }}-${{ matrix.image }}/${digest#sha256:}"
- name: Upload digest
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v3
with:
name: digests-${{ matrix.version }}-${{ matrix.image }}
path: /tmp/digests/${{ matrix.version }}-${{ matrix.image }}/*
if-no-files-found: error
retention-days: 1

merge-manifests:
needs: ["build-test-push", "gather-versions"]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
strategy:
matrix:
version: ${{ fromJSON(needs.gather-versions.outputs.versions) }}
image: [slim, ubuntu-22.04, ubuntu-24.04]
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.19.0
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests-${{ matrix.version }}-${{ matrix.image }}
path: /tmp/digests/${{ matrix.version }}-${{ matrix.image }}
- name: Create and push manifest
working-directory: /tmp/digests/${{ matrix.version }}-${{ matrix.image }}
run: |
docker buildx imagetools create -t ghcr.io/${{ github.repository }}:${{ matrix.version }}-${{ matrix.image }} \
$(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG RUBY_VERSION="3.3.1"
ARG RUBY_VERSION="3.4.1"
ARG IMAGE_NAME="ruby:${RUBY_VERSION}-slim"
# hadolint ignore=DL3006
FROM ${IMAGE_NAME}
Expand All @@ -7,7 +7,7 @@ LABEL maintainer="Moritz Heiber <[email protected]>"
LABEL org.opencontainers.image.source=https://github.com/moritzheiber/ruby-jemalloc-docker

ARG RUBY_VERSION
ARG RUBY_CHECKSUM="8dc2af2802cc700cd182d5430726388ccf885b3f0a14fcd6a0f21ff249c9aa99"
ARG RUBY_CHECKSUM="3d385e5d22d368b064c817a13ed8e3cc3f71a7705d7ed1bae78013c33aa7c87f"
ARG ADDITIONAL_FLAGS

ENV DEBIAN_FRONTEND="noninteractive" \
Expand All @@ -31,7 +31,7 @@ RUN apt-get update && \
libffi-dev \
zlib1g-dev \
libssl-dev && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain=1.77.0 && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain=1.84.0 && \
source "${HOME}/.cargo/env" && \
curl -L -o "ruby-${RUBY_VERSION}.tar.gz" "https://cache.ruby-lang.org/pub/ruby/${RUBY_VERSION%.*}/ruby-${RUBY_VERSION}.tar.gz" && \
echo "${RUBY_CHECKSUM} ruby-${RUBY_VERSION}.tar.gz" | sha256sum --strict -c - && \
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $ docker build \
--build-arg IMAGE_NAME=ubuntu:22.04 \
-t ruby-jemalloc:3.1.4-ubuntu-22.04 .
```
_Note: Ruby `3.3.1-slim` is the default when building the Docker image without any build arguments._
_Note: Ruby `3.4.1-slim` is the default when building the Docker image without any build arguments._

## Tests

Expand All @@ -105,7 +105,7 @@ dgoss run -ti ruby-jemalloc
You can specify the Ruby version to test for by passing `RUBY_VERSION` as a variable:

```console
dgoss run -ti -e RUBY_VERSION=3.3.1 ruby-jemalloc
dgoss run -ti -e RUBY_VERSION=3.4.1 ruby-jemalloc
```

_Note: `3.3.1` is the default. And don't forget to also pass the correct `RUBY_CHECKSUM`._
_Note: `3.4.1` is the default. And don't forget to also pass the correct `RUBY_CHECKSUM`._

0 comments on commit 81fd1ad

Please sign in to comment.