-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (74 loc) · 2.67 KB
/
deploy.yml
File metadata and controls
95 lines (74 loc) · 2.67 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Deploy to EC2
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Build project
run: npm run build
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/sysone-fe:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to EC2 with HTTPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu
# 환경 변수 파일 생성/업데이트
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" > .env
# HTTPS Docker Compose 파일이 있는지 확인
if [ ! -f "docker-compose.https.yml" ]; then
echo "❌ HTTPS 설정이 되어있지 않습니다!"
echo "먼저 서버에서 add-https-to-existing.sh 스크립트를 실행해주세요."
exit 1
fi
# 기존 컨테이너 중지 및 제거
sudo docker-compose -f docker-compose.https.yml down || true
# 오래된 이미지 제거
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/sysone-fe:latest || true
# 최신 이미지 풀 및 실행
sudo docker-compose -f docker-compose.https.yml pull
sudo docker-compose -f docker-compose.https.yml up -d
# 사용하지 않는 이미지 정리
sudo docker image prune -f
# 배포 상태 확인
sleep 10
sudo docker-compose -f docker-compose.https.yml ps
echo "✅ HTTPS 배포 완료: https://sysonetaskmanager.store"