Skip to content

chore: 배포 테스트 #19

chore: 배포 테스트

chore: 배포 테스트 #19

Workflow file for this run

name: Deploy Flask and Milvus App
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1. 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v4
# 2. Python 설치
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
# 3. Python 의존성 설치
- name: Install 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 이미지 빌드 및 푸시 (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
env:
HOST: 3.39.237.18 # EC2 퍼블릭 IP
USER: ${{ secrets.DEPLOY_USER }} # EC2 사용자 이름
KEY: ${{ secrets.DEPLOY_KEY }} # SSH 개인 키
run: |
# 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 설치 확인 및 설치
if ! [ -x "$(command -v docker)" ]; then
sudo yum update -y
sudo yum install -y docker
sudo service docker start
fi
# 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 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

Check failure on line 110 in .github/workflows/deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/deploy.yml

Invalid workflow file

You have an error in your yaml syntax on line 110
# Docker Compose 실행
sudo docker-compose down
sudo docker-compose pull
sudo docker-compose up -d --build
EOF