-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (112 loc) · 3.6 KB
/
drf_ci.yml
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
name: DRF CI/CD Pipeline
#on: [push, pull_request]
on: [ push ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run Flake8
run: flake8 .
test:
runs-on: ubuntu-latest
needs: lint
services:
db:
image: postgres:16-alpine
env:
POSTGRES_HOST: localhost
POSTGRES_DB: test_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: some_password
ports:
- 5432:5432
# Если требуется, вы можете настроить ожидание
# чтобы PostgreSQL был доступен перед запуском миграций
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.12' # Замените на вашу версию Python
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
echo "$POSTGRES_USER"
- name: Run migrations
env:
SECRET_KEY: gxt&zs7&=dm(5umk20(t93a9=##j_*$vi47q!1abrmfr+iu)*$
POSTGRES_HOST: localhost
POSTGRES_DB: test_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: some_password
run:
python3 manage.py migrate
- name: Run test
env:
SECRET_KEY: gxt&zs7&=dm(5umk20(t93a9=##j_*$vi47q!1abrmfr+iu)*$
POSTGRES_HOST: localhost
POSTGRES_DB: test_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: some_password
run:
python3 manage.py test -v3
deploy:
runs-on: ubuntu-latest
needs: test
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Run bash script via ssh
env:
SOME_DIR: ${{ secrets.SOME_DIR }}
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} "ls $SOME_DIR"
- name: Copy project files to server
run: |
rsync -avz --exclude '__pycache__' --exclude '.git' . ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:${{ secrets.DEPLOY_DIR }}
- name: Build image ,pull,push ,up
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} << 'EOF'
cd ${{ secrets.DEPLOY_DIR }}
docker compose down --rmi local || true
docker compose build
docker compose up -d
EOF
# build:
# needs: test
# runs-on: ubuntu-latest
#
# steps:
# - name: Check out code
# uses: actions/checkout@v3
#
# - name: Log in to Docker Hub
# run: echo ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
#
# - name: Build Docker image
# run: docker compose -f docker-compose.github.yml build
#
# - name: Push Docker image to Docker Hub
# run: docker compose -f docker-compose.github.yml push