Skip to content

Commit ff80de3

Browse files
committed
chore: EC2 자동 배포용 CI/CD 파이프라인 추가
EC2 서버로 자동 배포가 가능하도록 GitHub Actions workflow 파일(deploy.yml)을 추가함. - main 브랜치에 push 시 deploy.yml이 실행 - deploy.yml에서는 EC2 서버에 SSH 접속 후 deploy.sh를 실행 - deploy.sh에서는 docker-compose up -d --build 명령어로 전체 서비스를 재배포 - 중지된 컨테이너와 사용하지 않는 이미지를 간단히 정리 Secrets에 다음 값을 등록하였습니다: - EC2_KEY (EC2 접속용 private key) - EC2_HOST (EC2 퍼블릭 IP) - EC2_USER (EC2 접속 계정명) 주의: EC2 서버에 deploy.sh가 사전에 존재해야 정상 동작
1 parent 7f2013c commit ff80de3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main # main 브랜치 push 시 자동 배포
7+
8+
jobs:
9+
deploy:
10+
name: Deploy to EC2 Server
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up SSH key
18+
run: |
19+
mkdir -p ~/.ssh
20+
echo "${{ secrets.EC2_KEY }}" > ~/.ssh/id_rsa
21+
chmod 600 ~/.ssh/id_rsa
22+
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
23+
24+
- name: SSH and deploy
25+
run: |
26+
ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} "cd ~ && ./deploy.sh"

0 commit comments

Comments
 (0)