Skip to content

Commit

Permalink
edit ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
norefice-github committed Oct 10, 2023
1 parent 301d6ab commit 04e03aa
Showing 1 changed file with 77 additions and 65 deletions.
142 changes: 77 additions & 65 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ name: CI Pipeline

on:
push:
branches: [ "main" ]
branches: ["main"]
tags: ["v*.*.*"]
pull_request_target:
branches: ["main"]

env:
DOCKER_ORG: demonstrationorg
IMAGE_NAME: demonstrationorg/juvenile
SHA: ${{ github.event.after }}
SHA: ${{ github.event.pull_request.head.sha || github.event.after }}
DOCKERFILE_PATH: Dockerfile
PROD_IMAGE: demonstrationorg/juvenile:main

Expand All @@ -18,74 +20,84 @@ jobs:
build:
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read


steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ env.SHA }}

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log into registry
uses: docker/login-action@v2
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.revision=${{ env.SHA }}
com.docker.image.source.entrypoint=${{ env.DOCKERFILE_PATH }}
- name: Build and push Docker image on push
id: build-and-push
if: ${{ github.event_name != 'pull_request_target' }}
uses: docker/build-push-action@v4
with:
context: .
load: false
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: "linux/amd64,linux/arm64"
sbom: true
provenance: true

- name: Compare to deployed image
id: docker-scout-compare
if: ${{ github.event_name != 'pull_request_target' }}
uses: docker/scout-action@main
with:
command: compare
image: ${{ steps.meta.outputs.tags }}
only-severities: critical,high
to: ${{ env.PROD_IMAGE }}
platform: "linux/arm64"
exit-code: true
summary: true
organization: ${{ env.DOCKER_ORG }}

- name: Analyze for critical and high CVEs
id: docker-scout-cves
if: ${{ github.event_name == 'pull_request_target' }}
uses: docker/scout-action@main
with:
command: cves
image: ${{ steps.meta.outputs.tags }}
sarif-file: sarif.output.json
platform: "linux/arm64"
summary: true
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ env.SHA }}

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log into registry
uses: docker/login-action@v2
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.revision=${{ env.SHA }}
com.docker.image.source.entrypoint=${{ env.DOCKERFILE_PATH }}
- name: Build and push Docker image on push
id: build-and-push
if: ${{ github.event_name != 'pull_request_target' }}
uses: docker/build-push-action@v4
with:
context: .
load: false
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: "linux/amd64,linux/arm64"
sbom: true
provenance: true

- name: Build and push Docker image on PR
id: build-and-push-pr
if: ${{ github.event_name == 'pull_request_target' }}
uses: docker/build-push-action@v4
with:
context: .
load: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: "linux/arm64"
sbom: false
provenance: false

- name: Analyze for critical and high CVEs
id: docker-scout-cves
if: ${{ github.event_name != 'pull_request_target' }}
uses: docker/scout-action@main
with:
command: cves
image: ${{ steps.meta.outputs.tags }}
sarif-file: sarif.output.json
platform: "linux/arm64"
summary: true

- name: Compare to deployed image
id: docker-scout-compare
if: ${{ github.event_name == 'pull_request_target' }}
uses: docker/scout-action@main
with:
command: compare
image: ${{ steps.meta.outputs.tags }}
only-severities: critical,high
to: ${{ env.PROD_IMAGE }}
platform: "linux/arm64"
exit-code: true
summary: true
organization: ${{ env.DOCKER_ORG }}

0 comments on commit 04e03aa

Please sign in to comment.