From 9cae94e02ba9ed0a98f26f9e2729c6653988d026 Mon Sep 17 00:00:00 2001 From: YoungJun Park Date: Fri, 4 Oct 2024 01:04:28 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20CI/CD=20workflows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..63df645 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,55 @@ +name: Build and Deploy to NCP + +on: + push: + branches: + - main # main 브랜치에 푸시될 때만 실행 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Gradlew build + run: ./gradlew clean build -x test + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Registry + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: jun108059/weski-app:latest + + - name: Deploy to Server + uses: appleboy/ssh-action@v0.1.10 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + password: ${{ secrets.NCP_PASSWORD }} + port: ${{ secrets.SERVER_SSH_PORT }} + script: | + cd /root + docker-compose down + docker-compose pull + docker-compose up -d \ No newline at end of file