-
-
Notifications
You must be signed in to change notification settings - Fork 359
69 lines (54 loc) · 1.78 KB
/
backend-ec2-deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: EC2 Deployment
on:
push:
branches: [ backup ]
jobs:
deploy-to-ec2:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: npm install
working-directory: ./server
- name: Run tests
run: npm test -- --passWithNoTests
working-directory: ./server
- name: Set up .env file on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_SSH_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
port: 22
script: |
cd /home/ubuntu/Full-Stack-Project-Assessment/server
echo "DB_USER=${{ secrets.DB_USER }}" > .env
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
- name: Copy files to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_SSH_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
port: 22
source: "./Full-Stack-Project-Assessment/server"
target: "/home/ubuntu/Full-Stack-Project-Assessment/server"
- name: deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_SSH_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
port: 22
script: |
cd /home/ubuntu/Full-Stack-Project-Assessment/server
npm install
pm2 restart all