From dbc7ff3f9cb3aee09cb13da9dd708c5be596325a Mon Sep 17 00:00:00 2001 From: caniro Date: Sat, 31 May 2025 23:20:23 +0900 Subject: [PATCH 1/3] =?UTF-8?q?config:=20github=20actions=20workflows=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0,?= =?UTF-8?q?=20=EA=B0=80=EB=8F=85=EC=84=B1=20=EA=B0=9C=EC=84=A0,=20?= =?UTF-8?q?=EB=8C=80=EC=83=81=20=EA=B2=BD=EB=A1=9C=20=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20workflow=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/code-analyze-push.yml | 46 --------------- ...lyze-pr.yml => code-analyze-sonarqube.yml} | 20 +++++-- .github/workflows/deploy.yml | 58 ++++++++++++++----- .github/workflows/start-service.yml | 27 --------- 4 files changed, 59 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/code-analyze-push.yml rename .github/workflows/{code-analyze-pr.yml => code-analyze-sonarqube.yml} (81%) delete mode 100644 .github/workflows/start-service.yml diff --git a/.github/workflows/code-analyze-push.yml b/.github/workflows/code-analyze-push.yml deleted file mode 100644 index 900bcde7..00000000 --- a/.github/workflows/code-analyze-push.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Code Analyze Push - -run-name: Run code analyze triggered with push by ${{github.actor}} - -on: - push: - branches: - - dev -jobs: - build: - name: Build and analyze - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: 'temurin' # Alternative distribution options are available. - - name: Cache SonarQube packages - uses: actions/cache@v4 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache Gradle packages - uses: actions/cache@v4 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Build with tests - env: - JWT_SECRET: ${{ secrets.JWT_SECRET }} - continue-on-error: true - run: ./gradlew build --info - - - name: SonarQube Analysis - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} - run: ./gradlew sonar --info \ No newline at end of file diff --git a/.github/workflows/code-analyze-pr.yml b/.github/workflows/code-analyze-sonarqube.yml similarity index 81% rename from .github/workflows/code-analyze-pr.yml rename to .github/workflows/code-analyze-sonarqube.yml index 08f369c6..5c258ca8 100644 --- a/.github/workflows/code-analyze-pr.yml +++ b/.github/workflows/code-analyze-sonarqube.yml @@ -1,6 +1,6 @@ -name: Code Analyze Pull Request +name: Code Analyze With SonarQube -run-name: Run code analyze triggered with pull request by ${{github.actor}} +run-name: Run code analyze triggered by ${{github.actor}} on: pull_request: @@ -8,6 +8,13 @@ on: branches: - main - dev + paths: + - 'src/**' + push: + branches: + - dev + paths: + - 'src/**' jobs: build: @@ -15,26 +22,31 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: 21 - distribution: 'temurin' # Alternative distribution options are available. + distribution: 'temurin' + - name: Cache SonarQube packages uses: actions/cache@v4 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages uses: actions/cache@v4 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} restore-keys: ${{ runner.os }}-gradle + - name: Build with tests env: JWT_SECRET: ${{ secrets.JWT_SECRET }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1fac436f..d3f4aa27 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,13 @@ -name: CI/CD Deploy +name: CI/CD Deploy and Start services -run-name: Deploy springboot as backend image to ECR by ${{github.actor}} +run-name: Deploy to ECR and Start services by ${{github.actor}} on: push: - branches: [ "main" ] - paths-ignore: - - 'README.md' - - '.gitignore' + branches: + - main + paths: + - 'src/**' jobs: build: @@ -32,20 +32,48 @@ jobs: - name: Build with Gradle Wrapper run: ./gradlew build -x test - - name: Build image - run: | - docker build -t ${{ secrets.AWS_ORGANIZATION }}/backend . - docker tag ${{ secrets.AWS_ORGANIZATION }}/backend:latest ${{ secrets.AWS_ECR_BACKEND_REPO }}:latest - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} - aws-region: ${{ secrets.AWS_REGION }} + role-to-assume: ${{secrets.AWS_ROLE_TO_ASSUME}} + aws-region: ${{secrets.AWS_REGION}} - name: Login to Amazon ECR uses: aws-actions/amazon-ecr-login@v2 - - name: Push image to ECR + - name: Build and Push image to ECR run: | - docker push ${{ secrets.AWS_ECR_BACKEND_REPO }}:latest \ No newline at end of file + docker build -t ${{secrets.AWS_ORGANIZATION}}/backend . + docker tag ${{secrets.AWS_ORGANIZATION}}/backend:latest ${{secrets.AWS_ECR_BACKEND_REPO}}:latest + docker push ${{secrets.AWS_ECR_BACKEND_REPO}}:latest + + start-services: + needs: build + runs-on: ubuntu-latest + steps: + - name: Connect to cloud server and run Docker commands + uses: appleboy/ssh-action@v1.2.2 + with: + host: ${{secrets.BACKEND_HOST}} + username: ${{secrets.CLOUD_USERNAME}} + key: ${{secrets.CLOUD_SECRET_KEY}} + port: ${{secrets.CLOUD_PORT}} + script: | + cd ~ + sudo sh docker_login.sh + sudo docker stop springboot + sudo docker rm -f springboot + sudo docker pull ${{secrets.AWS_ECR_BACKEND_REPO}}:latest + sudo docker run -d \ + --name springboot \ + --restart on-failure \ + -p 8080:8080 \ + -e KAKAO_CLIENT_ID='${{secrets.KAKAO_CLIENT_ID}}' \ + -e MARIADB_USER='${{secrets.MARIADB_USER}}' \ + -e MARIADB_PASSWORD='${{secrets.MARIADB_PASSWORD}}' \ + -e MARIADB_DATABASE='${{secrets.MARIADB_DATABASE}}' \ + -e JWT_SECRET='${{secrets.JWT_SECRET}}' \ + -v /etc/localtime:/etc/localtime:ro \ + -v /usr/share/zoneinfo/Asia/Seoul:/etc/timezone:ro \ + -v /home/ubuntu/logs/springboot:/app/logs \ + ${{secrets.AWS_ECR_BACKEND_REPO}}:latest diff --git a/.github/workflows/start-service.yml b/.github/workflows/start-service.yml deleted file mode 100644 index 90f6cdff..00000000 --- a/.github/workflows/start-service.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Start services - -run-name: Start containers in cloud service by ${{ github.actor }} - -on: - workflow_run: - workflows: [CI/CD Deploy] - types: - - completed - -jobs: - start-services: - runs-on: ubuntu-latest - steps: - - name: Connect to cloud server - uses: appleboy/ssh-action@v1.2.2 - with: - host: ${{secrets.CLOUD_HOST}} - username: ${{secrets.CLOUD_USERNAME}} - key: ${{secrets.CLOUD_SECRET_KEY}} - port: ${{secrets.CLOUD_PORT}} - script: | - cd ~ - sudo docker compose stop backend - sudo docker compose rm -f backend - sudo docker compose pull backend - sudo docker compose up -d backend From 7281a0f7a1032ea232bdcd67f02c957b4e9e0697 Mon Sep 17 00:00:00 2001 From: Caniro Date: Tue, 3 Jun 2025 21:58:25 +0900 Subject: [PATCH 2/3] =?UTF-8?q?config:=20=EB=8F=84=EC=BB=A4=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=A0=80=EC=9E=A5=EC=86=8C=20ECR=20->=20d?= =?UTF-8?q?ocker=20hub=20=EB=A1=A4=EB=B0=B1,=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EB=AA=85=EB=A0=B9=20=EA=B0=84=EC=86=8C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 41 +++++++++++------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d3f4aa27..e6c01564 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,20 +32,19 @@ jobs: - name: Build with Gradle Wrapper run: ./gradlew build -x test - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 + - name: Login to DockerHub + uses: docker/login-action@v3 with: - role-to-assume: ${{secrets.AWS_ROLE_TO_ASSUME}} - aws-region: ${{secrets.AWS_REGION}} + username: ${{secrets.DOCKER_USERNAME}} + password: ${{secrets.DOCKER_TOKEN}} - - name: Login to Amazon ECR - uses: aws-actions/amazon-ecr-login@v2 - - - name: Build and Push image to ECR - run: | - docker build -t ${{secrets.AWS_ORGANIZATION}}/backend . - docker tag ${{secrets.AWS_ORGANIZATION}}/backend:latest ${{secrets.AWS_ECR_BACKEND_REPO}}:latest - docker push ${{secrets.AWS_ECR_BACKEND_REPO}}:latest + - name: Build and Push Docker Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{secrets.DOCKER_USERNAME}}/if-be:latest start-services: needs: build @@ -60,20 +59,4 @@ jobs: port: ${{secrets.CLOUD_PORT}} script: | cd ~ - sudo sh docker_login.sh - sudo docker stop springboot - sudo docker rm -f springboot - sudo docker pull ${{secrets.AWS_ECR_BACKEND_REPO}}:latest - sudo docker run -d \ - --name springboot \ - --restart on-failure \ - -p 8080:8080 \ - -e KAKAO_CLIENT_ID='${{secrets.KAKAO_CLIENT_ID}}' \ - -e MARIADB_USER='${{secrets.MARIADB_USER}}' \ - -e MARIADB_PASSWORD='${{secrets.MARIADB_PASSWORD}}' \ - -e MARIADB_DATABASE='${{secrets.MARIADB_DATABASE}}' \ - -e JWT_SECRET='${{secrets.JWT_SECRET}}' \ - -v /etc/localtime:/etc/localtime:ro \ - -v /usr/share/zoneinfo/Asia/Seoul:/etc/timezone:ro \ - -v /home/ubuntu/logs/springboot:/app/logs \ - ${{secrets.AWS_ECR_BACKEND_REPO}}:latest + /bin/bash run_springboot.sh From f57e687bb17919b6178e7f2109d95d757bcd5f09 Mon Sep 17 00:00:00 2001 From: Caniro Date: Tue, 3 Jun 2025 21:59:00 +0900 Subject: [PATCH 3/3] =?UTF-8?q?config:=20AWS=20MariaDB=20=EC=BB=A8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=84=88=20=EB=B6=84=EB=A6=AC=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-prod.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 275af44a..e240f9e2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -3,7 +3,7 @@ spring: cookie: secure: true datasource: - url: jdbc:mariadb://mariadb:3306/${MARIADB_DATABASE} + url: jdbc:mariadb://${MARIADB_HOST}:3306/${MARIADB_DATABASE} driver-class-name: org.mariadb.jdbc.Driver username: ${MARIADB_USER} password: ${MARIADB_PASSWORD}