añadida configuración inicial del bot
This commit is contained in:
109
.gitea/workflows/deploy-new.yml
Normal file
109
.gitea/workflows/deploy-new.yml
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
name: Deploy new Bot
|
||||||
|
on:
|
||||||
|
# allows the workflow to be run manually
|
||||||
|
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: https://github/fifsky/ssh-action@master
|
||||||
|
with:
|
||||||
|
# install the libraries required for your bot
|
||||||
|
command: |
|
||||||
|
pip install -r requirements.txt
|
||||||
|
host: localhost
|
||||||
|
user: root
|
||||||
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
deploy-via-sftp:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- id: SFTPDeploy
|
||||||
|
uses: https://github.com/wlixcc/SFTP-Deploy-Action@v1.2.1
|
||||||
|
with:
|
||||||
|
username: root
|
||||||
|
server: #127.0.0.1
|
||||||
|
port: 22
|
||||||
|
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
# clones entire github repo
|
||||||
|
local_path: ./*
|
||||||
|
# destination of the code on the server
|
||||||
|
remote_path: /root/${{ 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: https://github.com/fifsky/ssh-action@master
|
||||||
|
with:
|
||||||
|
command: |
|
||||||
|
cd ${{ env.REPO_NAME }}/lib/bot
|
||||||
|
touch token.0
|
||||||
|
echo ${{ env.BOT_TOKEN }} > token.0
|
||||||
|
echo $?
|
||||||
|
host: 127.0.0.1
|
||||||
|
user: root
|
||||||
|
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: https://github.com/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 /root/${{ env.REPO_NAME }}/main.py
|
||||||
|
User=root
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=30
|
||||||
|
WorkingDirectory=/root/${{ env.REPO_NAME }}/
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target" >> /etc/systemd/system/${{ env.REPO_NAME }}.service
|
||||||
|
chmod +x /root/${{ env.REPO_NAME }}/main.py
|
||||||
|
sudo systemctl enable ${{ env.REPO_NAME }}.service
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl start ${{ env.REPO_NAME }}.service
|
||||||
|
host: 127.0.0.1
|
||||||
|
user: root
|
||||||
|
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: https://github.com/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: 127.0.0.1
|
||||||
|
user: root
|
||||||
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
Reference in New Issue
Block a user