Skip to content

Commit b5e13c6

Browse files
authored
Merge pull request #140 from rake-compiler/multiplat
Multiplatform build support
2 parents 612cf2d + 6afb119 commit b5e13c6

File tree

8 files changed

+226
-134
lines changed

8 files changed

+226
-134
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ jobs:
4444
strategy:
4545
fail-fast: false
4646
matrix:
47+
os:
48+
- ubuntu-latest
49+
- ubuntu-24.04-arm
50+
platform:
51+
- aarch64-linux-gnu
52+
- aarch64-linux-musl
53+
- aarch64-mingw-ucrt
54+
- arm-linux-gnu
55+
- arm-linux-musl
56+
- arm64-darwin
57+
- jruby
58+
- x64-mingw-ucrt
59+
- x64-mingw32
60+
- x86-linux-gnu
61+
- x86-linux-musl
62+
- x86-mingw32
63+
- x86_64-darwin
64+
- x86_64-linux-gnu
65+
- x86_64-linux-musl
4766
include:
4867
- platform: aarch64-linux-gnu
4968
alias: aarch64-linux
@@ -66,7 +85,7 @@ jobs:
6685
- platform: x86_64-linux-gnu
6786
alias: x86_64-linux
6887
- platform: x86_64-linux-musl
69-
runs-on: ubuntu-latest
88+
runs-on: ${{ matrix.os }}
7089
steps:
7190
- uses: actions/checkout@v4
7291
- uses: ruby/setup-ruby@v1
@@ -78,13 +97,22 @@ jobs:
7897
uses: actions/cache@v4
7998
with:
8099
path: tmp/build-cache
81-
key: ${{ runner.os }}-${{ matrix.platform }}-buildx-${{ github.sha }}
82-
restore-keys: ${{ runner.os }}-${{ matrix.platform }}-buildx
83-
- name: Build docker image
100+
key: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx-${{ github.sha }}
101+
restore-keys: ${{ runner.os }}-on-${{ runner.arch }}-${{ matrix.platform }}-buildx
102+
enableCrossOsArchive: true
103+
- name: Change docker to a cache-able driver
84104
run: |
85105
docker buildx create --driver docker-container --use
86-
bundle exec rake build:${{ 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 --load"
87-
docker images
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"
114+
- name: Show docker images
115+
run: docker images
88116
- name: Update and prune docker buildx layer cache
89117
run: |
90118
rm -rf tmp/build-cache
@@ -101,6 +129,7 @@ jobs:
101129
bundle exec rake gem:${{ matrix.platform }}
102130
103131
- name: Upload native gem
132+
if: runner.arch == 'X64'
104133
uses: actions/upload-artifact@v4
105134
with:
106135
name: gem-${{ matrix.platform }}
@@ -116,7 +145,7 @@ jobs:
116145
bundle exec rake clean clobber
117146
bundle exec rake gem:${{ matrix.platform }}
118147
119-
- if: matrix.static
148+
- if: matrix.static && runner.arch == 'X64'
120149
name: Upload static native gem
121150
uses: actions/upload-artifact@v4
122151
with:
@@ -131,7 +160,7 @@ jobs:
131160
bundle exec rake clean clobber
132161
bundle exec rake gem:${{ matrix.alias }}
133162
134-
- if: matrix.alias
163+
- if: matrix.alias && runner.arch == 'X64'
135164
name: Upload native gem ${{ matrix.alias }}
136165
uses: actions/upload-artifact@v4
137166
with:

.github/workflows/publish-images.yml

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,47 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- uses: actions/checkout@v4
34-
- name: Use cache from primary pipeline
35-
uses: actions/cache@v4
34+
- name: Use X64 cache from primary pipeline
35+
uses: actions/cache/restore@v4
3636
with:
37-
path: tmp/build-cache
38-
key: ${{runner.os}}-${{matrix.platform}}-buildx-${{github.sha}}
39-
restore-keys: |
40-
${{runner.os}}-${{matrix.platform}}-buildx
37+
path: tmp/build-cache-X64
38+
key: ${{ runner.os }}-on-X64-${{ matrix.platform }}-buildx-${{ github.sha }}
39+
restore-keys: ${{ runner.os }}-on-X64-${{ matrix.platform }}-buildx
40+
enableCrossOsArchive: true
41+
- name: Use ARM64 cache from primary pipeline
42+
uses: actions/cache/restore@v4
43+
with:
44+
path: tmp/build-cache-ARM64
45+
key: ${{ runner.os }}-on-ARM64-${{ matrix.platform }}-buildx-${{ github.sha }}
46+
restore-keys: ${{ runner.os }}-on-ARM64-${{ matrix.platform }}-buildx
47+
enableCrossOsArchive: true
48+
fail-on-cache-miss: true
4149
- uses: ruby/setup-ruby@v1
4250
with:
4351
ruby-version: "3.3"
4452
bundler-cache: true
53+
- uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{github.actor}}
57+
password: ${{secrets.GITHUB_TOKEN}}
4558
- name: Generate docker image names
4659
id: rcd_config
4760
run: |
4861
bundle exec ruby -e ' \
4962
require "rake_compiler_dock"; \
50-
print "image_name="; \
63+
print "image_name_opt=-t "; \
5164
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})); \
52-
print "snapshot_name="; \
65+
print "snapshot_name_opt=-t "; \
5366
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)); \
5467
if %q(${{matrix.platform}}).end_with?("-gnu"); \
55-
print "generic_linux_snapshot_name="; \
68+
print "generic_linux_snapshot_name_opt=-t "; \
5669
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)).chomp("-gnu"); \
5770
end \
5871
' | tee -a $GITHUB_OUTPUT
5972
- name: Build docker image
6073
env:
61-
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load
74+
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}}
6275
run: |
6376
docker buildx create --driver docker-container --use
64-
bundle exec rake build:${{matrix.platform}}
65-
# move build cache and remove outdated layers
66-
rm -rf tmp/build-cache
67-
mv tmp/build-cache-new tmp/build-cache
68-
- uses: docker/login-action@v3
69-
with:
70-
registry: ghcr.io
71-
username: ${{github.actor}}
72-
password: ${{secrets.GITHUB_TOKEN}}
73-
- name: Push the docker image
74-
run: |
75-
docker images
76-
docker tag ${{steps.rcd_config.outputs.image_name}} ${{steps.rcd_config.outputs.snapshot_name}}
77-
docker push ${{steps.rcd_config.outputs.snapshot_name}}
78-
- name: Push a generic linux image
79-
if: ${{ steps.rcd_config.outputs.generic_linux_snapshot_name }}
80-
run: |
81-
docker tag ${{steps.rcd_config.outputs.image_name}} ${{steps.rcd_config.outputs.generic_linux_snapshot_name}}
82-
docker push ${{steps.rcd_config.outputs.generic_linux_snapshot_name}}
77+
bundle exec rake release:${{matrix.platform}}

.github/workflows/release-images.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ jobs:
6565
' | tee -a $GITHUB_OUTPUT
6666
- name: Build docker image
6767
env:
68-
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load
68+
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new
6969
run: |
7070
docker buildx create --driver docker-container --use
71-
bundle exec rake build:${{matrix.platform}}
71+
bundle exec rake build:x86:${{matrix.platform}}
7272
# move build cache and remove outdated layers
7373
rm -rf tmp/build-cache
7474
mv tmp/build-cache-new tmp/build-cache

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,46 @@ docker buildx create --use --driver=docker-container
6464
bundle exec rake build
6565
```
6666

67+
68+
### Create builder instance for two architectures
69+
70+
Building with qemu emulation fails currently with a segfault, so that it must be built by a builder instance with at least one remote node for the other architecture.
71+
Building on native hardware is also much faster (~45 minutes) than on qemu.
72+
A two-nodes builder requires obviously a ARM and a Intel/AMD device.
73+
It can be created like this:
74+
75+
```sh
76+
# Make sure the remote instance can be connected
77+
$ docker -H ssh://isa info
78+
79+
# Create a new builder with the local instance
80+
# Disable the garbage collector by the config file
81+
$ docker buildx create --name isayoga --config build/buildkitd.toml
82+
83+
# Add the remote instance
84+
$ docker buildx create --name isayoga --config build/buildkitd.toml --append ssh://isa
85+
86+
# They are inactive from the start
87+
$ docker buildx ls
88+
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
89+
isayoga docker-container
90+
\_ isayoga0 \_ unix:///var/run/docker.sock inactive
91+
\_ isayoga1 \_ ssh://isa inactive
92+
default* docker
93+
\_ default \_ default running v0.13.2 linux/arm64
94+
95+
# Bootstrap the instances
96+
$ docker buildx inspect --bootstrap --builder isayoga
97+
98+
# Set the new builder as default
99+
$ docker buildx use isayoga
100+
101+
# Now it should be default and in state "running"
102+
$ docker buildx ls
103+
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
104+
isayoga* docker-container
105+
\_ isayoga0 \_ unix:///var/run/docker.sock running v0.18.2 linux/arm64
106+
\_ isayoga1 \_ ssh://isa running v0.18.2 linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386
107+
default docker
108+
\_ default \_ default running v0.13.2 linux/arm64
109+
```

0 commit comments

Comments
 (0)