-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (64 loc) · 2.22 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
name: Build & Deploy
on:
push:
branches: [ main ]
jobs:
build:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Zip
run: |
touch build.tar.gz
tar --exclude='./.git' --exclude='./.github' --exclude='./Old' --exclude=./*.gz -zcf build.tar.gz -C ./ .
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: build
path: ./build.tar.gz
deploy:
needs: build
runs-on: ubuntu-latest
env:
SSH_USER: github
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: 194.36.146.51
REPO_NAME: ${{ github.event.repository.name }}
steps:
- name: Download build
uses: actions/download-artifact@v4
with:
name: build
- name: Install ssh key
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/staging.key
chmod 600 ~/.ssh/staging.key
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
- name: Configure SSH
run: |
cat >>~/.ssh/config <<END
Host staging
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/staging.key
StrictHostKeyChecking no
END
- name: Check SSH Connection
run: ssh staging 'echo "It works!"'
- name: Delete previous deploy files
run: ssh staging "sudo rm -r /home/$SSH_USER/$REPO_NAME/*"
continue-on-error: true
- name: Deploy build
run: rsync -avz -e 'ssh -i ~/.ssh/staging.key -o StrictHostKeyChecking=no' --progress ./build.tar.gz $SSH_USER@$SSH_HOST:/home/$SSH_USER/$REPO_NAME
- name: Unzip
run: ssh staging "cd /home/$SSH_USER/$REPO_NAME/ && sudo tar --no-same-owner --no-same-permissions -xf build.tar.gz"
- name: Delete build zip
run: ssh staging "cd /home/$SSH_USER/$REPO_NAME/ && sudo rm build.tar.gz"
- name: Delete current deployed files
run: ssh staging 'sudo rm -r -d /var/www/netdb'
continue-on-error: true
- name: Copy files
run: ssh staging "sudo rsync -av --ignore-existing /home/$SSH_USER/$REPO_NAME/ /var/www/netdb"