generated from oliversalzburg/nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615a673
commit 012a019
Showing
6 changed files
with
209 additions
and
96 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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
name: OCI Build/Publish | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
artifact: | ||
required: false | ||
type: string | ||
attest: | ||
default: true | ||
required: false | ||
type: boolean | ||
build_args: | ||
required: false | ||
type: string | ||
context: | ||
required: true | ||
type: string | ||
image_description: | ||
required: false | ||
type: string | ||
image_name: | ||
required: true | ||
type: string | ||
image_tag: | ||
required: true | ||
type: string | ||
image_title: | ||
required: false | ||
type: string | ||
is_latest: | ||
default: false | ||
required: true | ||
type: boolean | ||
push: | ||
default: false | ||
required: false | ||
type: boolean | ||
registry: | ||
default: ghcr.io | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
build-publish: | ||
name: OCI Build ${{ inputs.push && '+ Push' || '' }} | ||
permissions: | ||
attestations: write | ||
contents: read | ||
id-token: write | ||
packages: write | ||
security-events: write | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 | ||
|
||
- if: ${{ inputs.artifact }} | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.artifact }} | ||
|
||
- name: Extract metadata | ||
id: meta | ||
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 | ||
with: | ||
images: ${{ inputs.registry }}/${{ inputs.image_name }} | ||
labels: | | ||
org.opencontainers.image.description=${{ inputs.image_description || inputs.image_title || inputs.image_name }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.source=${{ github.server_url }}/${{ inputs.context }} | ||
org.opencontainers.image.title=${{ inputs.image_title || inputs.image_name }} | ||
org.opencontainers.image.version=${{ inputs.image_tag }} | ||
tags: | | ||
type=raw,value=${{ inputs.image_tag }} | ||
type=raw,value=latest,enable=${{ inputs.is_latest }} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3 | ||
|
||
- name: Log in to the registry | ||
if: ${{ inputs.push }} | ||
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3 | ||
with: | ||
registry: ${{ inputs.registry }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build ${{ inputs.push && '+ Push' || '' }} | ||
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5 | ||
id: build | ||
env: | ||
SOURCE_DATE_EPOCH: 0 | ||
with: | ||
build-args: ${{ inputs.build_args }} | ||
cache-from: type=registry,ref=${{ inputs.registry }}/${{ github.repository }}/cache | ||
cache-to: type=registry,ref=${{ inputs.registry }}/${{ github.repository }}/cache,mode=max | ||
context: ${{ inputs.context }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64 | ||
# Pushes a provenance attestation to the registry, which can currently confuse | ||
# some clients. We skip this process for the time being, and instead attest | ||
# our SBOM manually later. | ||
provenance: false | ||
push: ${{ inputs.push }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
|
||
- name: Generate SBOM | ||
if: ${{ inputs.push }} | ||
uses: anchore/sbom-action@e8d2a6937ecead383dfe75190d104edd1f9c5751 # v0 | ||
with: | ||
artifact-name: ${{ inputs.image_tag }}.sbom.spdx.json | ||
format: spdx-json | ||
image: ${{ inputs.registry }}/${{ inputs.image_name }}:${{ inputs.image_tag }} | ||
output-file: ${{ inputs.image_tag }}.sbom.spdx.json | ||
upload-artifact: true | ||
upload-release-assets: false | ||
|
||
- name: Grype scan | ||
if: ${{ inputs.push }} | ||
uses: anchore/scan-action@3343887d815d7b07465f6fdcd395bd66508d486a # v3 | ||
id: scan | ||
with: | ||
add-cpes-if-none: true | ||
fail-build: false | ||
image: ${{ inputs.registry }}/${{ inputs.image_name }}:${{ inputs.image_tag }} | ||
severity-cutoff: critical | ||
|
||
- name: Store SARIF report | ||
if: ${{ inputs.push }} | ||
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4 | ||
with: | ||
name: ${{ inputs.image_tag }}.sarif.json | ||
path: ${{ steps.scan.outputs.sarif }} | ||
|
||
- name: Upload scan report | ||
if: ${{ inputs.push }} | ||
uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3 | ||
with: | ||
category: ${{ inputs.image_name }}-${{ inputs.image_tag }} | ||
sarif_file: ${{ steps.scan.outputs.sarif }} | ||
|
||
- name: Upload SBOM attestation | ||
uses: actions/attest-sbom@aaa2d0a82e0853a3aea99fcf632b9b61cdb534c2 # v1 | ||
if: ${{ inputs.attest && inputs.push }} | ||
id: attest | ||
with: | ||
subject-name: ${{ inputs.registry }}/${{ inputs.image_name }} | ||
subject-digest: ${{ steps.build.outputs.digest }} | ||
sbom-path: ${{ inputs.image_tag }}.sbom.spdx.json | ||
push-to-registry: true |
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
File renamed without changes.
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