forked from paulinevos/raffle-server
-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (68 loc) · 2.95 KB
/
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
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
name: Deploy
on:
push:
branches:
- main
jobs:
deployment:
runs-on: ubuntu-latest
environment: Production
steps:
- name: Get current time for Folder
uses: josStorer/[email protected]
id: current-time
with:
format: YYYYMMDDHHMMSS
- name: Get current time for Cleanup
uses: josStorer/[email protected]
id: current-time-cleanup
with:
format: YYYYMM
- uses: actions/checkout@v4
- uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
- uses: "ramsey/composer-install@v2"
- name: Publish to Server
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
ARGS: "-rltgoDzvO --delete"
SOURCE: "./"
REMOTE_HOST: ${{ secrets.DEPLOY_HOST }}
REMOTE_USER: ${{ secrets.DEPLOY_USER }}
TARGET: ${{ secrets.DEPLOY_RELEASES_FOLDER }}/${{ steps.current-time.outputs.formattedTime }}
- name: Deploy on Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
key: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
username: ${{ secrets.DEPLOY_USER }}
script: |
sed -i 's/RAFFLE_SERVER_HOST_KEY/${{ secrets.RAFFLE_SERVER_HOST_KEY }}/g' ${{ secrets.DEPLOY_RELEASES_FOLDER }}/${{ steps.current-time.outputs.formattedTime }}/server/raffle-server.service
sed -i 's/RAFFLE_SERVER_PORT/${{ secrets.RAFFLE_SERVER_PORT }}/g' ${{ secrets.DEPLOY_RELEASES_FOLDER }}/${{ steps.current-time.outputs.formattedTime }}/server/raffle-server.service
rm -Rf ${{ secrets.DEPLOY_CURRENT_PATH }}
ln -sf ${{ secrets.DEPLOY_RELEASES_FOLDER }}/${{ steps.current-time.outputs.formattedTime }} ${{ secrets.DEPLOY_CURRENT_PATH }}
rm -Rf /etc/systemd/system/raffle-server.service
cp -f ${{ secrets.DEPLOY_RELEASES_FOLDER }}/${{ steps.current-time.outputs.formattedTime }}/server/raffle-server.service /etc/systemd/system/raffle-server.service
systemctl daemon-reload
service raffle-server restart
- name: Validate Host Conf
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
key: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
username: ${{ secrets.DEPLOY_USER }}
script: |
rm -Rf /etc/nginx/sites-enabled/raffle-server
ln -sf ${{ secrets.DEPLOY_CURRENT_PATH }}/server/raffle-server.nginx /etc/nginx/sites-enabled/raffle-server
service nginx reload
- name: Server Cleanup
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
key: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
username: ${{ secrets.DEPLOY_USER }}
script: |
cd ${{ secrets.DEPLOY_RELEASES_FOLDER }}
find . -maxdepth 1 -mindepth 1 -type d -a ! -regex '.*${{ steps.current-time-cleanup.outputs.formattedTime }}.*' -exec rm -Rf {} \+