diff --git a/.gitea/workflows/deploy-new.yml b/.gitea/workflows/deploy-new.yml new file mode 100644 index 0000000..8929f11 --- /dev/null +++ b/.gitea/workflows/deploy-new.yml @@ -0,0 +1,114 @@ +name: Deploy new Bot +on: + # allows the workflow to be run manually + workflow_dispatch: +env: + REPO_NAME: focabot +jobs: + install-requirements: + runs-on: ubuntu-latest + steps: + - name: Installing requirements for ${{ env.REPO_NAME }} + uses: https://github.com/fifsky/ssh-action@master + with: + # install the libraries required for your bot + command: | + pip install -r requirements.txt + sudo apt install sshpass + host: 172.17.0.1 + user: binlab + pass: ${{ secrets.KEY }} + args: '-vvv' + + + deploy-via-sftp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@latest + with: + github-server-url: 'http://20.251.208.74:3000' + - id: SFTPDeploy + uses: https://github.com/wlixcc/SFTP-Deploy-Action@v1.2.4 + with: + username: binlab + server: 172.17.0.1 + port: 22 + # clones entire github repo + local_path: ./* + # destination of the code on the server + remote_path: /home/admin/${{ env.REPO_NAME }}/ + password: ${{ secrets.KEY }} + ssh_private_key: ignored + + # 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: 172.17.0.1 + user: binlab + pass: ${{ 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 /home/admin/${{ env.REPO_NAME }}/main.py + User=root + Restart=on-failure + RestartSec=30 + WorkingDirectory=/home/admin/${{ 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: 172.17.0.1 + user: binlab + 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: 172.17.0.1 + user: binlab + key: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/.gitea/workflows/update-bot.yml b/.gitea/workflows/update-bot.yml new file mode 100644 index 0000000..72a2f6b --- /dev/null +++ b/.gitea/workflows/update-bot.yml @@ -0,0 +1,33 @@ +name: Update Bot +on: + push: + branches: [ main ] + workflow_dispatch: +env: + REPO_NAME: focabot +jobs: + deploy-via-sftp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: SFTP Deploy + uses: https://github.com/wlixcc/SFTP-Deploy-Action@v1.2.4 + with: + username: root + server: 172.17.0.1 + port: 22 + local_path: ./* + remote_path: /home/admin/${{ env.REPO_NAME }}/ + password: ${{ secrets.SSH_PASS }} + + restart-bot: + needs: [deploy-via-sftp] + runs-on: ubuntu-latest + steps: + - id: creating-systemctl-service + uses: https://github.com/fifsky/ssh-action@master + with: + command: sudo systemctl start ${{ env.REPO_NAME }}-watcher.service & + host: 172.17.0.1 + user: root + pass: ${{ secrets.SSH_PASS }} \ No newline at end of file