-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (117 loc) · 4.14 KB
/
deploy_bot.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
120
121
name: Deploy new Bot
on:
workflow_dispatch:
env:
REPO_NAME: ${{ github.event.repository.name }}
jobs:
install-requirements:
runs-on: ubuntu-latest
steps:
- name: Installing requirements for ${{ env.REPO_NAME }}
uses: fifsky/ssh-action@master
with:
command: pip install aiohttp
pip install aiosignal
pip install async-timeout
pip install attrs
pip install certifi
pip install charset-normalizer
pip install discord.py
pip install frozenlist
pip install idna
pip install multidict
pip install Pillow
pip install python-dotenv
pip install requests
pip install urllib3
pip install yarl
host: 132.145.220.235
user: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
deploy-via-sftp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: SFTPDeploy
uses: wlixcc/SFTP-Deploy-Action@v1.2.1
with:
username: ubuntu
server: 132.145.220.235
port: 22
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
# clones entire github repo
local_path: ./*
# destination of the code on the server
remote_path: /home/ubuntu/${{ env.REPO_NAME }}/
args: "-o ConnectTimeout=5"
# you may or may not need this. It all depends on how your code retrieves your discord token
# environment variables or Github secrets are heavily recommended
add-bot-token:
needs: [deploy-via-sftp]
runs-on: ubuntu-latest
timeout-minutes: 2
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
steps:
- id: add-bot-token
uses: fifsky/ssh-action@master
with:
command: |
cd ${{ env.REPO_NAME }}
touch .env
echo "BOT_TOKEN=${{ env.BOT_TOKEN }}" > .env
echo "GUILD_ID=${{ env.GUILD_ID }}" >> .env
echo $?
host: 132.145.220.235
user: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
create-systemctl-service:
needs: [add-bot-token, deploy-via-sftp]
runs-on: ubuntu-latest
steps:
- id: creating-systemctl-service
uses: fifsky/ssh-action@master
with:
# Make sure ExecStart=, WorkingDirectory= and chmod +x point to the same directory. These may be unique to your code setup
command: |
echo "[Unit]
Description=${{ env.REPO_NAME }} Discord Bot
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/ubuntu/${{ env.REPO_NAME }}/app.py
User=ubuntu
Restart=on-failure
RestartSec=30
WorkingDirectory=/home/ubuntu/${{ env.REPO_NAME }}/
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/${{ env.REPO_NAME }}.service
chmod +x /home/ubuntu/${{ env.REPO_NAME }}/app.py
sudo systemctl enable ${{ env.REPO_NAME }}.service
sudo systemctl daemon-reload
sudo systemctl start ${{ env.REPO_NAME }}.service
host: 132.145.220.235
user: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
create-systemctl-restart:
needs: [create-systemctl-service, add-bot-token, deploy-via-sftp]
runs-on: ubuntu-latest
steps:
- id: create-systemctl-restart-service
uses: fifsky/ssh-action@master
with:
command: |
echo "[Unit]
Description=${{ env.REPO_NAME }} Discord Bot restart
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart ${{ env.REPO_NAME }}.service
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/${{ env.REPO_NAME }}-watcher.service
sudo systemctl enable ${{ env.REPO_NAME }}-watcher.service
sudo systemctl daemon-reload
sudo systemctl start ${{ env.REPO_NAME }}-watcher.service
host: 132.145.220.235
user: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}