2022-10-06 17:14:13 +00:00
|
|
|
name: Reusable workflow to run trivy scan
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
image-name:
|
|
|
|
required: true
|
|
|
|
type: string
|
2022-11-22 21:07:19 +00:00
|
|
|
image-tag:
|
|
|
|
required: false
|
|
|
|
type: string
|
2022-10-06 17:14:13 +00:00
|
|
|
tag-suffix:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
dockerfile:
|
|
|
|
required: true
|
|
|
|
type: string
|
2022-11-22 21:07:19 +00:00
|
|
|
ref:
|
|
|
|
required: false
|
|
|
|
default: main
|
|
|
|
type: string
|
2022-11-23 20:25:19 +00:00
|
|
|
build-args:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
build-arch:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
build-platform:
|
|
|
|
required: true
|
|
|
|
type: string
|
2022-10-06 17:14:13 +00:00
|
|
|
secrets:
|
|
|
|
GHCR_USERNAME:
|
|
|
|
required: true
|
|
|
|
GHCR_TOKEN:
|
|
|
|
required: true
|
|
|
|
|
|
|
|
env:
|
|
|
|
IMAGE_NAME: ${{ inputs.image-name }}
|
|
|
|
TAG_SUFFIX: ${{ inputs.tag-suffix }}
|
2022-11-23 20:25:19 +00:00
|
|
|
ARCH: ${{ inputs.build-arch }}
|
2022-10-06 17:14:13 +00:00
|
|
|
DOCKERFILE: ${{ inputs.dockerfile }}
|
2022-10-06 21:05:08 +00:00
|
|
|
IS_FORK: ${{ secrets.GHCR_USERNAME == '' && 'true' || 'false' }}
|
2022-10-06 17:14:13 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-publish:
|
|
|
|
name: Build and Publish
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
image-tag: ${{ steps.container_info.outputs.image-tag }}
|
|
|
|
steps:
|
|
|
|
|
|
|
|
- name: Checkout
|
2024-05-25 13:15:00 +00:00
|
|
|
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
2022-11-22 21:07:19 +00:00
|
|
|
with:
|
|
|
|
ref: ${{ inputs.ref }}
|
2022-10-06 17:14:13 +00:00
|
|
|
|
|
|
|
- name: Setup QEMU
|
2024-01-18 20:03:07 +00:00
|
|
|
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
|
2022-10-06 17:14:13 +00:00
|
|
|
with:
|
|
|
|
platforms: all
|
|
|
|
|
|
|
|
- name: Setup Docker Buildx
|
2024-04-09 06:07:48 +00:00
|
|
|
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
|
2022-10-06 17:14:13 +00:00
|
|
|
with:
|
|
|
|
version: 'v0.4.2'
|
|
|
|
install: true
|
|
|
|
|
|
|
|
- name: Setup Go
|
2024-05-06 23:26:37 +00:00
|
|
|
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
|
2023-11-01 15:54:27 +00:00
|
|
|
id: setup-go
|
2022-10-06 17:14:13 +00:00
|
|
|
with:
|
|
|
|
go-version-file: "go.mod"
|
|
|
|
|
2023-11-01 15:54:27 +00:00
|
|
|
- name: Download Go modules
|
|
|
|
if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
|
|
|
|
run: go mod download
|
|
|
|
|
2022-10-06 17:14:13 +00:00
|
|
|
- name: Fetch History
|
|
|
|
shell: bash
|
|
|
|
run: git fetch --prune --unshallow
|
|
|
|
|
|
|
|
- name: Login to Docker
|
2024-04-16 20:56:55 +00:00
|
|
|
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
|
2022-10-06 21:05:08 +00:00
|
|
|
if: env.IS_FORK == 'false'
|
2022-10-06 17:14:13 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
|
2022-10-08 21:53:15 +00:00
|
|
|
- name: Get docker image tag
|
|
|
|
id: container_info
|
|
|
|
shell: bash
|
|
|
|
env:
|
|
|
|
GITHUB_REF: ${{ github.ref }}
|
|
|
|
run: |
|
2023-05-15 07:06:15 +00:00
|
|
|
# rebuild-image
|
2022-11-22 21:07:19 +00:00
|
|
|
if [ "${{ inputs.image-tag }}" != "" ]; then
|
|
|
|
TAG="${{ inputs.image-tag }}${{ inputs.tag-suffix }}"
|
2023-05-15 07:06:15 +00:00
|
|
|
# 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
|
2022-10-08 21:53:15 +00:00
|
|
|
else
|
|
|
|
TAG=$(make docker.tag)
|
|
|
|
fi
|
2023-12-21 21:30:54 +00:00
|
|
|
echo "image-tag=${TAG}" >> $GITHUB_OUTPUT
|
2022-10-08 21:53:15 +00:00
|
|
|
|
2022-10-06 17:14:13 +00:00
|
|
|
- name: Build & Publish Artifacts
|
2022-10-06 21:05:08 +00:00
|
|
|
if: env.IS_FORK == 'false'
|
2022-10-06 17:14:13 +00:00
|
|
|
shell: bash
|
|
|
|
env:
|
2022-10-10 17:59:25 +00:00
|
|
|
IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
|
2022-11-23 20:25:19 +00:00
|
|
|
BUILD_ARGS: ${{ inputs.build-args }}
|
|
|
|
DOCKER_BUILD_ARGS: >-
|
2022-10-06 17:14:13 +00:00
|
|
|
--push
|
2022-11-23 20:25:19 +00:00
|
|
|
--platform ${{ inputs.build-platform }}
|
2022-10-06 17:14:13 +00:00
|
|
|
run: make docker.build
|
|
|
|
|
2022-10-06 21:05:08 +00:00
|
|
|
- name: Build & Publish Artifacts fork
|
|
|
|
if: env.IS_FORK == 'true'
|
|
|
|
shell: bash
|
|
|
|
env:
|
2022-10-10 17:59:25 +00:00
|
|
|
IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
|
2022-11-23 20:25:19 +00:00
|
|
|
BUILD_ARGS: ${{ inputs.build-args }}
|
|
|
|
DOCKER_BUILD_ARGS: --load
|
2022-10-06 21:05:08 +00:00
|
|
|
run: make docker.build
|
|
|
|
|
2022-10-06 17:14:13 +00:00
|
|
|
- name: Run Trivy vulnerability scanner
|
2024-06-03 08:34:22 +00:00
|
|
|
uses: aquasecurity/trivy-action@fd25fed6972e341ff0007ddb61f77e88103953c2 # master
|
2022-10-06 17:14:13 +00:00
|
|
|
with:
|
2022-10-06 21:05:08 +00:00
|
|
|
image-ref: ${{ inputs.image-name }}:${{ steps.container_info.outputs.image-tag }}
|
2022-10-06 17:14:13 +00:00
|
|
|
format: 'table'
|
|
|
|
exit-code: '1'
|
|
|
|
ignore-unfixed: true
|
|
|
|
vuln-type: 'os,library'
|
|
|
|
severity: 'CRITICAL,HIGH'
|
|
|
|
|
|
|
|
sign:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: build-publish
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2024-05-25 13:15:00 +00:00
|
|
|
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
2022-10-06 17:14:13 +00:00
|
|
|
- name: Sign image
|
2022-10-06 21:05:08 +00:00
|
|
|
if: env.IS_FORK == 'false'
|
2022-10-06 17:14:13 +00:00
|
|
|
uses: ./.github/actions/sign
|
|
|
|
with:
|
|
|
|
image-name: ${{ inputs.image-name }}
|
|
|
|
image-tag: ${{ needs.build-publish.outputs.image-tag }}
|
|
|
|
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|