Deploy new Bot #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |