-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (81 loc) · 3.11 KB
/
deploy.yml
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 Flask and Milvus App
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
## 1. 소스코드 체크아웃
- name: Checkout Source Code
uses: actions/checkout@v4
## 2. Python 3.11 설정
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
## 3. Python 의존성 설치
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
## 4. Docker Hub 로그인
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
## 5. Docker 이미지 빌드 & 푸시
- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/flask-app:latest
## 6. EC2에 배포 (SCP + SSH)
- name: Deploy to EC2 (SCP + SSH)
env:
HOST: 3.39.237.18
USER: ${{ secrets.DEPLOY_USER }}
KEY: ${{ secrets.DEPLOY_KEY }}
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASS: ${{ secrets.DOCKER_PASSWORD }}
run: |
# SSH 설정
mkdir -p ~/.ssh
echo "$KEY" > ec2_key.pem
chmod 400 ec2_key.pem
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts
# 전체 프로젝트를 EC2로 전송
scp -i ec2_key.pem -o StrictHostKeyChecking=no -r $(pwd)/* $USER@$HOST:~/flask-milvus-app/
# EC2에서 Docker Compose 실행
ssh -i ec2_key.pem $USER@$HOST << 'EOF'
# Docker 설치 (설치되어 있지 않은 경우)
if ! [ -x "$(command -v docker)" ]; then
echo "Docker가 설치되어 있지 않음. 설치 중..."
sudo yum update -y
sudo yum install -y docker
sudo service docker start
else
echo "Docker가 이미 설치되어 있습니다."
fi
# Docker Compose 설치 (설치되어 있지 않은 경우)
if ! [ -x "$(command -v docker-compose)" ]; then
echo "Docker Compose가 설치되어 있지 않음. 설치 중..."
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
else
echo "Docker Compose가 이미 설치되어 있습니다."
fi
# Docker Hub 로그인
sudo docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"
# 프로젝트 디렉터리 이동 및 Docker Compose 실행
cd ~/flask-milvus-app
sudo docker-compose down || true
sudo docker-compose pull
sudo docker-compose up -d --build
# 컨테이너 상태 확인
sudo docker-compose ps
EOF