-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (43 loc) · 1.45 KB
/
DEV_deploy.yml
File metadata and controls
52 lines (43 loc) · 1.45 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
name: Deploy in DEV phase
on:
push:
branches:
- DEV/**
jobs:
deploy:
environment: DEV
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install SSH Client and Rsync
run: |
sudo apt-get update
sudo apt-get install -y ssh-client rsync
- name: Deploy, build and run Docker
env:
DEPLOY_SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_PORT: ${{ secrets.SERVER_PORT }}
SERVER_USER: ${{ secrets.SERVER_USER }}
DEPLOY_PATH: ${{ vars.PATH }}
run: |
# Write the SSH key to a file
echo "$DEPLOY_SSH_KEY" > deploy_key
chmod 600 deploy_key
# Create path if it does not exist
ssh -i deploy_key -p $SERVER_PORT -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "
mkdir -p $DEPLOY_PATH "
# Use rsync to deploy the code to the server
rsync \
-avz -e \
"ssh -i deploy_key -p $SERVER_PORT -o StrictHostKeyChecking=no" \
--exclude '.git' --exclude 'deploy_key' \
./ $SERVER_USER@$SERVER_IP:$DEPLOY_PATH
# Execute the Python script on the server
ssh -i deploy_key -p $SERVER_PORT -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "
cd $DEPLOY_PATH &&
docker compose down &&
docker compose up -d --build "
# Cleanup
rm -f deploy_key