Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
253 lines (239 loc) · 11 KB
/
Copy pathJenkinsfile
File metadata and controls
253 lines (239 loc) · 11 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
pipeline {
agent { label 'built-in' }
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
disableConcurrentBuilds()
skipDefaultCheckout(true)
timestamps()
timeout(time: 300, unit: 'MINUTES')
}
parameters {
string(name: 'GIT_URL', defaultValue: 'https://github.com/Timik232/DialogScribe.git', description: 'Repository URL or Jenkins-local Git bundle')
string(name: 'GIT_REF', defaultValue: 'master', description: 'Branch, tag, or commit to verify')
booleanParam(name: 'RUN_MODEL_TESTS', defaultValue: false, description: 'Dispatch GPU/HuggingFace/model checks to a dedicated labeled executor')
booleanParam(name: 'FORCE_NO_CACHE', defaultValue: false, description: 'Rebuild images from scratch regardless of dependency-change detection')
}
environment {
PYTHON_IMAGE = "dialogscribe-ci-python:${BUILD_NUMBER}"
APP_IMAGE = "dialogscribe-ci-app:${BUILD_NUMBER}"
PIP_INDEX_URL = 'http://192.168.1.48:3141/root/pypi/+simple/'
PIP_EXTRA_INDEX_URL = 'https://pypi.org/simple/'
NPM_CONFIG_REGISTRY = 'https://registry.npmjs.org'
JWT_SECRET = 'ci-test-only'
HOST_WORKSPACE = '/DATA/AppData/jenkins/home/workspace/dialogscribe-ci'
}
stages {
stage('Clean checkout') {
steps {
sh '''
docker run --rm \
-v "$HOST_WORKSPACE:/w" \
alpine:3 \
sh -c "chown -R $(id -u):$(id -g) /w && find /w -mindepth 1 -maxdepth 1 -exec rm -rf {} +"
'''
sh '''
set -eu
case "$GIT_URL" in
*.tar.gz|*.tgz)
tar -xzf "$GIT_URL"
;;
*.tar)
tar -xf "$GIT_URL"
;;
*)
git clone --no-tags "$GIT_URL" .
case "$GIT_REF" in
master) git checkout --detach origin/master ;;
*) git checkout --detach "$GIT_REF" ;;
esac
;;
esac
mkdir -p .ci-artifacts
chmod 0777 .ci-artifacts
echo "$GIT_REF" > .ci-artifacts/verified-commit.txt
# Images are built from the layer cache by default. A change to the
# dependency manifests or the Dockerfiles only adds --pull (fresh base
# image): the affected layers rebuild anyway, cache keys follow file
# content. --no-cache is reserved for FORCE_NO_CACHE=true - a manual
# switch and the monthly dialogscribe-ci-nocache verification job.
NOCACHE_FLAG=""
if [ "${FORCE_NO_CACHE:-}" = "true" ]; then
NOCACHE_FLAG="--pull --no-cache"
elif ! git rev-parse --verify -q origin/master >/dev/null 2>&1; then
NOCACHE_FLAG="--pull --no-cache"
elif git diff --name-only origin/master...HEAD | grep -qE '^(requirements[^/]*[.]txt|ci/Dockerfile[.]python|Dockerfile|frontend/package(-lock)?[.]json)$'; then
NOCACHE_FLAG="--pull"
fi
echo "$NOCACHE_FLAG" > .ci-artifacts/nocache-flag
echo "image build flags: ${NOCACHE_FLAG:---cached}"
'''
}
}
stage('Secret scan') {
steps {
sh '''
docker run --rm \
--user "$(id -u):$(id -g)" \
-v "$HOST_WORKSPACE:/repo" \
zricethezav/gitleaks:v8.24.3 \
dir /repo --redact --no-banner \
--report-format=json \
--report-path=/repo/.ci-artifacts/gitleaks.json
'''
}
}
stage('Build Python test image') {
steps {
sh '''
NOCACHE_FLAG="$(cat .ci-artifacts/nocache-flag)"
docker build $NOCACHE_FLAG -f ci/Dockerfile.python -t "$PYTHON_IMAGE" .
'''
}
}
stage('Audit matrix') {
steps {
sh '''
docker run --rm \
--user "$(id -u):$(id -g)" \
-e PYTHONDONTWRITEBYTECODE=1 -e HOME=/tmp \
-v "$HOST_WORKSPACE:/workspace" -w /workspace \
"$PYTHON_IMAGE" \
python tools/validate_audit_matrix.py audit/findings.json \
| tee .ci-artifacts/audit-matrix.log
'''
}
}
stage('Python collection') {
steps {
sh '''
docker run --rm \
--user "$(id -u):$(id -g)" \
-e PYTHONDONTWRITEBYTECODE=1 -e HOME=/tmp \
-e JWT_SECRET \
-v "$HOST_WORKSPACE:/workspace" -w /workspace \
"$PYTHON_IMAGE" \
python -m pytest --collect-only -q -p no:cacheprovider \
-m "not slow and not requires_gpu and not requires_hf_token and not requires_model" \
> .ci-artifacts/python-collection.log
'''
}
}
stage('Python baseline tests') {
steps {
sh '''
docker run --rm \
--user "$(id -u):$(id -g)" \
-e PYTHONDONTWRITEBYTECODE=1 -e HOME=/tmp \
-e JWT_SECRET \
-v "$HOST_WORKSPACE:/workspace" -w /workspace \
"$PYTHON_IMAGE" \
python tools/verify_test_baseline.py \
--junit .ci-artifacts/python-tests.xml \
-p no:cacheprovider \
-m "not slow and not requires_gpu and not requires_hf_token and not requires_model"
'''
}
post {
always {
junit allowEmptyResults: true, skipMarkingBuildUnstable: true, testResults: '.ci-artifacts/python-tests.xml'
}
}
}
stage('Ruff (Task 1 scope)') {
steps {
sh '''
docker run --rm \
--user "$(id -u):$(id -g)" \
-e PYTHONDONTWRITEBYTECODE=1 -e HOME=/tmp \
-v "$HOST_WORKSPACE:/workspace" -w /workspace \
"$PYTHON_IMAGE" \
python -m ruff check \
tools/validate_audit_matrix.py \
tools/verify_test_baseline.py \
tests/test_audit_matrix.py \
tests/test_diarization.py \
| tee .ci-artifacts/ruff.log
'''
}
}
stage('Frontend baseline check and build') {
steps {
sh '''
# Unit tests (node:test) import .ts sources directly: needs a Node with type stripping
# and glob support (>= 22.18). node:20 cannot run them; no node_modules required.
rc=0
docker run --rm \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-v "$HOST_WORKSPACE/frontend:/app" -w /app \
node:24-slim \
node --test 'src/lib/**/*.test.ts' \
> .ci-artifacts/frontend-node-test.log 2>&1 || rc=$?
cat .ci-artifacts/frontend-node-test.log
test "$rc" -eq 0
docker run --rm \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e NPM_CONFIG_REGISTRY \
-v "$HOST_WORKSPACE/frontend:/app" -w /app \
node:20-slim \
sh -lc 'npm ci --cache /tmp/npm-cache && npx svelte-kit sync && ls -la .svelte-kit/tsconfig.json && npx svelte-check --tsconfig ./tsconfig.json --output machine' \
> .ci-artifacts/frontend-check.log || test "$?" -eq 1
docker run --rm \
--user "$(id -u):$(id -g)" \
-e PYTHONDONTWRITEBYTECODE=1 -e HOME=/tmp \
-v "$HOST_WORKSPACE:/workspace" -w /workspace \
"$PYTHON_IMAGE" \
python tools/verify_frontend_baseline.py .ci-artifacts/frontend-check.log
docker run --rm \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e NPM_CONFIG_REGISTRY \
-v "$HOST_WORKSPACE/frontend:/app" -w /app \
node:20-slim \
sh -lc 'npm run build && grep -rq "Скачать PNG" build/_app/immutable && grep -rq mindmap.png build/_app/immutable || { echo "FATAL: mindmap export UI missing from built bundle (see tests/test_frontend_export_guard.py)"; exit 1; }' \
| tee .ci-artifacts/frontend-build.log
'''
}
}
stage('Production Docker build') {
steps {
sh '''
NOCACHE_FLAG="$(cat .ci-artifacts/nocache-flag)"
docker build $NOCACHE_FLAG -t "$APP_IMAGE" .
'''
}
}
stage('GPU and model tests') {
when {
beforeAgent true
expression { params.RUN_MODEL_TESTS }
}
agent { label 'gpu && model-tests' }
steps {
deleteDir()
sh '''
set -eu
git clone --no-tags "$GIT_URL" .
git checkout --detach "$GIT_REF"
'''
withCredentials([string(credentialsId: 'dialogscribe-hf-token', variable: 'HF_TOKEN')]) {
sh '''
docker run --rm --gpus all \
-e HF_TOKEN \
-v "$WORKSPACE:/workspace" -w /workspace \
python:3.10-slim \
sh -lc 'pip install --no-cache-dir -r requirements.txt -r requirements.dev.txt >/dev/null && python -m pytest -q -m "requires_gpu or requires_hf_token or requires_model"'
'''
}
}
}
}
post {
always {
archiveArtifacts allowEmptyArchive: true, artifacts: '.ci-artifacts/**/*', fingerprint: true
sh 'docker image rm -f "$PYTHON_IMAGE" "$APP_IMAGE" >/dev/null 2>&1 || true'
deleteDir()
}
}
}