From 19c2c15505d3a37b6337dddccb6ccdf0d0d921a8 Mon Sep 17 00:00:00 2001 From: Zepelown Date: Fri, 20 Dec 2024 22:53:18 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20worflow=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=EB=B0=8F=20mysql=20db=20=EB=A1=9C=EC=BB=AC=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/{build.yml => cicd.yml} | 42 +++++++++++++++++++++-- .github/workflows/deploy.yml | 41 ---------------------- 2 files changed, 40 insertions(+), 43 deletions(-) rename .github/workflows/{build.yml => cicd.yml} (50%) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/cicd.yml similarity index 50% rename from .github/workflows/build.yml rename to .github/workflows/cicd.yml index 9900c3c..95c1692 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/cicd.yml @@ -1,4 +1,4 @@ -name: Build +name: Build and Deploy on: push: @@ -10,12 +10,20 @@ on: types: - closed -jobs: +jobs: build: # if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: + - name: Setup MySQL + uses: mirromutth/mysql-action@v1.1 + with: + host port: 3306 + container port: 3306 + mysql database: 'wabi' + mysql root password: ${{ secrets.SPRING_DATASOURCE_NAME }} + - name: Checkout uses: actions/checkout@v3 @@ -52,3 +60,33 @@ jobs: docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7} + deploy: + runs-on: ubuntu-latest + steps: + - name: Deploy using Docker + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PASSPHRASE }} + script: | + #!/bin/bash + ls + cd / + sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} + + # Create .env file in the correct directory + echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" | sudo tee -a .env > /dev/null + echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" | sudo tee -a .env > /dev/null + echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" | sudo tee -a .env > /dev/null + echo "JWT_KEY=${{ secrets.JWT_KEY }}" | sudo tee -a .env > /dev/null + echo "JWT_EXPIRATION_MINUTES=${{ secrets.JWT_EXPIRATION_MINUTES }}" | sudo tee -a .env > /dev/null + echo "JWT_REFRESH_EXPIRATION_HOURS=${{ secrets.JWT_REFRESH_EXPIRATION_HOURS }}" | sudo tee -a .env > /dev/null + echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" | sudo tee -a .env > /dev/null + echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" | sudo tee -a .env > /dev/null + echo "DOCKERHUB_REPOSITORY=${{ secrets.DOCKERHUB_REPOSITORY }}" | sudo tee -a .env > /dev/null + + sudo docker-compose down + sudo docker-compose up -d diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index d944e2d..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Deploy - -on: - workflow_run: - workflows: ["Build"] - types: - - completed - -jobs: - deploy: - if: startsWith(github.event.workflow_run.head_branch, 'Fix/#58') - runs-on: ubuntu-latest - - steps: - - name: Deploy using Docker - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SERVER_IP }} - username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - passphrase: ${{ secrets.SSH_PASSPHRASE }} - script: | - #!/bin/bash - ls - cd / - sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} - sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} - - # Create .env file in the correct directory - echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" | sudo tee -a .env > /dev/null - echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" | sudo tee -a .env > /dev/null - echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" | sudo tee -a .env > /dev/null - echo "JWT_KEY=${{ secrets.JWT_KEY }}" | sudo tee -a .env > /dev/null - echo "JWT_EXPIRATION_MINUTES=${{ secrets.JWT_EXPIRATION_MINUTES }}" | sudo tee -a .env > /dev/null - echo "JWT_REFRESH_EXPIRATION_HOURS=${{ secrets.JWT_REFRESH_EXPIRATION_HOURS }}" | sudo tee -a .env > /dev/null - echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" | sudo tee -a .env > /dev/null - echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" | sudo tee -a .env > /dev/null - echo "DOCKERHUB_REPOSITORY=${{ secrets.DOCKERHUB_REPOSITORY }}" | sudo tee -a .env > /dev/null - - sudo docker-compose down - sudo docker-compose up -d