Skip to content

Commit

Permalink
[CI] Ajout docker container scan
Browse files Browse the repository at this point in the history
  • Loading branch information
syji35 committed Nov 23, 2023
1 parent 8998bff commit 842b9d9
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ name: Build Docker

on:
push:
branches: ["main", "develop"]
branches: ["main","develop"]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]


env:
Expand All @@ -16,6 +18,9 @@ env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository_owner }}/lufi

permissions:
contents: read


jobs:
build:
Expand All @@ -32,28 +37,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3


# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
uses: docker/metadata-action@v5.0.0 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
Expand All @@ -64,12 +51,22 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up Docker Buildx
uses: docker/[email protected] # v3.0.0
- name: Log to GHCR
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
uses: docker/build-push-action@v5.0.0 # v5.0.0
with:
context: .
platforms: linux/amd64
Expand All @@ -79,3 +76,11 @@ jobs:
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Lufi Docker
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max

- name: Scan for vulnerabilities
uses: crazy-max/ghaction-container-scan@v3
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{github.ref_name}}
dockerfile: ./Dockerfile
annotations: true
severity: CRITICAL

0 comments on commit 842b9d9

Please sign in to comment.