11name : Build and Publish Image
22description : Steps for building an image for a specific ruby version
33inputs :
4+ publish_manifest :
5+ required : false
6+ default : " false"
7+ description : " Set to true to publish a multi-arch manifest instead of building"
48 ruby_version :
59 required : true
610 description : " The version of Ruby to build the image for"
11+ build_platform :
12+ required : false
13+ description : " The single platform to build (linux/amd64 or linux/arm64)"
14+ platform_suffix :
15+ required : false
16+ description : " Platform suffix for arch-specific tags (amd64 or arm64)"
717 image_tag :
818 required : true
919 description : " The tag to use for the image"
@@ -16,18 +26,31 @@ inputs:
1626runs :
1727 using : " composite"
1828 steps :
29+ - name : Validate required inputs
30+ shell : bash
31+ run : |
32+ if [[ "${{ inputs.publish_manifest }}" != "true" ]]; then
33+ if [[ -z "${{ inputs.build_platform }}" || -z "${{ inputs.platform_suffix }}" ]]; then
34+ echo "build_platform and platform_suffix are required when publish_manifest is false"
35+ exit 1
36+ fi
37+ fi
38+
1939 - name : Checkout (GitHub)
40+ if : ${{ inputs.publish_manifest != 'true' }}
2041 uses : actions/checkout@v6
2142 with :
2243 ref : ${{ inputs.image_tag }}
2344
24- - name : Set up QEMU for multi-architecture builds
25- uses : docker/setup-qemu-action@v3
26-
2745 - name : Set up Docker Buildx
46+ if : ${{ inputs.publish_manifest != 'true' }}
2847 uses : docker/setup-buildx-action@v3
2948 with :
30- platforms : linux/amd64,linux/arm64
49+ platforms : ${{ inputs.build_platform }}
50+
51+ - name : Set up Docker Buildx (manifest)
52+ if : ${{ inputs.publish_manifest == 'true' }}
53+ uses : docker/setup-buildx-action@v3
3154
3255 - name : Set Image version env variable
3356 run : echo "IMAGE_VERSION=$(echo ${{ inputs.image_tag }} | tr -d ruby-)" >> $GITHUB_ENV
@@ -41,16 +64,25 @@ runs:
4164 password : ${{ inputs.gh_token }}
4265
4366 - name : Pre-build Dev Container Image
67+ if : ${{ inputs.publish_manifest != 'true' }}
4468 uses : devcontainers/ci@v0.3
4569 env :
4670 RUBY_VERSION : ${{ inputs.ruby_version }}
4771 BUILDX_NO_DEFAULT_ATTESTATIONS : true
4872 with :
4973 imageName : ghcr.io/rails/devcontainer/images/ruby
50- imageTag : ${{ env.IMAGE_VERSION }}-${{ inputs.ruby_version }},${{ inputs.ruby_version }}
74+ imageTag : ${{ env.IMAGE_VERSION }}-${{ inputs.ruby_version }}-${{ inputs.platform_suffix }},${{ inputs.ruby_version }}-${{ inputs.platform_suffix }}
75+ cacheFrom : ghcr.io/rails/devcontainer/images/ruby:${{ inputs.ruby_version }}-${{ inputs.platform_suffix }}
5176 subFolder : images/ruby
5277 push : always
53- platform : linux/amd64,linux/arm64
78+ platform : ${{ inputs.build_platform }}
5479
55- - name : Checkout (GitHub)
56- uses : actions/checkout@v6
80+ - name : Create and push multi-arch manifest
81+ if : ${{ inputs.publish_manifest == 'true' }}
82+ shell : bash
83+ run : |
84+ docker buildx imagetools create \
85+ -t ghcr.io/rails/devcontainer/images/ruby:${IMAGE_VERSION}-${{ inputs.ruby_version }} \
86+ -t ghcr.io/rails/devcontainer/images/ruby:${{ inputs.ruby_version }} \
87+ ghcr.io/rails/devcontainer/images/ruby:${IMAGE_VERSION}-${{ inputs.ruby_version }}-amd64 \
88+ ghcr.io/rails/devcontainer/images/ruby:${IMAGE_VERSION}-${{ inputs.ruby_version }}-arm64
0 commit comments