Skip to content

Commit 39bcba9

Browse files
author
LINESKL
committed
Merge branch 'master' of https://github.com/LINESKL/FastAPI
2 parents 86bdeeb + c0f2891 commit 39bcba9

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
services:
13+
postgres:
14+
image: postgres:16-alpine
15+
env:
16+
POSTGRES_USER: lineskin
17+
POSTGRES_PASSWORD: altel8708
18+
POSTGRES_DB: lineskin
19+
ports:
20+
- 5432:5432
21+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
22+
redis:
23+
image: redis:7-alpine
24+
ports:
25+
- 6379:6379
26+
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Python 3.11
33+
uses: actions/setup-python@v4
34+
with:
35+
python-version: '3.11'
36+
37+
- name: Install dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install -r requirements.txt
41+
pip install pytest pytest-asyncio pytest-cov
42+
43+
- name: Run tests
44+
env:
45+
DATABASE_URL: postgresql+asyncpg://lineskin:altel8708@localhost:5432/lineskin
46+
REDIS_URL: redis://localhost:6379/0
47+
SECRET_KEY: test-secret-key-1234567890
48+
run: |
49+
pytest -v --cov=./ --cov-report=xml
50+
51+
- name: Upload coverage to Codecov
52+
uses: codecov/codecov-action@v3
53+
if: always()
54+
55+
- name: Build Docker image
56+
run: |
57+
docker build -t fastapi-app .
58+
59+
- name: Login to Docker Hub
60+
if: github.ref == 'refs/heads/main'
61+
uses: docker/login-action@v2
62+
with:
63+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
64+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
65+
66+
- name: Push to Docker Hub
67+
if: github.ref == 'refs/heads/main'
68+
run: |
69+
docker tag fastapi-app ${{ secrets.DOCKER_HUB_USERNAME }}/fastapi-app:latest
70+
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/fastapi-app:latest
71+

0 commit comments

Comments
 (0)