Skip to content

feat: test trivy

feat: test trivy #23

Workflow file for this run

name: Build and publish Docker image
on:
push:
branches:
- '*'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- '*'
jobs:
trivy-scan:
name: scan image with trivy
runs-on: ubuntu-latest
env:
IMG_NAME: "kcandidate/hello"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: build local container
uses: docker/build-push-action@v2
with:
tags: ${{ IMG_NAME }}:${{ github.sha }}

Check failure on line 24 in .github/workflows/docker-image.yaml

View workflow run for this annotation

GitHub Actions / Build and publish Docker image

Invalid workflow file

The workflow is not valid. .github/workflows/docker-image.yaml (Line: 24, Col: 17): Unrecognized named-value: 'IMG_NAME'. Located at position 1 within expression: IMG_NAME

Check failure on line 24 in .github/workflows/docker-image.yaml

View workflow run for this annotation

GitHub Actions / Build and publish Docker image

Invalid workflow file

The workflow is not valid. .github/workflows/docker-image.yaml (Line: 24, Col: 17): Unrecognized named-value: 'IMG_NAME'. Located at position 1 within expression: IMG_NAME
push: false
load: true
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMG_NAME }}:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
exit-code: 1
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
build:
name: Build and push docker image
needs: trivy-scan
runs-on: ubuntu-latest
env:
IMG_NAME: "kcandidate/hello"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Debug
run: |
echo "github.ref -> {{ github.ref }}"
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v3
with:
images: ${{ env.IMG_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
- name: Log in to Docker Hub
uses: docker/login-action@v1
if: ${{ github.ref_type == 'tag' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}