Go to file
Shkar T. Noori 95127ca9d2
Add harbor scan report inputs and commenting functionality in action.yml
This update introduces new input parameters for enabling harbor scan report retrieval and commenting on pull requests. The action now includes logic to comment on the PR with scan results, enhancing visibility and feedback during the CI/CD process.
2025-05-09 03:10:50 +03:00
.github Bump docker/build-push-action from 5 to 6 2024-06-18 04:46:54 +00:00
action.yml Add harbor scan report inputs and commenting functionality in action.yml 2025-05-09 03:10:50 +03:00
LICENSE Initial commit 2022-08-17 16:53:41 +03:00
README.md Update README.md 2024-03-04 15:40:49 +03:00

Build Image Workflow

This GitHub Action automates the process of building and pushing a Docker image to a self-hosted registry. The workflow includes setting up Docker Buildx, extracting metadata, logging in to the registry, and building and pushing the Docker image.

Inputs

image (required)

  • Description: Image Name
  • Required: true

build-args (optional)

  • Description: Build Arguments
  • Required: false

file (optional)

  • Description: Dockerfile Path
  • Required: false

registry (required)

  • Description: Registry URL
  • Required: true
  • Default: reg.dev.krd

username (required)

  • Description: Username for the registry
  • Required: true

password (required)

  • Description: Password for the registry
  • Required: true

build-secrets (optional)

  • Description: Build Secrets
  • Required: false

Outputs

tag

  • Description: Image Tag
  • Value: ${{ steps.meta.outputs.tags[0] }}

tags

  • Description: Image Tags
  • Value: ${{ steps.meta.outputs.tags }}

Workflow Steps

  1. Set up Docker Buildx:

    • Uses: docker/setup-buildx-action@v3
  2. Extract Metadata:

    • Uses: docker/metadata-action@v5
    • Inputs:
      • images: ${{ inputs.registry }}/${{ inputs.image }}
      • flavor: latest=false
      • tags:
        • Cache: type=raw,value=${{ github.ref_name }}-cache
        • Branches: type=ref,event=branch, type=ref,event=branch,suffix=-{{sha}},priority=8888
        • Releases: type=semver,pattern={{major}}, type=semver,pattern={{major}}.{{minor}}, type=semver,pattern={{version}},priority=9999
  3. Login to Registry:

    • Uses: docker/login-action@v3
    • Inputs:
      • registry: ${{ inputs.registry }}
      • username: ${{ inputs.username }}
      • password: ${{ inputs.password }}
  4. Build Docker images:

    • Uses: docker/build-push-action@v5
    • Inputs:
      • push: true
      • file: ${{ inputs.file }}
      • tags: ${{ steps.meta.outputs.tags }}
      • cache-to: type=inline
      • cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.image }}:${{ github.ref_name }}-cache
      • build-args: ${{ inputs.build-args }}
      • secrets: ${{ inputs.build-secrets }}

Example Usage

name: Build Image Workflow
on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Build and Push Image
        uses: ditkrg/build-image-workflow@v1
        with:
          image: "my-docker-image"
          registry: "my-registry.example.com"
          username: ${{ secrets.REGISTRY_USERNAME }}
          password: ${{ secrets.REGISTRY_PASSWORD }}
          build-args: "EXAMPLE=123"
          build-secrets: "EXAMPLE=****"
          file: "path/to/Dockerfile"

If you want to use it with our GitOps Action:

name: Deploy

on:
  push:
    branches:
      - dev
      - main
    tags:
      - v[0-9]+.[0-9]+.[0-9]+

    paths-ignore:
      - "**.md"
      - ".vscode/**"

      - ".github/**"
      - "!.github/workflows/tests-base.yaml"
      - "!.github/workflows/deploy.yaml"

jobs:
  build:
    runs-on: ubuntu-latest
    concurrency: build-${{ github.ref_name }}
    outputs:
      tag: ${{ steps.build-image.outputs.tag }}
      tags: ${{ steps.build-image.outputs.tags }}
    steps:
      - id: build-image
        name: Build and Push Image
        uses: ditkrg/build-image-workflow@v1
        with:
          image: "my-docker-image"
          registry: "my-registry.example.com"
          username: ${{ secrets.REGISTRY_USERNAME }}
          password: ${{ secrets.REGISTRY_PASSWORD }}
          build-args: "EXAMPLE=123"
          build-secrets: "EXAMPLE=****"
          file: "path/to/Dockerfile"

  update-gitops:
    runs-on: ubuntu-latest
    concurrency: pr-${{ github.ref_name }}
    needs: build
    steps:
      - name: Update gitops
        uses: ditkrg/update-gitops-image@v1
        with:
          owner: ditkrg
          repo: GITOPS_REPO
          app-id: ${{ secrets.APP_ID }}
          image-tag: ${{ needs.build.outputs.tag }}
          private-key: ${{ secrets.APP_PRIVATE_KEY }}
          component-name: REPO_NAME