Skip to content

Commit

Permalink
Add tests to the matrix for docker platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ianks committed Dec 17, 2022
1 parent b8c3992 commit a9624e6
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ jobs:
- arm-linux
- aarch64-linux
- jruby
docker-platform:
- linux/amd64
- linux/arm64
docker-platform-cpu:
- amd64
- arm64

runs-on: ubuntu-latest
env:
PLATFORM: ${{ matrix.platform }}
DOCKER_BUILD_PLATFORM: linux/${{ matrix.docker-platform-cpu }}
steps:
- uses: actions/checkout@v2

- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: tmp/build-cache
key: ${{ runner.os }}-${{ matrix.platform }}-buildx-${{ github.sha }}
key: ${{ runner.os }}-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-buildx-${{ github.sha }}
# TODO: remove last key
restore-keys: |
${{ runner.os }}-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-buildx
${{ runner.os }}-${{ matrix.platform }}-buildx
- uses: ruby/setup-ruby@v1
Expand All @@ -62,9 +65,26 @@ jobs:
uses: docker/setup-qemu-action@v2

- name: Build docker image
id: buildx
run: |
docker buildx create --driver docker-container --use
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"
extra_tag="rcd-${PLATFORM}-${DOCKER_BUILD_PLATFORM}-${{ github.sha }}"
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"
bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="$docker_build"
# Save the image if the commit message contains the docker platform name (e.g. "[linux/arm64] ...")
if [[ "${{ github.event.head_commit.message }}" == *"[$DOCKER_BUILD_PLATFORM]"* ]]; then
echo "::info::Saving docker image $extra_tag"
docker save -o "tmp/${extra_tag}.tar" $extra_tag
echo "image-tarball: tmp/${extra_tag}.tar" >> $GITHUB_OUTPUT
fi
- name: Upload Docker image tarball
if: ${{ steps.buildx.outputs.image-tarball != '' }}
uses: actions/upload-artifact@v3
with:
path: ${{ steps.buildx.outputs.image-tarball }}
retention-days: 1

- name: Move build cache and remove outdated layers
run: |
Expand All @@ -83,7 +103,7 @@ jobs:
- name: Upload binary gem
uses: actions/upload-artifact@v2
with:
name: gem-${{ matrix.platform }}
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
path: test/rcd_test/pkg/*-*-*.gem

- if: matrix.platform == 'jruby'
Expand All @@ -109,11 +129,11 @@ jobs:
name: Upload static binary gem
uses: actions/upload-artifact@v2
with:
name: gem-${{ matrix.platform }}-static
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
path: test/rcd_test/pkg/*-*-*.gem

job_test_native:
name: Test (${{matrix.ruby}}, ${{matrix.platform}})
name: Test (${{matrix.ruby}}, ${{matrix.platform}}, ${{ matrix.docker-platform-cpu }})
needs: docker_build
strategy:
fail-fast: false
Expand Down Expand Up @@ -155,11 +175,11 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
- run: ruby --version
- name: Download gem-${{matrix.platform}}
- name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
uses: actions/download-artifact@v2
with:
name: gem-${{ matrix.platform }}
- name: Install gem-${{matrix.platform}}
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
- name: Install gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
run: gem install --local *.gem --verbose
- name: Run tests
run: |
Expand Down Expand Up @@ -199,11 +219,11 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
- run: ruby --version
- name: Download gem-${{matrix.platform}}-static
- name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
uses: actions/download-artifact@v2
with:
name: gem-${{ matrix.platform }}-static
- name: Install gem-${{matrix.platform}}-static
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
- name: Install gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}-static
run: gem install --local *.gem --verbose
- name: Run tests
run: |
Expand Down Expand Up @@ -237,12 +257,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download gem-${{matrix.platform}}
- name: Download gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
uses: actions/download-artifact@v2
with:
name: gem-${{ matrix.platform }}
name: gem-${{ matrix.platform }}-${{ matrix.docker-platform-cpu }}
- name: Build image and Run tests
run: |
docker buildx create --driver docker-container --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker build --rm --build-arg from_image=${{matrix.from_image}} -t ruby-test -f test/env/Dockerfile.${{matrix.dockerfile}} .
docker run --rm -t --network=host -v `pwd`:/build ruby-test
docker buildx build --platform=$DOCKER_BUILD_PLATFORM --rm --build-arg from_image=${{matrix.from_image}} -t ruby-test -f test/env/Dockerfile.${{matrix.dockerfile}} .
docker run --platform=$DOCKER_BUILD_PLATFORM --rm -t --network=host -v `pwd`:/build ruby-test

0 comments on commit a9624e6

Please sign in to comment.