Skip to content

Commit

Permalink
chore: add deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilhermeasper committed Jul 12, 2023
1 parent d6cde4e commit f5e174a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

jobs:
build:

runs-on: [self-hosted, Linux, X64]

strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build
deploy:
needs: build
runs-on: [self-hosted, Linux, X64]
steps:
- run: chmod +x ./deploy.sh
- run: echo ${{ secrets.DVNS_CLUSTER_PASSWORD }} | sudo -S ./deploy.sh
50 changes: 50 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

MAINPID=$(ps -ef | grep node | grep -v grep | awk '{print $2}')

service=$(cat << EOF
[Unit]
Description=MarquinhosBOT
After=network.target
[Service]
User=guilherme
KillMode=none
WorkingDirectory=/home/$USER/github-runners/actions-runner/_work/MarquinhosBOT/MarquinhosBOT/dist
ExecStart=/home/$USER/.nvm/versions/node/v18.13.0/bin/node ./index.js
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
RestartSec=3
StartLimitInterval=0
[Install]
WantedBy=multi-user.target
EOF
)

systemctl stop marquinhos.service

echo "$service" > /etc/systemd/system/marquinhos.service

systemctl daemon-reload

systemctl enable marquinhos.service

systemctl start marquinhos.service

systemctl status marquinhos.service

0 comments on commit f5e174a

Please sign in to comment.