Skip to content

Commit 373e971

Browse files
authored
Merge pull request #158 from rake-compiler/push-multiplat
CI: Update the publish and release workflows for multi-platform images
2 parents b5e13c6 + 6371091 commit 373e971

File tree

5 files changed

+203
-94
lines changed

5 files changed

+203
-94
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,20 @@ jobs:
9696
- name: Fetch docker buildx layer cache
9797
uses: actions/cache@v4
9898
with:
99-
path: tmp/build-cache
99+
path: tmp/build-cache-${{ runner.arch }}
100100
key: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx-${{ github.sha }}
101101
restore-keys: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx
102102
enableCrossOsArchive: true
103103
- name: Change docker to a cache-able driver
104104
run: |
105105
docker buildx create --driver docker-container --use
106-
- name: Build docker image
107-
if: runner.arch == 'X64'
108-
run: |
109-
bundle exec rake build:x86:${{ matrix.platform }} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new"
110-
- name: Build docker image
111-
if: runner.arch == 'ARM64'
112-
run: |
113-
bundle exec rake build:arm:${{ matrix.platform }} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new"
106+
bundle exec rake build:${{ matrix.platform }} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache-${{ runner.arch }} --cache-to=type=local,dest=tmp/build-cache-new"
114107
- name: Show docker images
115108
run: docker images
116109
- name: Update and prune docker buildx layer cache
117110
run: |
118-
rm -rf tmp/build-cache
119-
mv tmp/build-cache-new tmp/build-cache
111+
rm -rf tmp/build-cache-${{ runner.arch }}
112+
mv tmp/build-cache-new tmp/build-cache-${{ runner.arch }}
120113
121114
- name: Test the generated image
122115
run: bundle exec rake test TEST_PLATFORM=${{ matrix.platform }}

.github/workflows/publish-images.yml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,58 @@ on:
99

1010
jobs:
1111
build:
12+
name: build native
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os:
17+
- ubuntu-latest
18+
- ubuntu-24.04-arm
19+
platform:
20+
- aarch64-linux-gnu
21+
- aarch64-linux-musl
22+
- aarch64-mingw-ucrt
23+
- arm-linux-gnu
24+
- arm-linux-musl
25+
- arm64-darwin
26+
- jruby
27+
- x64-mingw-ucrt
28+
- x64-mingw32
29+
- x86-linux-gnu
30+
- x86-linux-musl
31+
- x86-mingw32
32+
- x86_64-darwin
33+
- x86_64-linux-gnu
34+
- x86_64-linux-musl
35+
runs-on: ${{ matrix.os }}
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: ruby/setup-ruby@v1
39+
with:
40+
ruby-version: "3.3"
41+
bundler-cache: true
42+
43+
- name: Fetch docker buildx layer cache
44+
uses: actions/cache@v4
45+
with:
46+
path: tmp/build-cache-${{ runner.arch }}
47+
key: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx-${{ github.sha }}
48+
restore-keys: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx
49+
enableCrossOsArchive: true
50+
- name: Change docker to a cache-able driver
51+
run: |
52+
docker buildx create --driver docker-container --use
53+
bundle exec rake build:${{ matrix.platform }} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache-${{ runner.arch }} --cache-to=type=local,dest=tmp/build-cache-new"
54+
- name: Show docker images
55+
run: docker images
56+
- name: Update and prune docker buildx layer cache
57+
run: |
58+
rm -rf tmp/build-cache-${{ runner.arch }}
59+
mv tmp/build-cache-new tmp/build-cache-${{ runner.arch }}
60+
61+
push:
62+
name: push
63+
needs: build
1264
strategy:
1365
fail-fast: false
1466
matrix:
@@ -60,16 +112,14 @@ jobs:
60112
run: |
61113
bundle exec ruby -e ' \
62114
require "rake_compiler_dock"; \
63-
print "image_name_opt=-t "; \
64-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})); \
65115
print "snapshot_name_opt=-t "; \
66116
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)); \
67117
if %q(${{matrix.platform}}).end_with?("-gnu"); \
68118
print "generic_linux_snapshot_name_opt=-t "; \
69119
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)).chomp("-gnu"); \
70120
end \
71121
' | tee -a $GITHUB_OUTPUT
72-
- name: Build docker image
122+
- name: Use cache and push docker image
73123
env:
74124
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache-X64 --cache-from=type=local,src=tmp/build-cache-ARM64 --cache-to=type=local,dest=tmp/build-cache-new ${{steps.rcd_config.outputs.snapshot_name_opt}} ${{steps.rcd_config.outputs.generic_linux_snapshot_name_opt}}
75125
run: |

.github/workflows/release-images.yml

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,57 @@ on:
1616
jobs:
1717
build:
1818
name: "build ${{ inputs.tag }} ${{ matrix.platform }}"
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os:
23+
- ubuntu-latest
24+
- ubuntu-24.04-arm
25+
platform:
26+
- aarch64-linux-gnu
27+
- aarch64-linux-musl
28+
- aarch64-mingw-ucrt
29+
- arm-linux-gnu
30+
- arm-linux-musl
31+
- arm64-darwin
32+
- jruby
33+
- x64-mingw-ucrt
34+
- x64-mingw32
35+
- x86-linux-gnu
36+
- x86-linux-musl
37+
- x86-mingw32
38+
- x86_64-darwin
39+
- x86_64-linux-gnu
40+
- x86_64-linux-musl
41+
runs-on: ${{ matrix.os }}
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: ruby/setup-ruby@v1
45+
with:
46+
ruby-version: "3.3"
47+
bundler-cache: true
48+
49+
- name: Fetch docker buildx layer cache
50+
uses: actions/cache@v4
51+
with:
52+
path: tmp/build-cache-${{ runner.arch }}
53+
key: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx-${{ github.sha }}
54+
restore-keys: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx
55+
enableCrossOsArchive: true
56+
- name: Change docker to a cache-able driver
57+
run: |
58+
docker buildx create --driver docker-container --use
59+
bundle exec rake build:${{ matrix.platform }} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache-${{ runner.arch }} --cache-to=type=local,dest=tmp/build-cache-new"
60+
- name: Show docker images
61+
run: docker images
62+
- name: Update and prune docker buildx layer cache
63+
run: |
64+
rm -rf tmp/build-cache-${{ runner.arch }}
65+
mv tmp/build-cache-new tmp/build-cache-${{ runner.arch }}
66+
67+
push:
68+
needs: build
69+
name: "push ${{ inputs.tag }} ${{ matrix.platform }}"
1970
strategy:
2071
fail-fast: false
2172
matrix:
@@ -40,20 +91,41 @@ jobs:
4091
- uses: actions/checkout@v4
4192
with:
4293
ref: ${{ inputs.tag }}
43-
- name: Use cache from primary pipeline
44-
uses: actions/cache@v4
94+
- name: Use X64 cache from primary pipeline
95+
uses: actions/cache/restore@v4
96+
with:
97+
path: tmp/build-cache-X64
98+
key: ${{ runner.os }}-on-X64-${{ matrix.platform }}-buildx-${{ github.sha }}
99+
restore-keys: ${{ runner.os }}-on-X64-${{ matrix.platform }}-buildx
100+
enableCrossOsArchive: true
101+
- name: Use ARM64 cache from primary pipeline
102+
uses: actions/cache/restore@v4
45103
with:
46-
path: tmp/build-cache
47-
key: ${{runner.os}}-${{matrix.platform}}-buildx-${{github.sha}}
48-
restore-keys: |
49-
${{runner.os}}-${{matrix.platform}}-buildx
104+
path: tmp/build-cache-ARM64
105+
key: ${{ runner.os }}-on-ARM64-${{ matrix.platform }}-buildx-${{ github.sha }}
106+
restore-keys: ${{ runner.os }}-on-ARM64-${{ matrix.platform }}-buildx
107+
enableCrossOsArchive: true
108+
fail-on-cache-miss: true
50109
- uses: ruby/setup-ruby@v1
51110
with:
52111
ruby-version: "3.3"
53112
bundler-cache: true
54113
- name: Generate docker image names
55114
id: rcd_config
56115
run: |
116+
bundle exec ruby -e ' \
117+
require "rake_compiler_dock"; \
118+
print "image_name_opt=-t "; \
119+
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})); \
120+
print "snapshot_name_opt=-t "; \
121+
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)); \
122+
if %q(${{matrix.platform}}).end_with?("-gnu"); \
123+
print "generic_linux_snapshot_name_opt=-t "; \
124+
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)).chomp("-gnu"); \
125+
end \
126+
' | tee -a $GITHUB_OUTPUT
127+
128+
57129
bundle exec ruby -e ' \
58130
require "rake_compiler_dock"; \
59131
print "image_name="; \

Dockerfile.mri.erb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<% image = "ubuntu:20.04" %>
22
FROM <%= image %>
33

4+
ARG TARGETPLATFORM
5+
46
##
57
## Install required base packages for compiling ruby
68
##
@@ -25,11 +27,23 @@ COPY --from=larskanis/mingw64-ucrt:20.04 \
2527
RUN dpkg -i /debs/*.deb
2628

2729
<% elsif platform =~ /aarch64-mingw-ucrt/ %>
28-
RUN wget https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-ubuntu-20.04-<%= RUBY_PLATFORM[/^\w+/] %>.tar.xz && \
30+
31+
RUN echo $TARGETPLATFORM
32+
RUN <<EOF
33+
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then
34+
DOWNLOAD_PLATFORM="x86_64";
35+
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then
36+
DOWNLOAD_PLATFORM="aarch64";
37+
else
38+
echo "Unsupported platform $TARGETPLATFORM";
39+
exit 1;
40+
fi &&
41+
wget https://github.com/mstorsjo/llvm-mingw/releases/download/20250114/llvm-mingw-20250114-ucrt-ubuntu-20.04-$DOWNLOAD_PLATFORM.tar.xz && \
2942
tar xf llvm-mingw*.tar.xz && \
3043
mv `ls -d llvm-mingw-*/` /llvm-mingw && \
3144
echo "export PATH=/llvm-mingw/bin:\$PATH" >> /etc/rubybashrc && \
3245
rm -r /llvm-mingw/bin/i686-w64* /llvm-mingw/bin/armv7-w64* /llvm-mingw/bin/x86_64-w64* /llvm-mingw/i686-w64* /llvm-mingw/armv7-w64* /llvm-mingw/x86_64-w64*
46+
EOF
3347

3448
<% elsif platform =~ /linux-musl/ %>
3549
COPY build/mk_musl_cross.sh /tmp

0 commit comments

Comments
 (0)