Refact : 크레딧 기능 활성화 #24
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 with Gradle | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout With Submodules | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.ACCESS_TOKEN }} | |
| submodules: recursive | |
| fetch-depth: 0 | |
| - name: Update Git Submodules | |
| run: git submodule update --init --recursive | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Grant execute permission for Gradlew | |
| run: chmod +x ./gradlew | |
| - name: Build Jar | |
| run: ./gradlew clean bootJar -Dspring.profiles.active=prod | |
| - name: Docker login | |
| run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| - name: Docker build and push | |
| run: | | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest | |
| deploy: | |
| name: Deploy to NCP Server | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| steps: | |
| - name: Deploy to NCP EC2 via SSH | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.NCP_HOST }} | |
| username: ${{ secrets.NCP_USER }} | |
| password: ${{ secrets.NCP_PASSWORD }} | |
| port: ${{ secrets.NCP_PORT }} | |
| script: | | |
| echo "Docker Image Pull" | |
| docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest | |
| echo "Remove old containers" | |
| docker rm -f spring-app || true | |
| docker rm -f redis-container || true | |
| echo "Create network if not exists" | |
| docker network inspect app-net >/dev/null 2>&1 || docker network create app-net | |
| echo "Create volume for Redis data if not exists" | |
| docker volume inspect redis-data >/dev/null 2>&1 || docker volume create redis-data | |
| echo "Run Redis container" | |
| docker run -d --restart unless-stopped \ | |
| --name redis-container \ | |
| --network app-net \ | |
| -p ${{ secrets.REDIS_PORT }}:6379 \ | |
| -v redis-data:/data \ | |
| redislabs/rebloom:latest \ | |
| --requirepass "${{ secrets.REDIS_PASSWORD }}" | |
| echo "Run SpringBoot container" | |
| docker run -d --restart unless-stopped \ | |
| --name spring-app \ | |
| --network app-net \ | |
| -p ${{ secrets.SPRINGBOOT_PORT }}:8080 \ | |
| -e SPRING_REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} \ | |
| -e SPRINGBOOT_PORT=${{ secrets.SPRINGBOOT_PORT }} \ | |
| -e DB_URL="${{ secrets.DB_URL }}" \ | |
| -e DB_USERNAME="${{ secrets.DB_USERNAME }}" \ | |
| -e DB_PASSWORD="${{ secrets.DB_PASSWORD }}" \ | |
| -e NAVER_CLIENT_ID="${{ secrets.NAVER_CLIENT_ID }}" \ | |
| -e NAVER_CLIENT_SECRET="${{ secrets.NAVER_CLIENT_SECRET }}" \ | |
| -e JWT_SECRET="${{ secrets.JWT_SECRET }}" \ | |
| -e API_NAVER_CLIENT_ID="${{ secrets.API_NAVER_CLIENT_ID }}" \ | |
| -e API_NAVER_CLIENT_SECRET="${{ secrets.API_NAVER_CLIENT_SECRET }}" \ | |
| -e API_CLOVA_KEY="${{ secrets.API_CLOVA_KEY }}" \ | |
| -e API_CLOVA_URL="${{ secrets.API_CLOVA_URL }}" \ | |
| ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest |