Skip to content

Commit

Permalink
build: build platforms separately
Browse files Browse the repository at this point in the history
  • Loading branch information
Michsior14 committed Sep 23, 2024
1 parent 17f6d60 commit aa70e7a
Showing 1 changed file with 137 additions and 22 deletions.
159 changes: 137 additions & 22 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ env:
RAPIDJSON_VERSION: 1.1.0
NVM_VERSION: 0.39.7

AIS_REPOSITORY_NAME: ghcr.io/michsior14/ubuntu-occt-asi-cgal-eigen-node
REPOSITORY_NAME: ghcr.io/michsior14/ubuntu-occt-cgal-eigen-node

jobs:
build-ubuntu-occt-asi-cgal-eigen-node:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

env:
IMAGE_NAME: ubuntu-occt-asi-cgal-eigen-node

strategy:
max-parallel: 1
fail-fast: false
matrix:
node: [18, 20]
platform: [linux/amd64, linux/arm64/v8]

steps:
- name: Prepare envs
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
image_name=${{ env.AIS_REPOSITORY_NAME }}
echo "IMAGE_NAME=${image_name//ghcr.io\/michsior14\///}"" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4

Expand All @@ -50,12 +56,13 @@ jobs:

- name: Build and push Docker image
uses: docker/build-push-action@v6
id: build
with:
context: ./tools/${{ env.IMAGE_NAME }}
push: true
platforms: linux/amd64,linux/arm64/v8
platforms: ${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image,name=${{ env.AIS_REPOSITORY_NAME }},push-by-digest=true,name-canonical=true,push=true
build-args: |
node_version=${{ matrix.node }}
ubuntu_version=${{ env.UBUNTU_VERSION }}
Expand All @@ -67,24 +74,79 @@ jobs:
asi_version=${{ env.ASI_VERSION }}
asi_version_mode=${{ env.ASI_VERSION_MODE }}
tags: |
ghcr.io/michsior14/${{ env.IMAGE_NAME }}:node-${{matrix.node}}${{ env.ASI_VERSION_MODE == 'commit' && format('-{0}', env.ASI_VERSION) || ''}}
ghcr.io/michsior14/${{ env.IMAGE_NAME }}:${{ env.UBUNTU_VERSION }}-occt-${{ env.OCCT_VERSION }}-asi-${{ env.ASI_VERSION }}-cgal-${{ env.CGAL_VERSION }}-eigen-${{ env.EIGEN_VERSION }}-node-${{ matrix.node }}
${{ env.AIS_REPOSITORY_NAME }}:node-${{matrix.node}}${{ env.ASI_VERSION_MODE == 'commit' && format('-{0}', env.ASI_VERSION) || ''}}
${{ env.AIS_REPOSITORY_NAME }}:${{ env.UBUNTU_VERSION }}-occt-${{ env.OCCT_VERSION }}-asi-${{ env.ASI_VERSION }}-cgal-${{ env.CGAL_VERSION }}-eigen-${{ env.EIGEN_VERSION }}-node-${{ matrix.node }}
build-ubuntu-occt-cgal-eigen-node:
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-asi-${{matrix.node}}-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge-ubuntu-occt-asi-cgal-eigen-node:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs:
- build-ubuntu-occt-asi-cgal-eigen-node

strategy:
fail-fast: false
matrix:
node: [18, 20]

steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-asi-${{matrix.node}}-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

env:
IMAGE_NAME: ubuntu-occt-cgal-eigen-node
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.AIS_REPOSITORY_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.AIS_REPOSITORY_NAME }}:node-${{matrix.node}}${{ env.ASI_VERSION_MODE == 'commit' && format('-{0}', env.ASI_VERSION) || ''}}
build-ubuntu-occt-cgal-eigen-node:
runs-on: ubuntu-latest

strategy:
max-parallel: 1
fail-fast: false
matrix:
node: [18, 20]
platform: [linux/amd64, linux/arm64/v8]

steps:
- name: Prepare envs
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
image_name=${{ env.REPOSITORY_NAME }}
echo "IMAGE_NAME=${image_name//ghcr.io\/michsior14\///}"" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4

Expand All @@ -103,12 +165,13 @@ jobs:

- name: Build and push Docker image
uses: docker/build-push-action@v6
id: build
with:
context: ./tools/${{ env.IMAGE_NAME }}
push: true
platforms: linux/amd64,linux/arm64/v8
platforms: ${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image,name=${{ env.REPOSITORY_NAME }},push-by-digest=true,name-canonical=true,push=true
build-args: |
node_version=${{ matrix.node }}
ubuntu_version=${{ env.UBUNTU_VERSION }}
Expand All @@ -117,5 +180,57 @@ jobs:
eigen_version=${{ env.EIGEN_VERSION }}
nvm_version=${{ env.NVM_VERSION }}
tags: |
ghcr.io/michsior14/${{ env.IMAGE_NAME }}:node-${{matrix.node}}
ghcr.io/michsior14/${{ env.IMAGE_NAME }}:${{ env.UBUNTU_VERSION }}-occt-${{ env.OCCT_VERSION }}-cgal-${{ env.CGAL_VERSION }}-eigen-${{ env.EIGEN_VERSION }}-node-${{ matrix.node }}
${{ env.REPOSITORY_NAME }}:node-${{matrix.node}}
${{ env.REPOSITORY_NAME }}:${{ env.UBUNTU_VERSION }}-occt-${{ env.OCCT_VERSION }}-cgal-${{ env.CGAL_VERSION }}-eigen-${{ env.EIGEN_VERSION }}-node-${{ matrix.node }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{matrix.node}}-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge-ubuntu-occt-cgal-eigen-node:
runs-on: ubuntu-latest
needs:
- build-ubuntu-occt-cgal-eigen-node

strategy:
fail-fast: false
matrix:
node: [18, 20]

steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-${{matrix.node}}-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REPOSITORY_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REPOSITORY_NAME }}:node-${{matrix.node}}

0 comments on commit aa70e7a

Please sign in to comment.