Add GitHub Actions workflow for Docker images #17
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: Create and publish Docker images | |
on: | |
push: { branches: [ unstable ] } | |
pull_request: { branches: [ unstable ] } | |
workflow_call: | |
workflow_dispatch: | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- name: github_ci | |
- name: openmpi | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }}_${{ matrix.name }} | |
- uses: actions/cache@v3 | |
with: | |
path: var-cache-ccache | |
key: ccache-${{ matrix.name }}-${{ github.run_id }} | |
restore-keys: | |
ccache-${{ matrix.name }}- | |
- name: Inject ccache into Docker | |
uses: reproducible-containers/buildkit-cache-dance@v2 | |
with: | |
cache-source: var-cache-ccache | |
cache-target: /var/cache/ccache | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./Docker | |
file: ./Docker/${{ matrix.name }}_dockerfile | |
build-args: | | |
NCORES=2 | |
no-cache-filters: pkgs | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha,scope=${{ github.ref_name }}-${{ matrix.name }} | |
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ matrix.name }} |