-
Notifications
You must be signed in to change notification settings - Fork 2
46 lines (39 loc) · 1.13 KB
/
main.yml
File metadata and controls
46 lines (39 loc) · 1.13 KB
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
name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_SSH_PEM }}" > ~/.ssh/ec2.pem
chmod 600 ~/.ssh/ec2.pem
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- name: Set up environment variables
run: |
ssh -i ~/.ssh/ec2.pem ec2-user@${{ secrets.EC2_ADDRESS }} "bash -s" << 'EOF'
if [ ! -f ~/moving-be/.env ]; then
touch ~/moving-be/.env
fi
echo "${{ secrets.ENV_FILE }}" > ~/moving-be/.env
EOF
- name: Deploy to EC2
run: |
ssh -i ~/.ssh/ec2.pem -T ec2-user@${{ secrets.EC2_ADDRESS }} << 'EOF'
cd ~/moving-be
git fetch origin main
git reset --hard origin/main
npm install
npm run build
if ! pm2 list | grep -q "my-app"; then
pm2 start dist/app.js --name my-app -i max
else
pm2 reload my-app --update-env
fi
EOF