-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (74 loc) · 2.57 KB
/
Copy pathci.yml
File metadata and controls
85 lines (74 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# =============================================================================
# OID - GitHub Actions CI Workflow
# =============================================================================
# Triggers on pushes to main and pull requests to:
# 1. Lint the Dockerfile with hadolint
# 2. Build the Docker image (multi-platform, no push)
# 3. Scan the image for vulnerabilities with Trivy
# =============================================================================
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# ---------------------------------------------------------------------------
# Job 1: Lint Dockerfile with hadolint
# ---------------------------------------------------------------------------
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
config: .hadolint.yaml
failure-threshold: warning
# ---------------------------------------------------------------------------
# Job 2: Build and scan Docker image
# ---------------------------------------------------------------------------
build-and-scan:
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
security-events: write
steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build Docker image (single platform for CI, loaded locally for scanning)
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: false
load: true
tags: ${{ env.IMAGE_NAME }}:ci
cache-from: type=gha
cache-to: type=gha,mode=max
# Scan the built image for vulnerabilities
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@v0.24.0
with:
image-ref: "${{ env.IMAGE_NAME }}:ci"
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"
ignore-unfixed: true
# Upload Trivy scan results to GitHub Security tab
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: "trivy-results.sarif"