Repository navigation
98 lines (84 loc) · 2.81 KB
/
Copy pathmain.yml
File metadata and controls
98 lines (84 loc) · 2.81 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
name: CI/CD Pipeline
on:
push:
branches: ["master", "dev"]
jobs:
build_job:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
POSTGRES_DB: test_db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Installing dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create .env.test file
run: |
echo "TEST_DATABASE_URL=postgresql+asyncpg://test_user:test_password@localhost:5432/test_db" >> .env.test
echo "TEST_REDIS_URL=redis://localhost:6379/0" >> .env.test
- name: Check production with linters
run: |
isort --check .
black --check .
flake8 .
- name: Check production with pytest
env:
DATABASE_URL: "postgresql+asyncpg://test_user:test_password@localhost:5432/test_db"
REDIS_URL: "redis://:test_password@localhost:6379/1"
run: pytest
deploy_job:
needs: build_job
runs-on: self-hosted
environment: Production
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create .env file
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
REDIS_DB: ${{ secrets.REDIS_DB }}
REDIS_URL: ${{ secrets.REDIS_URL }}
DOMAIN: ${{ secrets.DOMAIN }}
run: |
touch .env
echo "POSTGRES_USER=$POSTGRES_USER" >> .env
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> .env
echo "POSTGRES_DB=$POSTGRES_DB" >> .env
echo "DATABASE_URL=$DATABASE_URL" >> .env
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> .env
echo "REDIS_DB=$REDIS_DB" >> .env
echo "REDIS_URL=$REDIS_URL" >> .env
echo "DOMAIN=$DOMAIN" >> .env
- name: Stops all containers
run: docker compose -f docker-compose.yml --profile prod down
- name: Build docker compose
run: docker compose -f docker-compose.yml --profile prod up --build -d
- name: Wait for loading database
run: sleep 10
- name: Cleanup workspace
if: always()
run: rm -rf .env