-
Notifications
You must be signed in to change notification settings - Fork 1
200 lines (171 loc) · 7.3 KB
/
Copy pathdocker-pr.yml
File metadata and controls
200 lines (171 loc) · 7.3 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Build PR Images
on:
pull_request:
paths:
- '**/Dockerfile'
env:
REGISTRY: ghcr.io
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Detect changed Dockerfiles
id: changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
with:
filters: |
kasmvnc_qupath:
- '.seqera/**'
- name: Set matrix
id: set-matrix
run: |
CONTAINERS="[]"
if [[ "${{ steps.changes.outputs.kasmvnc_qupath }}" == "true" ]]; then
CONTAINERS=$(echo "$CONTAINERS" | jq -c '. + [{"name":"kasmvnc-qupath","path":"./.seqera"}]')
fi
echo "matrix={\"container\":$CONTAINERS}" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
needs: detect-changes
if: ${{ fromJson(needs.detect-changes.outputs.matrix).container[0] != null }}
permissions:
contents: read
packages: write
pull-requests: write
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
- name: Extract metadata
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}/development
tags: |
type=ref,event=pr,prefix=${{ matrix.container.name }}-pr
- name: Build and push ${{ matrix.container.name }}
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25
with:
context: ${{ matrix.container.path }}
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.container.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.container.name }}
- name: Get image reference for scan
id: scanref
run: |
echo "ref=${{ fromJSON(steps.meta.outputs.json).tags[0] }}" >> $GITHUB_OUTPUT
- name: Run security scan
uses: aquasecurity/trivy-action@76071ef0d7ec797419534a183b498b4d6366cf37
with:
image-ref: ${{ steps.scanref.outputs.ref }}
format: "table"
output: "trivy-results.txt"
severity: "CRITICAL,HIGH,MEDIUM"
exit-code: "0"
- name: Display security scan results
if: always()
run: |
echo "## 🔒 Security Scan Results - ${{ matrix.container.name }}" >> $GITHUB_STEP_SUMMARY
if [ -f trivy-results.txt ]; then
echo '```' >> $GITHUB_STEP_SUMMARY
cat trivy-results.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "No security scan results found" >> $GITHUB_STEP_SUMMARY
fi
- name: Upload security scan results
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
if: always()
with:
name: trivy-scan-${{ matrix.container.name }}-${{ github.run_id }}
path: trivy-results.txt
retention-days: 30
- name: Generate build summary
if: always()
run: |
echo "## 🐳 Build Summary - ${{ matrix.container.name }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Image**: \`${{ env.REGISTRY }}/${{ github.repository }}/development\`" >> $GITHUB_STEP_SUMMARY
echo "- **Tag**: \`${{ matrix.container.name }}-pr${{ github.event.pull_request.number }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: ${{ github.head_ref }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const fs = require('fs');
const imageName = '${{ matrix.container.name }}';
const imageTag = `${{ env.REGISTRY }}/${{ github.repository }}/development:${imageName}-pr${{ github.event.pull_request.number }}`;
const commentId = `build-results-${imageName}`;
let securityStatus = '✅ Security scan completed';
try {
if (fs.existsSync('trivy-results.txt')) {
const results = fs.readFileSync('trivy-results.txt', 'utf8');
const lines = results.split('\n');
const criticalCount = lines.filter(line => line.includes('CRITICAL')).length;
const highCount = lines.filter(line => line.includes('HIGH')).length;
const mediumCount = lines.filter(line => line.includes('MEDIUM')).length;
if (criticalCount > 0 || highCount > 0) {
securityStatus = `⚠️ Found ${criticalCount} critical, ${highCount} high, ${mediumCount} medium vulnerabilities`;
} else if (mediumCount > 0) {
securityStatus = `✅ ${mediumCount} medium vulnerabilities found`;
} else {
securityStatus = '✅ No vulnerabilities found';
}
}
} catch (e) {
securityStatus = '⚠️ Security scan results could not be parsed';
}
const output = `## 🐳 Docker Build Results - ${imageName}
✅ Docker image built successfully
| Property | Value |
|----------|-------|
| **Image** | \`${imageTag}\` |
| **Branch** | ${{ github.head_ref }} |
| **Commit** | \`${{ github.sha }}\` |
| **Security** | ${securityStatus} |
\`\`\`bash
docker pull ${imageTag}
\`\`\`
📁 Download the full security scan report from the workflow artifacts.
<!-- ${commentId} -->`;
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingComment = comments.data.find(comment =>
comment.body.includes(`<!-- ${commentId} -->`)
);
if (existingComment) {
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
}