Skip to content

Commit

Permalink
ci(gh-actions): update workflow to support custom image tag and build…
Browse files Browse the repository at this point in the history
… context and trigger main br
  • Loading branch information
PunGrumpy committed Jun 13, 2024
1 parent 73ec0a9 commit 2846079
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
name: 🐳 Docker
name: 🐳 Docker Workflow

on:
push:
branches:
- main
- docker
pull_request:
branches:
- docker
workflow_dispatch:
inputs:
reason:
description: 'Reason for manual run'
required: true
default: 'Manual run'
image_tag:
description: 'Docker image tag to use (default: latest)'
required: false
default: 'latest'
build_context:
description: 'Build context directory (default: .)'
required: false
default: '.'

env:
REGISTRY: ghcr.io
Expand All @@ -25,34 +31,39 @@ permissions:

jobs:
build-and-push:
name: 🚀 Build and push Docker image
name: 🚀 Build and Push Docker Image
runs-on: ubuntu-latest

steps:
- name: 🛎️ Checkout
- name: 🛎️ Checkout Repository
uses: actions/checkout@v4
- name: 🤔 Login to GitHub Container Registry

- name: 🔑 Login 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

- name: 🪙 Extract Metadata for Docker
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: latest
- name: 🏗️ Build Docker image
tags: ${{ github.event.inputs.image_tag || 'latest' }}

- name: 🏗️ Build and Push Docker Image
id: build
uses: docker/build-push-action@v5
with:
context: .
context: ${{ github.event.inputs.build_context || '.' }}
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
- name: 📦 Generate artifact attestation

- name: 📦 Generate Artifact Attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true

0 comments on commit 2846079

Please sign in to comment.