Repository navigation
215 lines (184 loc) · 7.25 KB
/
Copy pathci.yml
File metadata and controls
215 lines (184 loc) · 7.25 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: CI/CD
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
actions: read
env:
REGISTRY: ghcr.io
jobs:
# ── Unit & integration tests ─────────────────────────────
test:
name: Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- name: Run tests
run: npm test
env:
NODE_ENV: test
JWT_SECRET: ci-test-demo-secret
STORAGE_BACKEND: json
- name: Audit dependencies
run: npm audit --audit-level=high
continue-on-error: true
# ── Static security analysis (runs parallel to tests) ───
scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Semgrep SAST
run: |
pip install semgrep
semgrep scan \
--config "p/default" \
--config "p/javascript" \
--config "p/docker" \
--config "p/github-actions" \
--json --output semgrep-results.json || true
continue-on-error: true
- name: Upload Semgrep results
uses: actions/upload-artifact@v4
if: always() && hashFiles('semgrep-results.json') != ''
with:
name: ankra-semgrep-scan
path: semgrep-results.json
retention-days: 90
- name: Checkov IaC scan
uses: bridgecrewio/checkov-action@v12
with:
directory: .
framework: dockerfile,helm,github_actions
output_format: json
output_file_path: checkov-results.json
soft_fail: true
continue-on-error: true
- name: Upload Checkov results
uses: actions/upload-artifact@v4
if: always() && hashFiles('checkov-results.json') != ''
with:
name: ankra-checkov-scan
path: checkov-results.json
retention-days: 90
# ── Docker build + Helm package (main branch only) ──────
build:
name: Build & Publish
runs-on: ubuntu-latest
needs: [test, scan]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Derive image name (lowercase)
id: repo
run: |
echo "image=${{ env.REGISTRY }}/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
# ── Docker ───────────────────────────────────────────
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.repo.outputs.image }}
tags: |
type=sha
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
# ── Image vulnerability scan ────────────────────────
- name: Get short SHA
id: vars
run: echo "short_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Trivy vulnerability scan
uses: aquasecurity/trivy-action@v0.35.0
with:
image-ref: ${{ steps.repo.outputs.image }}:sha-${{ steps.vars.outputs.short_sha }}
format: json
output: trivy-results.json
severity: CRITICAL,HIGH,MEDIUM,LOW
trivyignores: .trivyignore
continue-on-error: true
- name: Upload Trivy results
uses: actions/upload-artifact@v4
if: always() && hashFiles('trivy-results.json') != ''
with:
name: ankra-security-scan
path: trivy-results.json
retention-days: 90
# ── Helm ─────────────────────────────────────────────
- name: Setup Helm
uses: azure/setup-helm@v4
- name: Helm lint
run: helm lint chart/
- name: Package and push Helm chart
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
helm package chart/
CHART_PKG=$(ls isms-builder-*.tgz)
helm push "$CHART_PKG" oci://${{ env.REGISTRY }}/${{ steps.repo.outputs.owner }}/charts
# ── Make packages public ─────────────────────────────
# GHCR packages are private by default. Attempt to set public visibility.
# If GITHUB_TOKEN lacks permission, set visibility manually in GitHub:
# Profile → Packages → select package → Package settings → Change visibility
- name: Make container image public
run: |
curl -s -f -X PATCH \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/${{ steps.repo.outputs.owner }}/packages/container/isms-builder/visibility" \
-d '{"visibility":"public"}' || \
curl -s -f -X PATCH \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/user/packages/container/isms-builder/visibility" \
-d '{"visibility":"public"}' || true
continue-on-error: true
- name: Make Helm chart public
run: |
curl -s -f -X PATCH \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/${{ steps.repo.outputs.owner }}/packages/container/charts%2Fisms-builder/visibility" \
-d '{"visibility":"public"}' || \
curl -s -f -X PATCH \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/user/packages/container/charts%2Fisms-builder/visibility" \
-d '{"visibility":"public"}' || true
continue-on-error: true