-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (113 loc) · 3.95 KB
/
main.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
name: Urban Utopia 2024 (backend)
on:
push:
branches:
- main
jobs:
# backend_tests:
# name: Run tests for backend
# runs-on: ubuntu-latest
# services:
# postgres:
# image: postgres:13.10
# 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
# strategy:
# matrix:
# python-version: ["3.9", "3.10", "3.11"]
# steps:
# - name: Clone project to runner
# uses: actions/checkout@v3
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install dependencies
# run: |
# cd backend &&
# python -m pip install --upgrade pip &&
# pip install -r requirements.txt
# - name: Run flake8 tests
# run: |
# cd backend &&
# python -m flake8
# - name: Run Pytest
# run: |
# cd backend &&
# cp .env.example .env &&
# python manage.py makemigrations &&
# pytest
build_and_push_backend_and_gateway_image:
name: Build backend and gateway images and push to the DockerHub
# needs:
# - backend_tests
runs-on: ubuntu-latest
steps:
- name: Clone project to runner
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push backend image to the Dockerhub
uses: docker/build-push-action@v4
with:
context: ./backend/
push: True
tags: ${{ secrets.DOCKERHUB_USERNAME }}/urban_utopia_2024_backend:latest
- name: Push gateway image to the Dockerhub
uses: docker/build-push-action@v4
with:
context: ./gateway/
push: True
tags: ${{ secrets.DOCKERHUB_USERNAME }}/urban_utopia_2024_gateway:latest
deploy_on_server:
name: Deploy project on server
needs: build_and_push_backend_and_gateway_image
runs-on: ubuntu-latest
steps:
- name: Clone project to runner
uses: actions/checkout@v3
- name: Copy docker-compose.production.yml to server via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: "docker-compose.production.yml"
target: "/home/urban_utopia_2024/"
- name: Executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /home/urban_utopia_2024
sudo docker compose down
sudo rm docker-compose.yml
sudo mv docker-compose.production.yml docker-compose.yml
sudo docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/urban_utopia_2024_backend
sudo docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/urban_utopia_2024_gateway
sudo docker volume rm urban_utopia_2024_urban_utopia_2024_static_volume
sudo docker compose up -d --build
sudo service nginx restart
send_message_telegram:
name: Send message to telegram
needs: deploy_on_server
runs-on: ubuntu-latest
steps:
- name: Send message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_ME_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: ✅ Деплой "Urban Utopia 2024 (backend)" выполнен успешно!