-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from viccuad/gha-refactor
ci: Refactor GHA workflows as kubewarden-controller ones
- Loading branch information
Showing
7 changed files
with
197 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,39 @@ | ||
name: Build container image | ||
# to depend on other workflows, or provide container image for all branches | ||
name: Build container image, sign it, and generate SBOMs | ||
|
||
on: | ||
workflow_call: | ||
outputs: | ||
digest: | ||
description: "Container image digest" | ||
value: ${{jobs.build.outputs.digest}} | ||
|
||
push: | ||
branches: | ||
- main | ||
- "main" | ||
- "feat-**" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
uses: kubewarden/audit-scanner/.github/workflows/reusable-container-image.yml@main | ||
uses: ./.github/workflows/container-image.yml | ||
permissions: | ||
packages: write | ||
with: | ||
push-image: true | ||
|
||
sign: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
uses: ./.github/workflows/sign-image.yml | ||
permissions: | ||
packages: write | ||
id-token: write | ||
needs: build | ||
steps: | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3 | ||
|
||
- name: Sign the images | ||
run: | | ||
cosign sign --yes \ | ||
${{needs.build.outputs.repository}}@${{needs.build.outputs.digest}} | ||
with: | ||
image-digest: ${{ needs.build.outputs.digest }} | ||
|
||
- name: Sign the SBOM | ||
run: | | ||
tag=$(echo '${{needs.build.outputs.digest}}' | sed 's/:/-/g') | ||
cosign sign --yes \ | ||
"${{needs.build.outputs.repository}}:$tag.sbom" | ||
sbom: | ||
needs: build | ||
uses: ./.github/workflows/sbom.yml | ||
permissions: | ||
packages: write | ||
id-token: write | ||
with: | ||
image-digest: ${{ needs.build.outputs.digest }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Generate SBOMs | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
image-digest: | ||
type: string | ||
required: true | ||
|
||
jobs: | ||
sbom: | ||
name: Generate SBOM, sign and attach them to OCI image | ||
strategy: | ||
matrix: | ||
arch: [amd64, arm64] | ||
|
||
permissions: | ||
packages: write | ||
id-token: write | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install cosign | ||
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3 | ||
|
||
- name: Install the syft command | ||
uses: kubewarden/github-actions/syft-installer@00836d4962f80890a32cca1dd324d2ebafc4e29c # v3.1.5 | ||
|
||
- name: Install the crane command | ||
uses: kubewarden/github-actions/crane-installer@00836d4962f80890a32cca1dd324d2ebafc4e29c # v3.1.5 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Find platform digest | ||
shell: bash | ||
run: | | ||
set -e | ||
DIGEST=$(crane digest \ | ||
--platform "linux/${{ matrix.arch }}" \ | ||
ghcr.io/${{ github.repository_owner }}/audit-scanner@${{ inputs.image-digest }}) | ||
echo "PLATFORM_DIGEST=${DIGEST}" >> "$GITHUB_ENV" | ||
- name: Create SBOM file | ||
shell: bash | ||
run: | | ||
syft \ | ||
-o spdx-json \ | ||
--file audit-scanner-sbom-${{ matrix.arch }}.spdx \ | ||
ghcr.io/${{ github.repository_owner }}/audit-scanner@${{ env.PLATFORM_DIGEST }} | ||
- name: Sign SBOM file | ||
run: | | ||
cosign sign-blob --yes \ | ||
--output-certificate audit-scanner-sbom-${{ matrix.arch }}.spdx.cert \ | ||
--output-signature audit-scanner-sbom-${{ matrix.arch }}.spdx.sig \ | ||
audit-scanner-sbom-${{ matrix.arch }}.spdx | ||
- name: Attach SBOM file in the container image | ||
shell: bash | ||
run: | | ||
cosign attach \ | ||
sbom --sbom audit-scanner-sbom-${{ matrix.arch }}.spdx \ | ||
ghcr.io/${{ github.repository_owner }}/audit-scanner@${{ env.PLATFORM_DIGEST }} | ||
- name: Sign SBOM file pushed to OCI registry | ||
shell: bash | ||
run: | | ||
set -e | ||
SBOM_TAG="$(echo ${{ env.PLATFORM_DIGEST }} | sed -e 's/:/-/g').sbom" | ||
cosign sign --yes \ | ||
ghcr.io/${{github.repository_owner}}/audit-scanner:${SBOM_TAG} | ||
- | ||
name: Upload SBOMs as artifacts | ||
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3 | ||
with: | ||
name: sbom | ||
path: audit-scanner-sbom-* |
Oops, something went wrong.