Skip to content

Commit

Permalink
chore: 배포 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
shdhkim committed Dec 21, 2024
1 parent 44164b6 commit d4c82f7
Showing 1 changed file with 30 additions and 54 deletions.
84 changes: 30 additions & 54 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
# 1. 코드 체크아웃
# 1. 소스코드 체크아웃
- name: Checkout code
uses: actions/checkout@v4

Expand All @@ -26,91 +26,67 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
# 4. Docker Hub 로그인
# 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 이미지 빌드 푸시 (Flask)
# 5. Docker 이미지 빌드 & 푸시 (Flask)
- name: Build and Push Flask Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/flask-app:latest

# 6. EC2로 배포 (Docker Compose 방식)
- name: Deploy to EC2 via Docker Compose
# 6. SCP로 docker-compose.yml을 EC2에 전송 후 Docker Compose 실행
- name: Deploy to EC2 (SCP + SSH)
env:
HOST: 3.39.237.18 # EC2 퍼블릭 IP
USER: ${{ secrets.DEPLOY_USER }} # EC2 사용자 이름
KEY: ${{ secrets.DEPLOY_KEY }} # SSH 개인 키
HOST: 3.39.237.18 # EC2 퍼블릭 IP
USER: ${{ secrets.DEPLOY_USER }} # ec2-user 등
KEY: ${{ secrets.DEPLOY_KEY }} # SSH 개인 키
run: |
# SSH 설정
# 6-1) SSH 설정
mkdir -p ~/.ssh
echo "$KEY" > deploy_key.pem
chmod 400 deploy_key.pem
echo "Adding $HOST to known_hosts"
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts || exit 1
# EC2 접속 및 Docker Compose 실행
ssh -i deploy_key.pem $USER@$HOST <<'EOF'
# Docker 설치 확인 및 설치
echo "$KEY" > ec2_key.pem
chmod 400 ec2_key.pem
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts
# 6-2) docker-compose.yml 파일을 EC2로 전송 (로컬 디렉터리 기준)
scp -i ec2_key.pem -o StrictHostKeyChecking=no \
docker-compose.yml \
$USER@$HOST:~/flask-milvus-app/docker-compose.yml
# 6-3) EC2에서 Docker Compose 실행
ssh -i ec2_key.pem $USER@$HOST << 'SSHEND'
# Docker 설치
if ! [ -x "$(command -v docker)" ]; then
sudo yum update -y
sudo yum install -y docker
sudo service docker start
fi
# Docker Compose 설치 확인 및 설치
# Docker Compose 설치
if ! [ -x "$(command -v docker-compose)" ]; then
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/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
fi
# Docker Hub 로그인
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
# 프로젝트 디렉터리로 이동
# 프로젝트 디렉터리 준비
mkdir -p ~/flask-milvus-app
cd ~/flask-milvus-app
# docker-compose.yml 파일 복사
cat > docker-compose.yml <<'COMPOSE'
version: '3.8'

services:
flask-app:
container_name: flask-app
image: ${{ secrets.DOCKER_USERNAME }}/flask-app:latest
ports:
- "5000:5000"
depends_on:
- milvus
environment:
- MILVUS_HOST=milvus
- MILVUS_PORT=19530
restart: always

milvus:
image: milvusdb/milvus:latest
container_name: milvus
ports:
- "19530:19530"
volumes:
- milvus_data:/var/lib/milvus
environment:
- MILVUS_LOG_LEVEL=info
restart: always

volumes:
milvus_data:
COMPOSE

# Docker Compose 실행
sudo docker-compose down
sudo docker-compose down || true
sudo docker-compose pull
sudo docker-compose up -d --build
EOF
# 컨테이너 상태
sudo docker-compose ps
EOF

0 comments on commit d4c82f7

Please sign in to comment.