Merge pull request #7 from growin-2025/feature/2-cd-setup #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |