Skip to content

Commit a9624e6

Browse files
committed
Add tests to the matrix for docker platform
1 parent b8c3992 commit a9624e6

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

.github/workflows/ci.yml

+40-19
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,25 @@ jobs:
3535
- arm-linux
3636
- aarch64-linux
3737
- jruby
38-
docker-platform:
39-
- linux/amd64
40-
- linux/arm64
38+
docker-platform-cpu:
39+
- amd64
40+
- arm64
4141

4242
runs-on: ubuntu-latest
4343
env:
4444
PLATFORM: ${{ matrix.platform }}
45+
DOCKER_BUILD_PLATFORM: linux/${{ matrix.docker-platform-cpu }}
4546
steps:
4647
- uses: actions/checkout@v2
4748

4849
- name: Cache Docker layers
49-
uses: actions/cache@v2
50+
uses: actions/cache@v3
5051
with:
5152
path: tmp/build-cache
52-
key: ${{ runner.os }}-${{ matrix.platform }}-buildx-${{ github.sha }}
53+
key: ${{ runner.os }}-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-buildx-${{ github.sha }}
54+
# TODO: remove last key
5355
restore-keys: |
56+
${{ runner.os }}-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-buildx
5457
${{ runner.os }}-${{ matrix.platform }}-buildx
5558
5659
- uses: ruby/setup-ruby@v1
@@ -62,9 +65,26 @@ jobs:
6265
uses: docker/setup-qemu-action@v2
6366

6467
- name: Build docker image
68+
id: buildx
6569
run: |
6670
docker buildx create --driver docker-container --use
67-
bundle exec rake build:${PLATFORM} DOCKER_BUILD_PLATFORM="${{ matrix.docker-platform }}" RCD_DOCKER_BUILD="docker buildx build --platform=${{ matrix.docker-platform }} --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load"
71+
extra_tag="rcd-${PLATFORM}-${DOCKER_BUILD_PLATFORM}-${{ github.sha }}"
72+
docker_build="docker buildx build --platform=$DOCKER_BUILD_PLATFORM --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load -t $extra_tag"
73+
bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build"
74+
75+
# Save the image if the commit message contains the docker platform name (e.g. "[linux/arm64] ...")
76+
if [[ "${{ github.event.head_commit.message }}" == *"[$DOCKER_BUILD_PLATFORM]"* ]]; then
77+
echo "::info::Saving docker image $extra_tag"
78+
docker save -o "tmp/${extra_tag}.tar" $extra_tag
79+
echo "image-tarball: tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT
80+
fi
81+
82+
- name: Upload Docker image tarball
83+
if: ${{ steps.buildx.outputs.image-tarball != '' }}
84+
uses: actions/upload-artifact@v3
85+
with:
86+
path: ${{ steps.buildx.outputs.image-tarball }}
87+
retention-days: 1
6888

6989
- name: Move build cache and remove outdated layers
7090
run: |
@@ -83,7 +103,7 @@ jobs:
83103
- name: Upload binary gem
84104
uses: actions/upload-artifact@v2
85105
with:
86-
name: gem-${{ matrix.platform }}
106+
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
87107
path: test/rcd_test/pkg/*-*-*.gem
88108

89109
- if: matrix.platform == 'jruby'
@@ -109,11 +129,11 @@ jobs:
109129
name: Upload static binary gem
110130
uses: actions/upload-artifact@v2
111131
with:
112-
name: gem-${{ matrix.platform }}-static
132+
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
113133
path: test/rcd_test/pkg/*-*-*.gem
114134

115135
job_test_native:
116-
name: Test (${{matrix.ruby}}, ${{matrix.platform}})
136+
name: Test (${{matrix.ruby}}, ${{matrix.platform}}, ${{ matrix.docker-platform-cpu }})
117137
needs: docker_build
118138
strategy:
119139
fail-fast: false
@@ -155,11 +175,11 @@ jobs:
155175
with:
156176
ruby-version: ${{ matrix.ruby }}
157177
- run: ruby --version
158-
- name: Download gem-${{matrix.platform}}
178+
- name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
159179
uses: actions/download-artifact@v2
160180
with:
161-
name: gem-${{ matrix.platform }}
162-
- name: Install gem-${{matrix.platform}}
181+
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
182+
- name: Install gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
163183
run: gem install --local *.gem --verbose
164184
- name: Run tests
165185
run: |
@@ -199,11 +219,11 @@ jobs:
199219
with:
200220
ruby-version: ${{ matrix.ruby }}
201221
- run: ruby --version
202-
- name: Download gem-${{matrix.platform}}-static
222+
- name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
203223
uses: actions/download-artifact@v2
204224
with:
205-
name: gem-${{ matrix.platform }}-static
206-
- name: Install gem-${{matrix.platform}}-static
225+
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
226+
- name: Install gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
207227
run: gem install --local *.gem --verbose
208228
- name: Run tests
209229
run: |
@@ -237,12 +257,13 @@ jobs:
237257
runs-on: ubuntu-latest
238258
steps:
239259
- uses: actions/checkout@v2
240-
- name: Download gem-${{matrix.platform}}
260+
- name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
241261
uses: actions/download-artifact@v2
242262
with:
243-
name: gem-${{ matrix.platform }}
263+
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
244264
- name: Build image and Run tests
245265
run: |
266+
docker buildx create --driver docker-container --use
246267
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
247-
docker build --rm --build-arg from_image=${{matrix.from_image}} -t ruby-test -f test/env/Dockerfile.${{matrix.dockerfile}} .
248-
docker run --rm -t --network=host -v `pwd`:/build ruby-test
268+
docker buildx build --platform=$DOCKER_BUILD_PLATFORM --rm --build-arg from_image=${{matrix.from_image}} -t ruby-test -f test/env/Dockerfile.${{matrix.dockerfile}} .
269+
docker run --platform=$DOCKER_BUILD_PLATFORM --rm -t --network=host -v `pwd`:/build ruby-test

0 commit comments

Comments
 (0)