Skip to content

Restructure Actions #164

Restructure Actions

Restructure Actions #164

# This workflow will build and push a signed Docker image
name: Build and sign image
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build_and_sign_image:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: anchore/sbom-action@v0
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
- name: Install cosign
uses: sigstore/cosign-installer@9614fae9e5c5eddabb09f90a270fcb487c9f7149 #v3.0.2
with:
cosign-release: 'v1.13.1'
- name: Log into registry ${{ env.REGISTRY }} for ${{ github.actor }}
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build Docker Image
id: docker-build-and-push
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{github.run_number}}
- name: Sign the published Docker images
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: cosign sign "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.docker-build-and-push.outputs.digest }}"
# NOTE: This runs statically against the latest tag in Docker Hub which was not produced by this workflow
# This should be updated once this workflow is fully implemented
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@91713af97dc80187565512baba96e4364e983601 # 0.16.0
continue-on-error: true
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
format: 'sarif'
output: 'trivy-results-${{ inputs.image }}.sarif'
ignore-unfixed: 'true'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@b374143c1149a9115d881581d29b8390bbcbb59c # v2.2.11
continue-on-error: true
with:
sarif_file: 'trivy-results-${{ inputs.image }}.sarif'
sha: ${{ github.sha }}
ref: ${{ github.ref }}
- name: Generate Release
uses: ncipollo/release-action@v1
with:
body: |
# Release ${{ github.ref }}
## Changelog
${{ steps.meta.outputs.changelog }}
discussionCategory: "Release"
generateReleaseNotes: true
makeLatest: false
name: "nginx-loadbalancer-kubernetes ${{ github.ref }}"