-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (119 loc) · 3.33 KB
/
ci.yml
File metadata and controls
127 lines (119 loc) · 3.33 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
name: CI
on:
push:
branches: ["main", "develop"]
pull_request:
branches: ["main"]
env:
PYTHON_VERSION: "3.12"
IMAGE_NAME: devops-platform
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
cache-dependency-path: app/requirements.txt
- run: pip install flake8
- run: flake8 app/ --max-line-length=100 --exclude=app/tests,app/migrations
test:
name: Test
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
cache-dependency-path: app/requirements.txt
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r app/requirements.txt
pip install aiosqlite
- name: Run tests
run: |
pip install pytest-cov
pytest app/tests/ -v --cov=app --cov-report=xml --cov-report=term-missing
- uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false
security:
name: Security Scan
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v4
- uses: aquasecurity/trivy-action@master
with:
scan-type: "fs"
scan-ref: "./app"
severity: "CRITICAL,HIGH"
exit-code: "1"
ignore-unfixed: true
build:
name: Build & Push Image
runs-on: ubuntu-latest
needs: [test, security]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=sha-
type=raw,value=latest,enable=true
- uses: docker/build-push-action@v5
with:
context: ./app
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
load-test:
name: Load Test
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Start services
run: |
docker compose up -d --build
sleep 30
- name: Wait for app
run: |
for i in {1..10}; do
curl -sf http://localhost:8000/health && break
sleep 5
done
- name: Run k6 load test
uses: grafana/k6-action@v0.3.1
with:
filename: load-tests/smoke.js
env:
env:
BASE_URL: http://172.17.0.1:8000
- name: Stop services
if: always()
run: docker compose down -v