Merge pull request #44 from UruruLab/feat/35-member #30
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: CI/CD - DockerHub Push & EC2 Deploy | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout app repository | |
| uses: actions/checkout@v3 | |
| - name: Checkout private config repository | |
| uses: actions/checkout@v3 | |
| with: | |
| repository: UruruLab/Ururu-Backend-Config | |
| token: ${{ secrets.PRIVATE_REPO_TOKEN }} | |
| path: config | |
| - name: Copy config files (application*.yml) | |
| run: | | |
| mkdir -p src/main/resources/ | |
| cp config/application-*.yml src/main/resources/ | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Grant permission to Gradle | |
| run: chmod +x ./gradlew | |
| - name: Build Spring Boot JAR | |
| run: ./gradlew clean bootJar --no-daemon | |
| - name: Login to DockerHub | |
| run: | | |
| echo "${{ secrets.DOCKERHUB_PASSWORD }}" \ | |
| | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
| - name: Build Docker image | |
| run: docker build -t juwon0909/ururu:latest -f docker/Dockerfile . | |
| - name: Push image to DockerHub | |
| run: docker push juwon0909/ururu:latest | |
| - name: Ensure remote app directory exists | |
| uses: appleboy/ssh-action@v0.1.6 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: mkdir -p /home/ec2-user/app | |
| - name: Upload docker-compose-prod.yml to EC2 | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: docker/docker-compose-prod.yml | |
| target: /home/ec2-user/app/ | |
| strip_components: 1 | |
| overwrite: true | |
| - name: Upload .env to EC2 (from config repo) | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: config/.env | |
| target: /home/ec2-user/app/ | |
| strip_components: 1 | |
| overwrite: true | |
| - name: Deploy on EC2 | |
| uses: appleboy/ssh-action@v0.1.6 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| cd /home/ec2-user/app | |
| docker rm -f ururu || true | |
| docker compose -f docker-compose-prod.yml pull | |
| docker compose -f docker-compose-prod.yml up -d --remove-orphans |