-
Notifications
You must be signed in to change notification settings - Fork 3
358 lines (310 loc) · 12.1 KB
/
Copy pathdocker.yml
File metadata and controls
358 lines (310 loc) · 12.1 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
name: Build & Publish Docker
# ─────────────────────────────────────────────────────────────────
# COMMIT MESSAGE CONVENTIONS
#
# fix: ... → patch (v1.2.3 → v1.2.4)
# feat: ... → minor (v1.2.3 → v1.3.0)
# feat!: ... → major (v1.2.3 → v2.0.0)
# refactor: ... → patch
# chore: ... → patch
# docs: ... → patch
# (anything else) → patch
#
# Non-main branches → pushed as STG + <branch>-<sha>
# (no version tag created)
# ─────────────────────────────────────────────────────────────────
on:
push:
branches:
- "**"
permissions:
contents: write
security-events: write
jobs:
# ─────────────────────────────────────────────
# 1. SECURITY SCAN (runs in parallel with test)
# ─────────────────────────────────────────────
scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Run Trivy filesystem scan
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: fs
scan-ref: .
severity: CRITICAL,HIGH
exit-code: 1
skip-dirs: e2e/node_modules
# ─────────────────────────────────────────────
# 2. UNIT TESTS (runs in parallel with scan)
# ─────────────────────────────────────────────
test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.11"
- name: Cache pip
uses: actions/cache@v6
with:
path: ~/.cache/pip
key: pip-${{ hashFiles('requirements.txt') }}
restore-keys: pip-
- name: Install dependencies
run: |
pip install pytest pyyaml apscheduler defusedxml fastapi httpx requests
- name: Run tests
run: pytest --tb=short -v
# ─────────────────────────────────────────────
# 3. E2E TESTS (Playwright)
# ─────────────────────────────────────────────
e2e:
name: E2E Tests (Playwright)
needs: [scan, test]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build image for e2e (linux/amd64, load locally)
uses: docker/build-push-action@v7
with:
context: .
push: false
load: true
platforms: linux/amd64
build-args: VERSION=e2e
tags: cineplete:e2e
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Start app container
run: |
mkdir -p /tmp/cineplete-data /tmp/cineplete-config
sudo chown 1000:1000 /tmp/cineplete-data /tmp/cineplete-config
docker run -d \
--name cineplete-e2e \
-p 8787:8787 \
-v /tmp/cineplete-data:/data \
-v /tmp/cineplete-config:/config \
cineplete:e2e
- name: Wait for app to be ready
run: |
echo "Waiting for app..."
for i in $(seq 1 30); do
if curl -sf http://localhost:8787/api/version > /dev/null 2>&1; then
echo "App is up after ${i}s"
exit 0
fi
sleep 1
done
echo "App failed to start" && docker logs cineplete-e2e && exit 1
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: e2e/package-lock.json
- name: Install npm deps
working-directory: e2e
run: npm ci
- name: Cache Playwright browsers
id: pw-cache
uses: actions/cache@v6
with:
path: ~/.cache/ms-playwright
key: playwright-chromium-${{ hashFiles('e2e/package-lock.json') }}
- name: Install Playwright browsers
working-directory: e2e
if: steps.pw-cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps chromium
- name: Install Playwright system deps only (cache hit)
working-directory: e2e
if: steps.pw-cache.outputs.cache-hit == 'true'
run: npx playwright install-deps chromium
- name: Run Playwright tests
working-directory: e2e
env:
BASE_URL: http://localhost:8787
run: npx playwright test
- name: Upload Playwright report on failure
if: failure()
uses: actions/upload-artifact@v7
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 7
- name: Stop app container
if: always()
run: docker stop cineplete-e2e && docker rm cineplete-e2e
# ─────────────────────────────────────────────
# 4. COMPUTE VERSION
# ─────────────────────────────────────────────
version:
name: Compute Version
needs: e2e
runs-on: ubuntu-latest
outputs:
version: ${{ steps.resolve.outputs.version }}
is_main: ${{ steps.ctx.outputs.is_main }}
steps:
- name: Checkout (full history for tags)
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect branch context
id: ctx
run: |
IS_MAIN=$( [ "${{ github.ref }}" = "refs/heads/main" ] && echo "true" || echo "false" )
echo "is_main=$IS_MAIN" >> $GITHUB_OUTPUT
# ── Main: parse commit message → bump type ──
- name: Parse commit message
id: parse
if: steps.ctx.outputs.is_main == 'true'
run: |
MSG=$(git log -1 --pretty=%s)
echo "Commit message: $MSG"
# feat!: or fix!: or anything with ! before : → major
if echo "$MSG" | grep -qE '^[a-z]+!:'; then
echo "bump=major" >> $GITHUB_OUTPUT
# feat: → minor
elif echo "$MSG" | grep -qE '^feat(\(.+\))?:'; then
echo "bump=minor" >> $GITHUB_OUTPUT
# fix/refactor/chore/docs/style/test/ci/perf/build/anything else → patch
else
echo "bump=patch" >> $GITHUB_OUTPUT
fi
# ── Main: compute new vX.Y.Z tag ──
- name: Bump version
id: bump
if: steps.ctx.outputs.is_main == 'true'
run: |
BUMP="${{ steps.parse.outputs.bump }}"
LATEST=$(git tag --list 'v*.*.*' | sort -V | tail -1)
[ -z "$LATEST" ] && LATEST="v0.0.0"
echo "Latest tag: $LATEST | Bump: $BUMP"
VER="${LATEST#v}"
MAJOR=$(echo "$VER" | cut -d. -f1)
MINOR=$(echo "$VER" | cut -d. -f2)
PATCH=$(echo "$VER" | cut -d. -f3)
case "$BUMP" in
major) MAJOR=$((MAJOR+1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR+1)); PATCH=0 ;;
patch) PATCH=$((PATCH+1)) ;;
esac
NEW="v${MAJOR}.${MINOR}.${PATCH}"
echo "New version: $NEW"
echo "version=$NEW" >> $GITHUB_OUTPUT
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$NEW"
git push origin "$NEW"
# ── Non-main: branch-sha label (no tag created) ──
- name: STG version label
id: stg
if: steps.ctx.outputs.is_main == 'false'
run: |
SHA=$(git rev-parse --short HEAD)
BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/-/g')
echo "version=${BRANCH}-${SHA}" >> $GITHUB_OUTPUT
- name: Resolve final version
id: resolve
run: |
if [ "${{ steps.ctx.outputs.is_main }}" = "true" ]; then
echo "version=${{ steps.bump.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${{ steps.stg.outputs.version }}" >> $GITHUB_OUTPUT
fi
# ─────────────────────────────────────────────
# 4. BUILD & PUSH
# ─────────────────────────────────────────────
build:
name: Build & Push Docker
needs: version
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# ── Main → latest + vX.Y.Z ──
- name: Build & Push (main)
if: needs.version.outputs.is_main == 'true'
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ needs.version.outputs.version }}
tags: |
sdblepas/cineplete:latest
sdblepas/cineplete:${{ needs.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ── Non-main → STG + branch-sha (amd64 only — arm64 emulation is slow) ──
- name: Build & Push (STG)
if: needs.version.outputs.is_main == 'false'
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
build-args: VERSION=${{ needs.version.outputs.version }}
tags: |
sdblepas/cineplete:STG
sdblepas/cineplete:${{ needs.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ─────────────────────────────────────────────
# 5. INSTALL SCRIPT SMOKE TEST (non-blocking)
# ─────────────────────────────────────────────
install-smoke:
name: Install Script Smoke Test
needs: version
if: needs.version.outputs.is_main == 'true' && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Run install script (no systemd)
env:
SKIP_SYSTEMD: "1"
run: sudo -E bash install/install.sh
- name: Overwrite release with current checkout
run: |
sudo rsync -a --exclude='.venv' --exclude='__pycache__' \
./ /opt/cineplete/
sudo chown -R cineplete:cineplete /opt/cineplete
- name: Start app manually
run: |
sudo -u cineplete bash -c '
cd /opt/cineplete
nohup /opt/cineplete/.venv/bin/uvicorn app.web:app \
--host 127.0.0.1 \
--port 7474 \
>/tmp/cineplete.log 2>&1 &
'
- name: Wait for app
run: |
for i in {1..30}; do
if curl -fs http://127.0.0.1:7474/api/version >/dev/null; then
exit 0
fi
sleep 2
done
cat /tmp/cineplete.log || true
exit 1