Skip to content

SHARD-916 Workflow addition to build and push docker image #9

SHARD-916 Workflow addition to build and push docker image

SHARD-916 Workflow addition to build and push docker image #9

Workflow file for this run

name: Create and publish a Docker image
on:
push:
branches: ['dev']
pull_request:
branches: ['dev']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
display-image-name:
runs-on: ubuntu-latest
steps:
- name: Display IMAGE_NAME
run: echo "IMAGE_NAME is ${{ env.IMAGE_NAME }}"
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Declare version variables
shell: bash
run: |
echo "SHORT_COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> "$GITHUB_ENV"
- name: Echo step
run: |
echo "Branch: ${{ env.SHORT_COMMIT_HASH }}"
echo "Sha: ${{ env.BRANCH_NAME }}"
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}-${{ env.SHORT_COMMIT_HASH }}
labels: |
version=${{ env.SHORT_COMMIT_HASH }}
branch=${{ env.BRANCH_NAME }}
- 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