Build and publish Docker image #71
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: Build and publish Docker image | |
on: | |
# push: | |
# branches: | |
# - main | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} # user/reponame | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
base-image: | |
- mambaorg/micromamba:git-c160e88-jammy@sha256:e3a59f560211ded26e65afafafd20eafc31bad2745db9a2932e39574847a7159 | |
- mambaorg/micromamba:git-c160e88-jammy-cuda-11.8.0@sha256:804aef13a790647f5145b0e6673f7069c4591e7871d25381ffcd778bf1fe0d4b | |
# Set permissions for GitHub token | |
# <https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#authenticating-to-package-registries-on-github> | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@8b122486cedac8393e77aa9734c3528886e4a1a8 # v2.0.0 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # v2.0.0 | |
- name: Extract tag prefix | |
id: extract_tag | |
# Extract everything between `:` and `@` in the `base-image` | |
run: | | |
TAG_PREFIX=$(echo "${{ matrix.base-image }}" | sed -E 's/[^:]+:([^@]+)@.*/\1/') | |
echo "TAG_PREFIX=$TAG_PREFIX" >> $GITHUB_ENV | |
- name: Prepare metadata | |
id: meta | |
uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a # v4.0.1 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=${{ env.TAG_PREFIX }} | |
type=raw,value=latest | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b # v2.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
id: docker_build | |
uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 # v3.0.0 | |
with: | |
context: ./docker | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: BASE_IMAGE=${{ matrix.base-image }} | |
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
cache-to: type=inline |