Skip to content

make it a set, so we won't run twice on NUMCPUS==1 #90

make it a set, so we won't run twice on NUMCPUS==1

make it a set, so we won't run twice on NUMCPUS==1 #90

Workflow file for this run

name: Build and publish Spare Cores images
on:
push:
branches:
- main
env:
REGISTRY: ghcr.io
jobs:
find-jobs:
runs-on: ubuntu-latest
name: Find Jobs
outputs:
folders: ${{ steps.jobs.outputs.folders }}
steps:
- uses: actions/checkout@v4
- id: jobs
uses: kmanimaran/list-folder-action@v4
with:
path: ./images
matrix:
runs-on: ubuntu-latest
# runs-on: self-hosted
name: Matrix Jobs
needs: [find-jobs]
defaults:
run:
working-directory: ${{ github.workspace }}/images/${{ matrix.folder }}
strategy:
fail-fast: false
matrix:
folder: ${{ fromJson(needs.find-jobs.outputs.folders )}}
permissions:
contents: read
packages: write
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}
# idea taken from: https://github.com/docker/buildx/discussions/1382#discussioncomment-6252049
# we need to have two buildcache tags, but they conflict/race on the first build, so let's (re)build the amd64/arm64
# images from the cache and push their buildcaches individually
- name: Build and push amd64/arm64 Docker image
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}/images/${{ matrix.folder }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}:buildcache-arm64
type=registry,ref=${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}:buildcache-amd64
- name: Push amd64 Docker image's buildcache
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}/images/${{ matrix.folder }}
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}-amd64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}:buildcache-amd64
cache-to: type=registry,ref=${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}:buildcache-amd64,mode=max
- name: Push arm64 Docker image's buildcache
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}/images/${{ matrix.folder }}
platforms: linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}-arm64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}:buildcache-arm64
cache-to: type=registry,ref=${{ env.REGISTRY }}/sparecores/${{ matrix.folder }}:buildcache-arm64,mode=max