From b7f68fb9942ea589df0a78dd63385d7fa927f188 Mon Sep 17 00:00:00 2001 From: Minseong Park <52368015+pminsung12@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:04:26 +0900 Subject: [PATCH 01/10] =?UTF-8?q?[BSVR-27]=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20CI/CD=20=EC=84=B8=ED=8C=85=20(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: gitignore에 .env 추가 * feat: application-jpa sql init mode 항목 always->never * feat: 개발환경 db 세팅 값을 cloud db for mysql로 변경 * feat: 개발환경 cicd 스크립트 작성 * feat: 개발용 main 브랜치 ci 스크립트 재작성 * fix: 트리거에서 개발서버 배포담당인 dev브랜치 제외 --- .github/workflows/dev-ci.yaml | 71 ----------- .github/workflows/dev-cicd.yaml | 115 ++++++++++++++++++ .github/workflows/main-ci.yaml | 69 +++++++++++ .gitignore | 2 + docker-compose.yml | 74 ++++++----- .../src/main/resources/application-jpa.yaml | 2 +- 6 files changed, 223 insertions(+), 110 deletions(-) delete mode 100644 .github/workflows/dev-ci.yaml create mode 100644 .github/workflows/dev-cicd.yaml create mode 100644 .github/workflows/main-ci.yaml diff --git a/.github/workflows/dev-ci.yaml b/.github/workflows/dev-ci.yaml deleted file mode 100644 index 68b7ca8a..00000000 --- a/.github/workflows/dev-ci.yaml +++ /dev/null @@ -1,71 +0,0 @@ -name: Build And Test - -on: - push: - branches: - - dev - - main - pull_request: - branches: - - dev - - main - -jobs: - build-and-test: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: "17" - distribution: "corretto" - - - name: Cache Gradle - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build with Gradle - run: ./gradlew build -x test --stacktrace --parallel - - - name: Run tests - run: ./gradlew test - - - name: Publish Unit Test Results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: '**/build/test-results/test/TEST-*.xml' - - - name: JUnit Report Action - uses: mikepenz/action-junit-report@v3 - if: always() - with: - report_paths: '**/build/test-results/test/TEST-*.xml' - - - name: Store test results - uses: actions/upload-artifact@v3 - if: always() - with: - name: test-results - path: '**/build/test-results/test/TEST-*.xml' - - - name: Test Report Summary - if: always() - run: | - echo '## Test Report Summary' >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - ./gradlew test --console=plain || true - echo '```' >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-cicd.yaml new file mode 100644 index 00000000..e40f8710 --- /dev/null +++ b/.github/workflows/dev-cicd.yaml @@ -0,0 +1,115 @@ +name: Build And Test + +on: + push: + branches: + - dev + - main + pull_request: + branches: + - dev + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: "17" + distribution: "corretto" + + - name: Cache Gradle + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test --stacktrace --parallel + + - name: Run tests + run: ./gradlew test + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: '**/build/test-results/test/TEST-*.xml' + + - name: JUnit Report Action + uses: mikepenz/action-junit-report@v3 + if: always() + with: + report_paths: '**/build/test-results/test/TEST-*.xml' + + - name: Store test results + uses: actions/upload-artifact@v3 + if: always() + with: + name: test-results + path: '**/build/test-results/test/TEST-*.xml' + + - name: Test Report Summary + if: always() + run: | + echo '## Test Report Summary' >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + ./gradlew test --console=plain || true + echo '```' >> $GITHUB_STEP_SUMMARY + + deploy: + needs: build-and-test + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:${{ github.sha }} + + - name: Deploy to Dev NCP Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_NCP_SERVER_HOST }} + username: ${{ secrets.DEV_NCP_SERVER_USERNAME }} + password: ${{ secrets.DEV_NCP_SERVER_PASSWORD }} + script: | + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev-${{ github.sha }} + docker stop spot-server-dev || true + docker rm spot-server-dev || true + docker run -d --name spot-server-dev \ + -p 8080:8080 \ + -e SPRING_DATASOURCE_URL=${{ secrets.DEV_DB_URL }} \ + -e SPRING_DATASOURCE_USERNAME=${{ secrets.DEV_DB_USERNAME }} \ + -e SPRING_DATASOURCE_PASSWORD=${{ secrets.DEV_DB_PASSWORD }} \ + -e TZ=Asia/Seoul \ + ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev-${{ github.sha }} + docker system prune -af \ No newline at end of file diff --git a/.github/workflows/main-ci.yaml b/.github/workflows/main-ci.yaml new file mode 100644 index 00000000..fc4be30b --- /dev/null +++ b/.github/workflows/main-ci.yaml @@ -0,0 +1,69 @@ +name: Build And Test + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: "17" + distribution: "corretto" + + - name: Cache Gradle + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build -x test --stacktrace --parallel + + - name: Run tests + run: ./gradlew test + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: '**/build/test-results/test/TEST-*.xml' + + - name: JUnit Report Action + uses: mikepenz/action-junit-report@v3 + if: always() + with: + report_paths: '**/build/test-results/test/TEST-*.xml' + + - name: Store test results + uses: actions/upload-artifact@v3 + if: always() + with: + name: test-results + path: '**/build/test-results/test/TEST-*.xml' + + - name: Test Report Summary + if: always() + run: | + echo '## Test Report Summary' >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + ./gradlew test --console=plain || true + echo '```' >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/.gitignore b/.gitignore index fcc22047..754acf39 100644 --- a/.gitignore +++ b/.gitignore @@ -381,3 +381,5 @@ gradle-app.setting # End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij,intellij+iml,intellij+all,visualstudiocode,java,gradle,kotlin /db/ + +.env \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 262876be..5959c3a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,42 +1,40 @@ # docker-compose.yml services: - mysql: - container_name: spot-mysql - image: mysql:8 # 선호하는 버전 있을 경우 선정 예정! - ports: - - 3306:3306 # 혹시나 기존에 MySQL 사용 중일 경우 앞자리를 다른 포트로 바꿔야함. - volumes: - - ./db/mysql/data:/var/lib/mysql # 기존 데이터 파일과 격리를 위해 db/mysql/data 로 설정함! - command: - - '--character-set-server=utf8mb4' - - '--collation-server=utf8mb4_unicode_ci' - environment: - TZ : "Asia/Seoul" - MYSQL_ROOT_PASSWORD: test1234 # 임시 비밀번호 - MYSQL_DATABASE: spot # DB 이름 선정 시 변경 예정. - MYSQL_USER: test1234 # 임시 유저 - MYSQL_PASSWORD: test1234 # 임시 비밀번호 - healthcheck: # MySQL 서비스 상태 확인 - test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] - timeout: 20s - retries: 10 + mysql: + container_name: spot-mysql + image: mysql:8 # 선호하는 버전 있을 경우 선정 예정! + ports: + - 3306:3306 # 혹시나 기존에 MySQL 사용 중일 경우 앞자리를 다른 포트로 바꿔야함. + volumes: + - ./db/mysql/data:/var/lib/mysql # 기존 데이터 파일과 격리를 위해 db/mysql/data 로 설정함! + command: + - '--character-set-server=utf8mb4' + - '--collation-server=utf8mb4_unicode_ci' + environment: + TZ : "Asia/Seoul" + MYSQL_ROOT_PASSWORD: test1234 # 임시 비밀번호 + MYSQL_DATABASE: spot # DB 이름 선정 시 변경 예정. + MYSQL_USER: test1234 # 임시 유저 + MYSQL_PASSWORD: test1234 # 임시 비밀번호 + healthcheck: # MySQL 서비스 상태 확인 + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 20s + retries: 10 - server: - build: # 디렉토리에 있는 도커파일 이용해서 이미지 빌드 - context: . - dockerfile: Dockerfile.dev - container_name: spot-spring-server - ports: - - 8080:8080 - depends_on: # 항상 mysql 실행하고 서버 실행되게 함. - mysql: - condition: service_healthy # mysql 컨테이너의 healthcheck가 정상일 때까지 대기! - environment: - SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/spot - SPRING_DATASOURCE_USERNAME: test1234 - SPRING_DATASOURCE_PASSWORD: test1234 - volumes: - - ./:/app - - ~/.gradle:/root/.gradle - command: ./gradlew :application:bootRun \ No newline at end of file + server: + build: # 디렉토리에 있는 도커파일 이용해서 이미지 빌드 + context: . + dockerfile: Dockerfile.dev + container_name: spot-spring-server + ports: + - 8080:8080 + environment: + - SPRING_DATASOURCE_URL=${DB_URL} + - SPRING_DATASOURCE_USERNAME=${DB_USERNAME} + - SPRING_DATASOURCE_PASSWORD=${DB_PASSWORD} + - TZ=Asia/Seoul + volumes: + - ./:/app + - ~/.gradle:/root/.gradle + command: ./gradlew :application:bootRun \ No newline at end of file diff --git a/infrastructure/jpa/src/main/resources/application-jpa.yaml b/infrastructure/jpa/src/main/resources/application-jpa.yaml index c7affc08..c8f9190f 100644 --- a/infrastructure/jpa/src/main/resources/application-jpa.yaml +++ b/infrastructure/jpa/src/main/resources/application-jpa.yaml @@ -17,7 +17,7 @@ spring: sql: init: - mode: always # 필요한 경우 'never'로 변경 + mode: never # 필요한 경우 'never'로 변경 server: port: 8080 From 5f50d4123811b62e9d28a0bda25c32f32e055390 Mon Sep 17 00:00:00 2001 From: Minseong Park <52368015+pminsung12@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:22:30 +0900 Subject: [PATCH 02/10] =?UTF-8?q?[BSVR=20-=2027]=20=EA=B0=9C=EB=B0=9C?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20CI/CD=20ver.2=20=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: gitignore에 .env 추가 * feat: application-jpa sql init mode 항목 always->never * feat: 개발환경 db 세팅 값을 cloud db for mysql로 변경 * feat: 개발환경 cicd 스크립트 작성 * feat: 개발용 main 브랜치 ci 스크립트 재작성 * fix: 트리거에서 개발서버 배포담당인 dev브랜치 제외 * fix: 개발환경 작업 스크립트 통합 --- .github/workflows/dev-cicd.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-cicd.yaml index e40f8710..4894c519 100644 --- a/.github/workflows/dev-cicd.yaml +++ b/.github/workflows/dev-cicd.yaml @@ -72,7 +72,8 @@ jobs: deploy: needs: build-and-test - if: github.ref == 'refs/heads/main' && github.event_name == 'push' + if: github.ref == 'refs/heads/dev' && github.event_name == 'push' + runs-on: ubuntu-latest steps: From 6a42b1a1e5838b508290ce3d1ae57f0358b56b1a Mon Sep 17 00:00:00 2001 From: Minseong Park <52368015+pminsung12@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:33:49 +0900 Subject: [PATCH 03/10] =?UTF-8?q?[BSVR-27]=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20CICD=20v.3=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: gitignore에 .env 추가 * feat: application-jpa sql init mode 항목 always->never * feat: 개발환경 db 세팅 값을 cloud db for mysql로 변경 * feat: 개발환경 cicd 스크립트 작성 * feat: 개발용 main 브랜치 ci 스크립트 재작성 * fix: 트리거에서 개발서버 배포담당인 dev브랜치 제외 * fix: 개발환경 작업 스크립트 통합 * feat: 배포용 도커파일 추가 --- .github/workflows/dev-cicd.yaml | 2 +- Dockerfile | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-cicd.yaml index 4894c519..971d56c1 100644 --- a/.github/workflows/dev-cicd.yaml +++ b/.github/workflows/dev-cicd.yaml @@ -73,7 +73,7 @@ jobs: deploy: needs: build-and-test if: github.ref == 'refs/heads/dev' && github.event_name == 'push' - + runs-on: ubuntu-latest steps: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a9b87f5e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# 빌드 스테이지 +FROM gradle:7.4-jdk17 AS build +WORKDIR /app +COPY . . +RUN ./gradlew build -x test + +# 실행 스테이지 +FROM openjdk:17-jdk-slim +WORKDIR /app +COPY --from=build /app/application/build/libs/*.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From e4b8ea370c8c40200d9ff9edf8417acfe8c6fa84 Mon Sep 17 00:00:00 2001 From: Minseong Park <52368015+pminsung12@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:42:52 +0900 Subject: [PATCH 04/10] =?UTF-8?q?[BSVR-27]=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20CICD=20ver.3=20(#29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: gitignore에 .env 추가 * feat: application-jpa sql init mode 항목 always->never * feat: 개발환경 db 세팅 값을 cloud db for mysql로 변경 * feat: 개발환경 cicd 스크립트 작성 * feat: 개발용 main 브랜치 ci 스크립트 재작성 * fix: 트리거에서 개발서버 배포담당인 dev브랜치 제외 * fix: 개발환경 작업 스크립트 통합 * feat: 배포용 도커파일 추가 * fix: ssh 포트번호 설정 추가 --- .github/workflows/dev-cicd.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-cicd.yaml index 971d56c1..e35145e6 100644 --- a/.github/workflows/dev-cicd.yaml +++ b/.github/workflows/dev-cicd.yaml @@ -102,6 +102,7 @@ jobs: host: ${{ secrets.DEV_NCP_SERVER_HOST }} username: ${{ secrets.DEV_NCP_SERVER_USERNAME }} password: ${{ secrets.DEV_NCP_SERVER_PASSWORD }} + port: ${{ secrets.DEV_NCP_SERVER_PORT }} script: | docker pull ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev-${{ github.sha }} docker stop spot-server-dev || true From ba5bfad9c085f322d3067b022a93996166e02c28 Mon Sep 17 00:00:00 2001 From: Minseong Park <52368015+pminsung12@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:08:20 +0900 Subject: [PATCH 05/10] =?UTF-8?q?[BSVR-27]=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20CICD=20ver.4=20(#30)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: gitignore에 .env 추가 * feat: application-jpa sql init mode 항목 always->never * feat: 개발환경 db 세팅 값을 cloud db for mysql로 변경 * feat: 개발환경 cicd 스크립트 작성 * feat: 개발용 main 브랜치 ci 스크립트 재작성 * fix: 트리거에서 개발서버 배포담당인 dev브랜치 제외 * fix: 개발환경 작업 스크립트 통합 * feat: 배포용 도커파일 추가 * fix: ssh 포트번호 설정 추가 * fix: push할 때 도커 이미지 태그와 실행 단계에서 이미지 태그가 다른 것 수정 --- .github/workflows/dev-cicd.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-cicd.yaml index e35145e6..a7f72e23 100644 --- a/.github/workflows/dev-cicd.yaml +++ b/.github/workflows/dev-cicd.yaml @@ -73,7 +73,6 @@ jobs: deploy: needs: build-and-test if: github.ref == 'refs/heads/dev' && github.event_name == 'push' - runs-on: ubuntu-latest steps: @@ -94,7 +93,7 @@ jobs: with: context: . push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:${{ github.sha }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev:${{ github.sha }} - name: Deploy to Dev NCP Server uses: appleboy/ssh-action@master From 2a69f412949af34f71ad631af90acea8cd891ce8 Mon Sep 17 00:00:00 2001 From: Minseong Park <52368015+pminsung12@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:15:36 +0900 Subject: [PATCH 06/10] =?UTF-8?q?[BSVR-27]=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20CICD=20ver.5=20(#31)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: gitignore에 .env 추가 * feat: application-jpa sql init mode 항목 always->never * feat: 개발환경 db 세팅 값을 cloud db for mysql로 변경 * feat: 개발환경 cicd 스크립트 작성 * feat: 개발용 main 브랜치 ci 스크립트 재작성 * fix: 트리거에서 개발서버 배포담당인 dev브랜치 제외 * fix: 개발환경 작업 스크립트 통합 * feat: 배포용 도커파일 추가 * fix: ssh 포트번호 설정 추가 * fix: push할 때 도커 이미지 태그와 실행 단계에서 이미지 태그가 다른 것 수정 * fix: build and push Docker image 태그 : 오타 수정 --- .github/workflows/dev-cicd.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-cicd.yaml index a7f72e23..45428dde 100644 --- a/.github/workflows/dev-cicd.yaml +++ b/.github/workflows/dev-cicd.yaml @@ -93,7 +93,7 @@ jobs: with: context: . push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev:${{ github.sha }} + tags: ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev-${{ github.sha }} - name: Deploy to Dev NCP Server uses: appleboy/ssh-action@master From bb63a08c6b313493d14f03edec549beb34e39c40 Mon Sep 17 00:00:00 2001 From: Minseong Park Date: Wed, 17 Jul 2024 22:52:43 +0900 Subject: [PATCH 07/10] =?UTF-8?q?ci:=20=EC=95=88=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main-ci.yaml | 69 ---------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 .github/workflows/main-ci.yaml diff --git a/.github/workflows/main-ci.yaml b/.github/workflows/main-ci.yaml deleted file mode 100644 index fc4be30b..00000000 --- a/.github/workflows/main-ci.yaml +++ /dev/null @@ -1,69 +0,0 @@ -name: Build And Test - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build-and-test: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: "17" - distribution: "corretto" - - - name: Cache Gradle - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build with Gradle - run: ./gradlew build -x test --stacktrace --parallel - - - name: Run tests - run: ./gradlew test - - - name: Publish Unit Test Results - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() - with: - files: '**/build/test-results/test/TEST-*.xml' - - - name: JUnit Report Action - uses: mikepenz/action-junit-report@v3 - if: always() - with: - report_paths: '**/build/test-results/test/TEST-*.xml' - - - name: Store test results - uses: actions/upload-artifact@v3 - if: always() - with: - name: test-results - path: '**/build/test-results/test/TEST-*.xml' - - - name: Test Report Summary - if: always() - run: | - echo '## Test Report Summary' >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - ./gradlew test --console=plain || true - echo '```' >> $GITHUB_STEP_SUMMARY \ No newline at end of file From ee1e803448c164e59a385cdda77acb8c77f69726 Mon Sep 17 00:00:00 2001 From: Minseong Park Date: Wed, 17 Jul 2024 22:53:05 +0900 Subject: [PATCH 08/10] =?UTF-8?q?ci:=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20cicd=EC=97=90=20github=20release=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ev-cicd.yaml => dev-build-and-deploy.yaml} | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) rename .github/workflows/{dev-cicd.yaml => dev-build-and-deploy.yaml} (81%) diff --git a/.github/workflows/dev-cicd.yaml b/.github/workflows/dev-build-and-deploy.yaml similarity index 81% rename from .github/workflows/dev-cicd.yaml rename to .github/workflows/dev-build-and-deploy.yaml index 45428dde..7cdddbda 100644 --- a/.github/workflows/dev-cicd.yaml +++ b/.github/workflows/dev-build-and-deploy.yaml @@ -3,11 +3,9 @@ name: Build And Test on: push: branches: - - dev - main pull_request: branches: - - dev - main jobs: @@ -72,7 +70,7 @@ jobs: deploy: needs: build-and-test - if: github.ref == 'refs/heads/dev' && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event_name == 'push' runs-on: ubuntu-latest steps: @@ -113,4 +111,25 @@ jobs: -e SPRING_DATASOURCE_PASSWORD=${{ secrets.DEV_DB_PASSWORD }} \ -e TZ=Asia/Seoul \ ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:dev-${{ github.sha }} - docker system prune -af \ No newline at end of file + docker system prune -af + + create-release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.SPOT_GITHUB_TOKEN }} + + - name: Create a GitHub release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.tag_version.outputs.new_tag }} + name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} From ee1ea1a4f72a22e97163a9d250e91f869ffb7b1e Mon Sep 17 00:00:00 2001 From: Minseong Park Date: Wed, 17 Jul 2024 22:53:20 +0900 Subject: [PATCH 09/10] =?UTF-8?q?ci:=20=EC=9A=B4=EC=98=81=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20deploy=20=EC=9E=90=EB=8F=99=ED=99=94=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/manual-prod-deploy.yaml | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/manual-prod-deploy.yaml diff --git a/.github/workflows/manual-prod-deploy.yaml b/.github/workflows/manual-prod-deploy.yaml new file mode 100644 index 00000000..45573a0f --- /dev/null +++ b/.github/workflows/manual-prod-deploy.yaml @@ -0,0 +1,37 @@ +name: Manual Production Deployment + +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag to deploy (v1.0.0)' + required: true + +jobs: + deploy-to-prod: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.tag }} + + - name: Deploy to Prod NCP Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.PROD_NCP_SERVER_HOST }} + username: ${{ secrets.PROD_NCP_SERVER_USERNAME }} + password: ${{ secrets.PROD_NCP_SERVER_PASSWORD }} + port: ${{ secrets.PROD_NCP_SERVER_PORT }} + script: | + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:${{ github.event.inputs.tag }} + docker stop spot-server-prod || true + docker rm spot-server-prod || true + docker run -d --name spot-server-prod \ + -p 8080:8080 \ + -e SPRING_DATASOURCE_URL=${{ secrets.PROD_DB_URL }} \ + -e SPRING_DATASOURCE_USERNAME=${{ secrets.PROD_DB_USERNAME }} \ + -e SPRING_DATASOURCE_PASSWORD=${{ secrets.PROD_DB_PASSWORD }} \ + -e TZ=Asia/Seoul \ + ${{ secrets.DOCKERHUB_USERNAME }}/spot-server:${{ github.event.inputs.tag }} + docker system prune -af \ No newline at end of file From 298dd69e37da51a642a7e2cdab895db3129caec9 Mon Sep 17 00:00:00 2001 From: Minseong Park Date: Wed, 17 Jul 2024 23:09:04 +0900 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20personal=20access=20token=EC=97=90?= =?UTF-8?q?=EC=84=9C=20github=20token=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-build-and-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-build-and-deploy.yaml b/.github/workflows/dev-build-and-deploy.yaml index 7cdddbda..e0e000af 100644 --- a/.github/workflows/dev-build-and-deploy.yaml +++ b/.github/workflows/dev-build-and-deploy.yaml @@ -125,7 +125,7 @@ jobs: id: tag_version uses: mathieudutour/github-tag-action@v6.1 with: - github_token: ${{ secrets.SPOT_GITHUB_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} - name: Create a GitHub release uses: ncipollo/release-action@v1