Skip to content

Commit bd1f06f

Browse files
Github actions added
1 parent 14cc665 commit bd1f06f

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Deploy to production
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- develop
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '20'
20+
21+
- name: Install dependencies
22+
run: npm install
23+
24+
- name: Build project
25+
run: npm run build
26+
27+
- name: Deploy to Self-Hosted Server
28+
env:
29+
SSH_PRIVATE_KEY: 'SHA256:sNWJn78radNW6ErUdZ5R0Hgdeb7rsZ06YXII85MJ5Nw'
30+
SSH_HOST: 'https://server.irpsc.com'
31+
SSH_USERNAME: 'frdevelop2'
32+
REMOTE_DEPLOY_PATH: '/home/frdevelop2/public_html'
33+
SSH_PORT: 4041
34+
run: |
35+
mkdir -p ~/.ssh
36+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
37+
chmod 600 ~/.ssh/id_rsa
38+
ssh-keyscan -p $SSH_PORT $SSH_HOST >> ~/.ssh/known_hosts
39+
rsync -avz --delete ./build/ $SSH_USERNAME@$SSH_HOST:$REMOTE_DEPLOY_PATH
40+
41+
# Set the name of the application
42+
APP_NAME="frdevelop2"
43+
44+
# Check if the application is already running
45+
if ssh -p $SSH_PORT $SSH_USERNAME@$SSH_HOST "pm2 show $APP_NAME &> /dev/null"; then
46+
# Restart the application
47+
ssh -p $SSH_PORT $SSH_USERNAME@$SSH_HOST "pm2 restart $APP_NAME"
48+
else
49+
# Start the application
50+
ssh -p $SSH_PORT $SSH_USERNAME@$SSH_HOST "pm2 start npm start --name $APP_NAME"
51+
fi

0 commit comments

Comments
 (0)