Skip to content

Commit f3688ef

Browse files
authored
Create main.yml
1 parent 117f1c4 commit f3688ef

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main # main 브랜치에 푸시될 때 트리거됨
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up SSH key
17+
run: |
18+
# GitHub secrets에 저장된 PEM 파일을 생성
19+
echo "${{ secrets.EC2_SSH_PEM }}" > ~/.ssh/ec2.pem
20+
chmod 600 ~/.ssh/ec2.pem # SSH 키에 적절한 권한 부여
21+
# EC2 인스턴스의 호스트 키를 확인하지 않도록 설정 (보안을 강화하려면 이 부분을 수정)
22+
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
23+
24+
- name: Deploy to EC2
25+
run: |
26+
ssh -i ~/.ssh/ec2.pem ec2-user@YOUR_EC2_PUBLIC_IP << 'EOF'
27+
cd /path/to/your/project
28+
git pull origin main # GitHub에서 최신 변경 사항을 pull
29+
npm install # 필요에 따라 의존성 설치
30+
npm run build
31+
pm2 restart dist/app.js # 서버 재시작 (pm2 또는 다른 방법으로)
32+
EOF

0 commit comments

Comments
 (0)