diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..af379b2 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,52 @@ +name: CD + +on: + push: + branches: [ "main" ] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + # 깃 레포 체크아웃 + - name: Checkout repository + uses: actions/checkout@v4 + + # .env 생성 + - name: Create .env file + run: echo "${{ secrets.ENV_FILE }}" > .env + + # EC2로 파일 전송 + - name: Copy files to EC2 + uses: appleboy/scp-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_KEY }} + port: 22 + source: "docker-compose.yml,.env" + target: "/home/ubuntu/growin/" + + # EC2에서 도커 컨테이너 재배포 + - name: Deploy to EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_KEY }} + port: 22 + script: | + cd /home/ubuntu/growin + + # 1. 최신 이미지 pull + sudo docker-compose pull + + # 2. 기존 컨테이너 중단 및 삭제 + sudo docker-compose down || true + + # 3. 컨테이너 재시작 + sudo docker-compose up -d + + # 4. 안 쓰는 이미지 정리 + sudo docker image prune -a -f diff --git a/.github/workflows/gradle.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/gradle.yml rename to .github/workflows/ci.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..50ec9e7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +services: + growin-api: + image: ghcr.io/growin-2025/growin-server:latest + container_name: growin-api + ports: + - "8080:8080" + env_file: + - .env