| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- name: Reusable workflow to run trivy scan
- on:
- workflow_call:
- inputs:
- image-name:
- required: true
- type: string
- image-tag:
- required: false
- type: string
- tag-suffix:
- required: true
- type: string
- dockerfile:
- required: true
- type: string
- ref:
- required: false
- default: main
- type: string
- build-args:
- required: true
- type: string
- build-arch:
- required: true
- type: string
- build-platform:
- required: true
- type: string
- secrets:
- IS_FORK:
- required: false
- env:
- IMAGE_NAME: ${{ inputs.image-name }}
- TAG_SUFFIX: ${{ inputs.tag-suffix }}
- ARCH: ${{ inputs.build-arch }}
- DOCKERFILE: ${{ inputs.dockerfile }}
- IS_FORK: ${{ secrets.IS_FORK }}
- permissions:
- contents: read
- jobs:
- build-publish:
- name: Build and Publish
- runs-on: ubuntu-latest
- permissions:
- contents: read
- packages: write
- id-token: write
- outputs:
- image-tag: ${{ steps.container_info.outputs.image-tag }}
- steps:
- - uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
- with:
- egress-policy: audit
- - name: Checkout
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- with:
- ref: ${{ inputs.ref }}
- - name: Setup QEMU
- uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- with:
- platforms: all
- - name: Setup Docker Buildx
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
- with:
- version: 'v0.4.2'
- install: true
- - name: Setup Go
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
- id: setup-go
- with:
- go-version-file: "go.mod"
- - name: Download Go modules
- if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
- run: go mod download
- - name: Fetch History
- shell: bash
- run: git fetch --prune --unshallow
- - name: Login to Docker
- uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
- if: env.IS_FORK != ''
- with:
- registry: ghcr.io
- username: ${{ github.actor }}
- password: ${{ github.token }}
- - name: Get docker image tag
- id: container_info
- shell: bash
- env:
- GITHUB_REF: ${{ github.ref }}
- run: |
- # rebuild-image
- if [ "${{ inputs.image-tag }}" != "" ]; then
- TAG="${{ inputs.image-tag }}${{ inputs.tag-suffix }}"
- # main / release-x.y
- elif [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" =~ refs/heads/release-.* ]]; then
- TAG=${GITHUB_REF#refs/heads/}${{ inputs.tag-suffix }}
- # Pull Request
- else
- TAG=$(make docker.tag)
- fi
- echo "image-tag=${TAG}" >> $GITHUB_OUTPUT
- - name: Build & Publish Artifacts
- if: env.IS_FORK != ''
- shell: bash
- env:
- IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
- BUILD_ARGS: ${{ inputs.build-args }}
- DOCKER_BUILD_ARGS: >-
- --push
- --platform ${{ inputs.build-platform }}
- run: make docker.build
- - name: Build & Publish Artifacts fork
- if: env.IS_FORK == ''
- shell: bash
- env:
- IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
- BUILD_ARGS: ${{ inputs.build-args }}
- DOCKER_BUILD_ARGS: --load
- run: make docker.build
- - name: Run Trivy vulnerability scanner
- uses: aquasecurity/trivy-action@dc5a429b52fcf669ce959baa2c2dd26090d2a6c4 # master
- with:
- image-ref: ${{ inputs.image-name }}:${{ steps.container_info.outputs.image-tag }}
- format: 'table'
- exit-code: '1'
- ignore-unfixed: true
- vuln-type: 'os,library'
- severity: 'CRITICAL,HIGH'
- sign:
- runs-on: ubuntu-latest
- needs: build-publish
- permissions:
- contents: read
- id-token: write #for keyless sign
- packages: write #to update packages with added SBOMs.
- steps:
- - uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
- with:
- egress-policy: audit
- - name: Checkout
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- - name: Sign image
- if: env.IS_FORK != ''
- uses: ./.github/actions/sign
- with:
- image-name: ${{ inputs.image-name }}
- image-tag: ${{ needs.build-publish.outputs.image-tag }}
|