130 lines
4.3 KiB
YAML
130 lines
4.3 KiB
YAML
name: Create and publish a Docker image
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-and-push-image:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
# Required for actions/attest-build-provenance
|
|
id-token: write
|
|
attestations: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get version from package.json
|
|
run: echo "PACKAGE_VERSION=$(jq -r '.version' app/package.json)" >> $GITHUB_ENV
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Extract Docker image metadata
|
|
id: metadata
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ github.repository }}
|
|
ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=semver,pattern={{version}},value=v${{ env.PACKAGE_VERSION }}
|
|
type=semver,pattern={{major}}.{{minor}},value=v${{ env.PACKAGE_VERSION }}
|
|
type=semver,pattern={{major}},value=v${{ env.PACKAGE_VERSION }}
|
|
type=raw,value=latest,enable=${{ !contains(env.PACKAGE_VERSION, '-') }}
|
|
|
|
- name: Build and push Docker image
|
|
id: build
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
build-args: |
|
|
PACKAGE_VERSION=${{ env.PACKAGE_VERSION }}
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
labels: ${{ steps.metadata.outputs.labels }}
|
|
annotations: ${{ steps.metadata.outputs.annotations }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Attest GHCR image
|
|
uses: actions/attest-build-provenance@v2
|
|
with:
|
|
subject-name: ghcr.io/${{ github.repository }}
|
|
subject-digest: ${{ steps.build.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
- name: Attest Docker Hub image
|
|
uses: actions/attest-build-provenance@v2
|
|
with:
|
|
subject-name: docker.io/${{ github.repository }}
|
|
subject-digest: ${{ steps.build.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
- name: Extract upload image metadata
|
|
id: upload-metadata
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ github.repository }}-upload
|
|
ghcr.io/${{ github.repository }}-upload
|
|
tags: |
|
|
type=semver,pattern={{version}},value=v${{ env.PACKAGE_VERSION }}
|
|
type=semver,pattern={{major}}.{{minor}},value=v${{ env.PACKAGE_VERSION }}
|
|
type=semver,pattern={{major}},value=v${{ env.PACKAGE_VERSION }}
|
|
type=raw,value=latest,enable=${{ !contains(env.PACKAGE_VERSION, '-') }}
|
|
|
|
- name: Build and push upload image
|
|
id: upload-build
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile.upload
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
build-args: |
|
|
PACKAGE_VERSION=${{ env.PACKAGE_VERSION }}
|
|
tags: ${{ steps.upload-metadata.outputs.tags }}
|
|
labels: ${{ steps.upload-metadata.outputs.labels }}
|
|
annotations: ${{ steps.upload-metadata.outputs.annotations }}
|
|
cache-from: type=gha,scope=upload
|
|
cache-to: type=gha,mode=max,scope=upload
|
|
|
|
- name: Attest GHCR upload image
|
|
uses: actions/attest-build-provenance@v2
|
|
with:
|
|
subject-name: ghcr.io/${{ github.repository }}-upload
|
|
subject-digest: ${{ steps.upload-build.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
- name: Attest Docker Hub upload image
|
|
uses: actions/attest-build-provenance@v2
|
|
with:
|
|
subject-name: docker.io/${{ github.repository }}-upload
|
|
subject-digest: ${{ steps.upload-build.outputs.digest }}
|
|
push-to-registry: true
|