Skip to content

Improve GHA and DevContainer config #31

Improve GHA and DevContainer config

Improve GHA and DevContainer config #31

Workflow file for this run

name: Commit Stage
on: push
env:
REGISTRY: ghcr.io
IMAGE_NAME: thomasvitale/policy-demo
VERSION: ${{ github.sha }}
jobs:
build:
name: Build
runs-on: ubuntu-22.04
permissions:
attestations: write
contents: read
id-token: write
packages: write
security-events: write
outputs:
image-digest: ${{ steps.image-info.outputs.digest }}
image-name: ${{ steps.image-info.outputs.name }}
steps:
- name: Check out source code
uses: actions/checkout@v4
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: liberica
cache: gradle
- name: Compile and test
run: |
cd policies/gradle
./gradlew clean build
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom.json
path: policies/gradle/build/reports/application.cdx.json
- name: SBOM vulnerability scanning
uses: aquasecurity/trivy-action@master
with:
scan-type: 'sbom'
scan-ref: 'policies/gradle/build/reports/application.cdx.json'
format: 'sarif'
output: 'trivy-results-source-code.sarif'
- name: Upload SBOM vulnerability report
uses: actions/upload-artifact@v4
with:
name: trivy-results-source-code.sarif
path: trivy-results-source-code.sarif
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
if: success() || failure()
with:
sarif_file: 'trivy-results-source-code.sarif'
category: "source-code"
- name: Package as OCI image
run: |
cd policies/gradle
./gradlew bootBuildImage --imageName ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
- name: OCI image vulnerability scanning
uses: aquasecurity/trivy-action@master
with:
scan-type: 'image'
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
format: 'sarif'
output: 'trivy-results-oci-image.sarif'
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
if: success() || failure()
with:
sarif_file: 'trivy-results-oci-image.sarif'
category: "oci-image"
- name: Authenticate with the container registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
registry: ${{ env.REGISTRY }}
- name: Publish OCI image
run: |
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Get OCI image info
id: image-info
run: |
image_reference=$(docker inspect --format='{{index .RepoDigests 0}}' ${REGISTRY}/${IMAGE_NAME}:${VERSION})
echo $image_reference
image_digest=$(echo "$image_reference" | awk -F '@' '{print $2}')
echo $image_digest
echo "IMAGE_DIGEST=${image_digest}" >> $GITHUB_ENV
- name: Sign image
run: |
cosign sign --yes "${REGISTRY}/${IMAGE_NAME}@${IMAGE_DIGEST}"
- name: Generate SLSA Build Attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ env.IMAGE_DIGEST }}
push-to-registry: true
github-token: ${{ secrets.IMAGE_PUSH_TOKEN }}