Skip to content

Merge pull request #34 from emerconn/renovate/aquasecurity-trivy-acti… #32

Merge pull request #34 from emerconn/renovate/aquasecurity-trivy-acti…

Merge pull request #34 from emerconn/renovate/aquasecurity-trivy-acti… #32

name: Container Image
on:
workflow_dispatch:
push:
branches: ['**']
tags: ['v*.*.*']
paths:
- Dockerfile
- .dockerignore
- entrypoint.sh
- .github/workflows/container-image.yml
pull_request:
types: [opened, reopened]
branches: [main]
paths:
- Dockerfile
- .dockerignore
- entrypoint.sh
- .github/workflows/container-image.yml
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
packages: write
environment:
name: image
outputs:
tags: ${{ steps.matrix.outputs.tags }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Collect Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
flavor: latest=false
images: |
${{ github.repository_owner }}/${{ github.event.repository.name }}
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
- name: Matrix tags
id: matrix
run: |
tags=$(echo '${{ steps.meta.outputs.json }}' | jq -c '.tags | map(select(startswith("ghcr.io")) | split(":")[1])')
echo "tags=$tags" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and publish Docker image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: |
linux/amd64
linux/arm64/v8
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-to: type=gha,mode=min
cache-from: type=gha
trivy:
runs-on: ubuntu-latest
needs: [build-and-publish]
environment:
name: trivy
permissions:
packages: read
strategy:
matrix:
tag: ${{ fromJson(needs.build-and-publish.outputs.tags) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ matrix.tag }}
format: 'table'
exit-code: '1'
ignore-unfixed: false
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'