Build all docker images #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker image build | |
on: | |
push: | |
branches: [ master ] | |
workflow_dispatch: ~ | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
strategy: | |
# Only allow a single parallel job to utilize build cache (second job | |
# can use build cache from first job) | |
max-parallel: 1 | |
matrix: | |
target-image: ["intel-impi-image", "gnu-ompi-image"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- uses: docker/setup-buildx-action@v2 | |
name: Set up Docker Buildx | |
id: buildx | |
- name: Get previous commit checksum | |
run: echo "PREV_COMMIT_SHA=$(git rev-parse HEAD~1)" >> $GITHUB_ENV | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: build-${{ github.sha }} | |
restore-keys: | | |
build-${{ github.sha }} | |
build-${{ env.PREV_COMMIT_SHA }} | |
build- | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
ghcr.io/kmturbulenz/${{ matrix.target-image }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=tag | |
type=sha | |
- uses: docker/login-action@v2 | |
name: Login to Github Packages | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: docker/build-push-action@v3 | |
name: Build image and push to GitHub Container Registry | |
with: | |
context: . | |
target: ${{ matrix.target-image }} | |
tags: ${{ steps.meta.outputs.tags }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
# build on feature branches, push only on master branch | |
push: ${{ github.ref == 'refs/heads/master' }} | |
# Cache trick from: | |
# https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching | |
# | |
# Other refs: | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |