Merge pull request #13 from 6th-COKATHON/feature/error.html #18
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: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Make .env file | |
| run: | | |
| echo "${{ secrets.ENV_FILE }}" > .env | |
| shell: bash | |
| - name: Archive .env and docker-compose.yml | |
| run: | | |
| mkdir deploy | |
| mv .env deploy/ | |
| cp docker-compose.yml deploy/ | |
| tar -czvf deploy.tar.gz -C deploy . | |
| shell: bash | |
| - name: Upload deployment artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: deployment-files | |
| path: deploy.tar.gz | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download deployment files | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: deployment-files | |
| path: . | |
| - name: Extract deployment files | |
| run: | | |
| echo "=== Extracting tar.gz ===" | |
| tar -xzvf deploy.tar.gz | |
| echo "=== After extraction ===" | |
| ls -al | |
| - name: Copy docker-compose.yml 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" | |
| target: "/home/ubuntu/cokathon/" | |
| - name: Copy .env to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: 22 | |
| source: ".env" | |
| target: "/home/ubuntu/cokathon/" | |
| - 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/cokathon | |
| sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| sudo docker-compose pull # 새 이미지 받기 | |
| sudo docker-compose down || true # 컨테이너 종료 | |
| sudo docker-compose up -d # 재실행 | |
| sudo docker image prune -f # 안 쓰는 이미지 정리 |