-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (39 loc) · 1.83 KB
/
auto_deploy.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
name: Deploy to Server
on:
push:
branches:
- prod # Запускать при пуше в ветку main
pull_request:
branches:
- prod
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Шаг 1: Клонируем репозиторий
- name: Checkout code
uses: actions/checkout@v3
# Шаг 2: Настройка SSH с использованием пароля
- name: Set up SSH with password
env:
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} # Пароль для SSH
SERVER_IP: ${{ secrets.SERVER_IP }} # IP-адрес сервера
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
# Устанавливаем sshpass для входа с паролем
sudo apt-get update && sudo apt-get install -y sshpass
# Шаг 3: Остановка docker-compose, выполнение rsync и запуск docker-compose
- name: Deploy to server
env:
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} # Пароль для SSH
SERVER_IP: ${{ secrets.SERVER_IP }} # IP-адрес сервера
run: |
# Остановка docker-compose
sshpass -p "$SSH_PASSWORD" ssh root@${{ secrets.SERVER_IP }} "cd /root/project && docker-compose down || true"
# Выполнение rsync
sshpass -p "$SSH_PASSWORD" rsync -avzu -e "ssh" . root@${{ secrets.SERVER_IP }}:/root/project
# Запуск docker-compose
sshpass -p "$SSH_PASSWORD" ssh root@${{ secrets.SERVER_IP }} "cd /root/project && docker-compose up -d --build"