-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (85 loc) · 2.76 KB
/
docker-image-build.yaml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Docker Image Build
on:
schedule:
- cron: '45 0 * * *'
push:
branches: [ "develop", "main" ]
pull_request:
branches: [ "main" ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Get commit hash short
- name: Get Commit Hash
id: commit
uses: prompt/actions-commit-hash@v3
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: image-metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ steps.commit.outputs.short }}
# Install QEMU static binaries.
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
# Build image for scanning local
- name: Build Docker container
id: image-build-security-scan
uses: docker/build-push-action@v6
with:
tags: security-scan
labels: ${{ steps.image-metadata.outputs.labels }}
#platforms: linux/amd64,linux/arm64
push: false
load: true
# Local scan image for vulnerabilities
- name: Scan image for Vulnerabilities
id: image-security-scan
uses: aquasecurity/trivy-action@master
with:
image-ref: 'security-scan'
exit-code: '1'
ignore-unfixed: false
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
format: 'sarif'
output: 'trivy-results.sarif'
# Upload scan results
- name: Upload scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
# Build image and push
- name: Build Docker and push container
uses: docker/build-push-action@v6
with:
tags: ${{ steps.image-metadata.outputs.tags }}
labels: ${{ steps.image-metadata.outputs.labels }}
#platforms: linux/amd64,linux/arm64
push: true