From 28460793b8add5bdc27b6e1d05421b879ca1e98c Mon Sep 17 00:00:00 2001 From: PunGrumpy <108584943+PunGrumpy@users.noreply.github.com> Date: Fri, 14 Jun 2024 00:22:45 +0700 Subject: [PATCH] ci(gh-actions): update workflow to support custom image tag and build context and trigger main br --- .github/workflows/docker.yml | 39 +++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7d99ac2..9820c08 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 @@ -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