feat: test trivy #23
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
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 GitHub Actions / Build and publish Docker imageInvalid workflow file
Check failure on line 24 in .github/workflows/docker-image.yaml GitHub Actions / Build and publish Docker imageInvalid workflow file
|
||
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 }} |