Skip to content

Snyk ghcr

Snyk ghcr #228

Workflow file for this run

name: Snyk Container
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '30 22 * * 5'
permissions:
contents: read
packages: write
jobs:
snyk:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: ubuntu-latest
env:
GITHUB_REGISTRY: ghcr.io
strategy:
fail-fast: false
matrix:
config:
- {name: base-r}
- {name: base-r-alpine}
name: ${{ matrix.config.name }}
steps:
- uses: actions/checkout@v4
- name: Log in to the Container registry 📦
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
logout: false
- name: Prepare tags
id: docker_meta
uses: docker/metadata-action@v5.5.1
with:
images: rapporteket/${{ matrix.config.name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=schedule,pattern=weekly
type=semver,pattern={{version}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.6.1
- name: Build docker image
uses: docker/build-push-action@v6.9.0
with:
context: ./${{ matrix.config.name }}/.
file: ./${{ matrix.config.name }}/Dockerfile
push: true
tags: ${{ env.GITHUB_REGISTRY }}/${{ steps.docker_meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Log out of the Container registry
run: docker logout ${{ env.GITHUB_REGISTRY }}
- name: Run Snyk to check Docker image for vulnerabilities
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
continue-on-error: true
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ghcr.io/rapporteket/base-r-alpine:pr-98
args: --file=${{ matrix.config.name }}/Dockerfile --severity-threshold=critical
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
- name: Monitor image in Snyk UI
continue-on-error: true
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
image: ${{ env.GITHUB_REGISTRY }}/${{ steps.docker_meta.outputs.tags }}
args: --file=${{ matrix.config.name }}/Dockerfile --severity-threshold=critical --org=b034af62-43be-40c7-95e8-fdc56d6f3092
- name: Accept only vulnerability levels below critical
continue-on-error: false
uses: snyk/actions/docker@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: ${{ env.GITHUB_REGISTRY }}/${{ steps.docker_meta.outputs.tags }}
args: --file=${{ matrix.config.name }}/Dockerfile --severity-threshold=critical