-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (79 loc) · 2.95 KB
/
ci_cd.yml
File metadata and controls
94 lines (79 loc) · 2.95 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
name: CI/CD Pipeline
on:
push:
branches: ["main", "development"]
pull_request:
branches: ["main", "development"]
jobs:
tests:
name: Run Tests
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up virtual environment
run: |
python3 -m venv .venv
.venv/bin/pip install --upgrade pip
.venv/bin/pip install -r requirements.txt
- name: Run Pytest
env:
SECRET_KEY: "test_secret_key"
ALGORITHM: "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: 30
REFRESH_TOKEN_EXPIRE_MINUTES: 60
EMAIL_VERIFICATION_CODE_EXPIRE_MINUTES: 10
RESET_TOKEN_EXPIRE_MINUTES: 30
NUMBER_OF_BYTES_FOR_RESET_TOKEN_GENERATION: 32
RESEND_API_KEY: "re_test_key"
EMAIL_SENDER: "test@example.com"
S3_ACCESS_KEY: "test"
S3_SECRET_KEY: "test"
DATABASE_URL: "sqlite+aiosqlite:///:memory:"
run: |
.venv/bin/pytest -v
build-and-push:
name: Build Docker Image
needs: tests
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/documents-exp-api:latest
deploy:
name: Deploy to Server
needs: build-and-push
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Copy .env
run: cp ~/.env.documents-exp .env
- name: Deploy
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
run: |
docker compose stop api
docker compose rm -f api
docker rmi $DOCKER_USERNAME/documents-exp-api:latest || true
docker pull $DOCKER_USERNAME/documents-exp-api:latest
docker compose up -d api
docker image prune -f
- name: Run migrations
run: |
sleep 5
docker exec documents_api alembic upgrade head