Skip to content

Merged

Merged #20

name: Publish Container Images
#on: workflow_dispatch
#release:
# types: [published] # todo - change this to trigger on other workflows
#push:
# branches:
# - main
#workflow_run:
# workflows: [Scala Build & Test]
# types:
# - completed
on:
push:
branches:
- "main"
- "initial-ci-setup"
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
workflow_run:
workflows: ["Rust Build & Test"]
types: [completed]
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check out the repository
uses: actions/checkout@v4
- name: Declare some variables
shell: bash
run: |
echo "short_git_hash=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
echo "git_branch=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Log in to Github 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: |
spicelabs/bigtent
ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and Push
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
provenance: mode=max
sbom: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true