-
Notifications
You must be signed in to change notification settings - Fork 8
341 lines (279 loc) · 10.4 KB
/
stable-build.yml
File metadata and controls
341 lines (279 loc) · 10.4 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
name: Stable Build and Test
on:
push:
branches: [ main, develop ]
paths:
- 'docker/**'
- 'requirements*.txt'
- '.python-version'
- 'docker-compose*.yml'
pull_request:
branches: [ main ]
paths:
- 'docker/**'
- 'requirements*.txt'
- '.python-version'
- 'docker-compose*.yml'
workflow_dispatch:
inputs:
python_version:
description: 'Python version to test'
required: false
default: '3.12.7'
type: string
env:
PYTHON_VERSION: ${{ github.event.inputs.python_version || '3.12.7' }}
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
jobs:
validate-python-version:
name: Validate Python Version Consistency
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check Python version pinning
run: |
echo "Checking Python version consistency..."
# Check .python-version file
if [ -f ".python-version" ]; then
PINNED_VERSION=$(cat .python-version)
echo "Pinned Python version: $PINNED_VERSION"
if [ "$PINNED_VERSION" != "$PYTHON_VERSION" ]; then
echo "❌ Python version mismatch!"
echo "Pinned: $PINNED_VERSION"
echo "Target: $PYTHON_VERSION"
exit 1
fi
else
echo "⚠️ .python-version file not found"
fi
# Check Dockerfiles for consistency
echo "Checking Dockerfiles for Python version references..."
# This ensures all Dockerfiles use ARG for Python version
if grep -r "python:3\." docker/ | grep -v "ARG\|${PYTHON_VERSION}"; then
echo "❌ Found hardcoded Python versions in Dockerfiles"
exit 1
fi
echo "✅ Python version consistency validated"
build-matrix:
name: Build Test Matrix
runs-on: ubuntu-latest
needs: validate-python-version
strategy:
matrix:
component: [api, worker-cpu, worker-gpu]
include:
- component: api
dockerfile: docker/api/Dockerfile.new
build_args: "PYTHON_VERSION=${{ env.PYTHON_VERSION }}"
- component: worker-cpu
dockerfile: docker/worker/Dockerfile
build_args: "PYTHON_VERSION=${{ env.PYTHON_VERSION }}\nWORKER_TYPE=cpu"
- component: worker-gpu
dockerfile: docker/worker/Dockerfile
build_args: "PYTHON_VERSION=${{ env.PYTHON_VERSION }}\nWORKER_TYPE=gpu"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build ${{ matrix.component }}
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
build-args: ${{ matrix.build_args }}
tags: rendiff-${{ matrix.component }}:test
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test ${{ matrix.component }} dependencies
run: |
echo "Testing critical dependencies in ${{ matrix.component }}..."
# Test psycopg2-binary (the main fix)
docker run --rm rendiff-${{ matrix.component }}:test python -c "
import psycopg2
print(f'✅ psycopg2-binary: {psycopg2.__version__}')
"
# Test other critical dependencies
if [ "${{ matrix.component }}" = "api" ]; then
docker run --rm rendiff-${{ matrix.component }}:test python -c "
import fastapi, sqlalchemy, asyncpg
print(f'✅ FastAPI: {fastapi.__version__}')
print(f'✅ SQLAlchemy: {sqlalchemy.__version__}')
print(f'✅ asyncpg: {asyncpg.__version__}')
"
fi
if [[ "${{ matrix.component }}" == worker* ]]; then
docker run --rm rendiff-${{ matrix.component }}:test python -c "
import celery, redis
print(f'✅ Celery: {celery.__version__}')
print(f'✅ Redis: {redis.__version__}')
"
fi
echo "✅ All dependencies verified for ${{ matrix.component }}"
test-ffmpeg:
name: Test FFmpeg Installation
runs-on: ubuntu-latest
needs: build-matrix
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build API container
uses: docker/build-push-action@v5
with:
context: .
file: docker/api/Dockerfile.new
build-args: "PYTHON_VERSION=${{ env.PYTHON_VERSION }}"
tags: rendiff-api:ffmpeg-test
load: true
- name: Test FFmpeg functionality
run: |
echo "Testing FFmpeg installation and basic functionality..."
# Test FFmpeg version
docker run --rm rendiff-api:ffmpeg-test ffmpeg -version | head -1
# Test FFmpeg basic functionality with a simple command
docker run --rm rendiff-api:ffmpeg-test ffmpeg -f lavfi -i testsrc=duration=1:size=320x240:rate=1 -t 1 test.mp4
echo "✅ FFmpeg installation and basic functionality verified"
integration-test:
name: Integration Test
runs-on: ubuntu-latest
needs: [build-matrix, test-ffmpeg]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create test environment
run: |
# Create minimal test environment
cat > test.env << EOF
DATABASE_URL=sqlite:///test.db
REDIS_URL=redis://redis:6379
ENABLE_API_KEYS=false
LOG_LEVEL=INFO
EOF
- name: Test with Docker Compose
run: |
# Use stable compose configuration
docker-compose -f docker-compose.yml -f docker-compose.stable.yml build
# Start services
docker-compose -f docker-compose.yml -f docker-compose.stable.yml up -d
# Wait for services to be ready
sleep 30
# Test API health endpoint
curl -f http://localhost:8000/api/v1/health || exit 1
echo "✅ Integration test passed"
- name: Cleanup
if: always()
run: |
docker-compose -f docker-compose.yml -f docker-compose.stable.yml down -v || true
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: build-matrix
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build API for scanning
uses: docker/build-push-action@v5
with:
context: .
file: docker/api/Dockerfile.new
build-args: "PYTHON_VERSION=${{ env.PYTHON_VERSION }}"
tags: rendiff-api:security-scan
load: true
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'rendiff-api:security-scan'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
dependency-check:
name: Dependency Vulnerability Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install safety
run: pip install safety
- name: Check dependencies with safety
run: |
# Check main requirements
safety check -r requirements.txt
# Check stable requirements if exists
if [ -f "docker/requirements-stable.txt" ]; then
safety check -r docker/requirements-stable.txt
fi
generate-report:
name: Generate Build Report
runs-on: ubuntu-latest
needs: [validate-python-version, build-matrix, test-ffmpeg, integration-test, security-scan, dependency-check]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate build report
run: |
cat > build-report.md << EOF
# Stable Build Report
**Date**: $(date)
**Python Version**: ${{ env.PYTHON_VERSION }}
**Commit**: ${{ github.sha }}
**Branch**: ${{ github.ref_name }}
## Build Results
| Component | Status |
|-----------|---------|
| Python Version Validation | ${{ needs.validate-python-version.result }} |
| API Build | ${{ needs.build-matrix.result }} |
| Worker CPU Build | ${{ needs.build-matrix.result }} |
| Worker GPU Build | ${{ needs.build-matrix.result }} |
| FFmpeg Test | ${{ needs.test-ffmpeg.result }} |
| Integration Test | ${{ needs.integration-test.result }} |
| Security Scan | ${{ needs.security-scan.result }} |
| Dependency Check | ${{ needs.dependency-check.result }} |
## Key Improvements
- ✅ Fixed psycopg2-binary compilation issue
- ✅ Standardized Python version across all containers
- ✅ Added comprehensive build dependencies
- ✅ Implemented proper runtime-only final stages
- ✅ Added dependency vulnerability scanning
- ✅ Created integration testing pipeline
## Recommendations
1. Use Python ${{ env.PYTHON_VERSION }} for all deployments
2. Monitor dependency vulnerabilities regularly
3. Keep FFmpeg updated for security patches
4. Implement automated deployment with these validated images
EOF
echo "Build report generated"
- name: Upload build report
uses: actions/upload-artifact@v3
with:
name: build-report
path: build-report.md
notify-status:
name: Notify Build Status
runs-on: ubuntu-latest
needs: [validate-python-version, build-matrix, test-ffmpeg, integration-test, security-scan, dependency-check]
if: always()
steps:
- name: Build status notification
run: |
if [ "${{ needs.build-matrix.result }}" = "success" ] && \
[ "${{ needs.integration-test.result }}" = "success" ]; then
echo "🎉 Stable build successful! Ready for deployment."
echo "BUILD_STATUS=success" >> $GITHUB_ENV
else
echo "❌ Build failed. Check the logs for details."
echo "BUILD_STATUS=failure" >> $GITHUB_ENV
fi