From 05a9af283a27cd12d7c04831bdf9f844806dfe91 Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sun, 23 Nov 2025 23:02:10 +0900 Subject: [PATCH 01/10] =?UTF-8?q?devops:=20GitHub=20Actions=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20CI/CD=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 90 +++++++++++++++++++++++++++++++ Dockerfile | 2 +- version.txt | 1 + 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy-test.yml create mode 100644 version.txt diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml new file mode 100644 index 0000000..a01c4ca --- /dev/null +++ b/.github/workflows/deploy-test.yml @@ -0,0 +1,90 @@ +name: CI/CD - Searchweb (version.txt 기반) + +on: + push: + branches: [ "main", "dev" ] + pull_request: + branches: [ "main", "dev" ] + +jobs: + build-and-push: + name: Build & Push Docker Image + runs-on: ubuntu-latest + + outputs: + image_tag: ${{ steps.meta.outputs.IMAGE_TAG }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Read version.txt + id: meta + run: | + VERSION=$(cat version.txt | tr -d ' \n') + echo "IMAGE_TAG=${VERSION}" >> $GITHUB_OUTPUT + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Grant execute permission + run: chmod +x ./gradlew + + - name: Build JAR + run: ./gradlew clean bootJar + + - name: Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker Build (version + latest) + run: | + docker build \ + -t ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:${{ steps.meta.outputs.IMAGE_TAG }} \ + -t ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest \ + . + + - name: Docker Push + run: | + docker push ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:${{ steps.meta.outputs.IMAGE_TAG }} + docker push ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest + + deploy: + name: Deploy to OCI + runs-on: ubuntu-latest + needs: build-and-push + + env: + IMAGE_TAG: ${{ needs.build-and-push.outputs.image_tag }} + + steps: + - name: Prepare SSH key + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + + - name: Add Known Hosts + run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts + + - name: Deploy via SSH + run: | + ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << EOF + docker login -u '${{ secrets.DOCKERHUB_USERNAME }}' -p '${{ secrets.DOCKERHUB_TOKEN }}' + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:${IMAGE_TAG} + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest + + if [ "$(docker ps -q -f name=searchweb)" ]; then docker stop searchweb; fi + if [ "$(docker ps -aq -f name=searchweb)" ]; then docker rm searchweb; fi + + docker run -d \ + --env-file /home/ubuntu/searchweb/.env \ + -p 8080:8080 \ + --name searchweb \ + ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest + EOF diff --git a/Dockerfile b/Dockerfile index 8a0b110..11a6afd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ -FROM openjdk:17-jdk-slim +FROM eclipse-temurin:17-jre-alpine COPY build/libs/SearchWeb-0.0.1-SNAPSHOT.jar app.jar ENTRYPOINT ["java", "-Dspring.profiles.active=docker", "-jar", "app.jar"] \ No newline at end of file diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..1cc5f65 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +1.1.0 \ No newline at end of file From 8e0dd5e46cffc801030d4ba2984dffd09fa1ea4f Mon Sep 17 00:00:00 2001 From: jin2304 Date: Mon, 24 Nov 2025 00:26:04 +0900 Subject: [PATCH 02/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20.env=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index a01c4ca..79414a5 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -83,7 +83,7 @@ jobs: if [ "$(docker ps -aq -f name=searchweb)" ]; then docker rm searchweb; fi docker run -d \ - --env-file /home/ubuntu/searchweb/.env \ + --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest From d0824a2ee05b402827b3d83c20e75f033623fb6e Mon Sep 17 00:00:00 2001 From: jin2304 Date: Mon, 24 Nov 2025 00:35:19 +0900 Subject: [PATCH 03/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=BB=A8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=84=88=20=EC=9D=B4=EB=A6=84=20=EC=A4=91=EB=B3=B5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 79414a5..71be3a4 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -74,17 +74,18 @@ jobs: - name: Deploy via SSH run: | - ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << EOF + ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' docker login -u '${{ secrets.DOCKERHUB_USERNAME }}' -p '${{ secrets.DOCKERHUB_TOKEN }}' docker pull ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:${IMAGE_TAG} docker pull ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest - if [ "$(docker ps -q -f name=searchweb)" ]; then docker stop searchweb; fi - if [ "$(docker ps -aq -f name=searchweb)" ]; then docker rm searchweb; fi + # 기존 컨테이너 강제 삭제 (있으면 지우고, 없으면 에러 무시) + docker rm -f searchweb 2>/dev/null || true + # 새 컨테이너 실행 docker run -d \ --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ ${{ secrets.DOCKERHUB_USERNAME }}/searchweb:latest - EOF + EOF \ No newline at end of file From 31adb4adbe8f7ad3162d596445a123f60a449c99 Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sun, 30 Nov 2025 19:22:05 +0900 Subject: [PATCH 04/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 71be3a4..b8c0ffa 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -84,6 +84,7 @@ jobs: # 새 컨테이너 실행 docker run -d \ + --env SPRING_PROFILES_ACTIVE=dev \ --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ From d2a24e6b01666ebdc98824ee89960564e1d1bb9e Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sun, 30 Nov 2025 20:43:41 +0900 Subject: [PATCH 05/10] =?UTF-8?q?devops:=20Dockerfile=20=EC=8B=A4=ED=96=89?= =?UTF-8?q?=ED=99=98=EA=B2=AC=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 11a6afd..dd932ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ FROM eclipse-temurin:17-jre-alpine COPY build/libs/SearchWeb-0.0.1-SNAPSHOT.jar app.jar -ENTRYPOINT ["java", "-Dspring.profiles.active=docker", "-jar", "app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From f8e29271e8c7f50a58b984cb0d45ea05f5a9c69b Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sun, 30 Nov 2025 22:43:14 +0900 Subject: [PATCH 06/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20local=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index b8c0ffa..b0b56e6 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -84,7 +84,7 @@ jobs: # 새 컨테이너 실행 docker run -d \ - --env SPRING_PROFILES_ACTIVE=dev \ + --env SPRING_PROFILES_ACTIVE=local \ --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ From 9605b7a9daf30369d4684746f25b4103439f9d9d Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sun, 30 Nov 2025 22:58:15 +0900 Subject: [PATCH 07/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20dev=20=ED=94=84=EB=A1=9C=ED=95=84?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index b0b56e6..b8c0ffa 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -84,7 +84,7 @@ jobs: # 새 컨테이너 실행 docker run -d \ - --env SPRING_PROFILES_ACTIVE=local \ + --env SPRING_PROFILES_ACTIVE=dev \ --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ From 4ecd76af13a89d24e34a33e0b7f2d433f7d7e823 Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sun, 30 Nov 2025 23:23:40 +0900 Subject: [PATCH 08/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=EC=97=90=EC=84=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=ED=99=98=EA=B2=BD=20=EB=AA=85=EC=8B=9C=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/deploy-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index b8c0ffa..71be3a4 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -84,7 +84,6 @@ jobs: # 새 컨테이너 실행 docker run -d \ - --env SPRING_PROFILES_ACTIVE=dev \ --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ From 0d3f53646dda3c47d3ce5e4fc5d2f1f12030b3f0 Mon Sep 17 00:00:00 2001 From: jin2304 Date: Mon, 1 Dec 2025 00:26:03 +0900 Subject: [PATCH 09/10] =?UTF-8?q?devops:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=EC=97=90=EC=84=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=ED=99=98=EA=B2=BD=20=EB=AA=85=EC=8B=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-test.yml b/.github/workflows/deploy-test.yml index 71be3a4..b8c0ffa 100644 --- a/.github/workflows/deploy-test.yml +++ b/.github/workflows/deploy-test.yml @@ -84,6 +84,7 @@ jobs: # 새 컨테이너 실행 docker run -d \ + --env SPRING_PROFILES_ACTIVE=dev \ --env-file /home/ubuntu/Searchweb/.env \ -p 8080:8080 \ --name searchweb \ From 73c7c2deb7456c1cef16761082aad39136cca7d1 Mon Sep 17 00:00:00 2001 From: jin2304 Date: Sat, 6 Dec 2025 21:46:48 +0900 Subject: [PATCH 10/10] =?UTF-8?q?devops:=20.gitignore=EC=97=90=20applicati?= =?UTF-8?q?on-*.properties,=20application.properties=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 민감 정보는 .env로 분리하였기 때문에 CI/CD를 위해 비민감 정보가 포함된 application-*.properties, application.properties은 .gitignore에서 삭제 --- .gitignore | 2 - src/main/resources/application-dev.properties | 15 ++++++ .../resources/application-local.properties | 14 ++++++ .../resources/application-prod.properties | 15 ++++++ src/main/resources/application.properties | 50 +++++++++++++++++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/application-dev.properties create mode 100644 src/main/resources/application-local.properties create mode 100644 src/main/resources/application-prod.properties create mode 100644 src/main/resources/application.properties diff --git a/.gitignore b/.gitignore index f5415cc..b700666 100644 --- a/.gitignore +++ b/.gitignore @@ -19,8 +19,6 @@ bin/ ### Ignore application.properties ### -application.properties -application-*.properties .env diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..8a319fb --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,15 @@ +# Dev mysql settings +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=${DEV_DB_URL} +spring.datasource.username=${DEV_DB_USERNAME} +spring.datasource.password=${DEV_DB_PASSWORD} + +## Dev OAUTH2 +spring.security.oauth2.client.registration.naver.redirect-uri=${CLOUD_NAVER_OAUTH_REDIRECT_URI} +spring.security.oauth2.client.registration.google.redirect-uri=${CLOUD_GOOGLE_OAUTH_REDIRECT_URI} +spring.security.oauth2.client.registration.kakao.redirect-uri=${CLOUD_KAKAO_OAUTH_REDIRECT_URI} + +## openai settings +#ai.openai.api-key=${OPENAI_API_KEY} +#ai.openai.chat.options.model=${OPENAI_API_MODEL} +#ai.openai.chat.options.temperature=${OPENAI_API_tmp} \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties new file mode 100644 index 0000000..bdda5c0 --- /dev/null +++ b/src/main/resources/application-local.properties @@ -0,0 +1,14 @@ +## Local mysql settings +spring.datasource.url=${LOCAL_DB_URL} +spring.datasource.username=${LOCAL_DB_USERNAME} +spring.datasource.password=${LOCAL_DB_PASSWORD} + +## LOCAL OAUTH2 +spring.security.oauth2.client.registration.naver.redirect-uri=${LOCAL_NAVER_OAUTH_REDIRECT_URI} +spring.security.oauth2.client.registration.google.redirect-uri=${LOCAL_GOOGLE_OAUTH_REDIRECT_URI} +spring.security.oauth2.client.registration.kakao.redirect-uri=${LOCAL_KAKAO_OAUTH_REDIRECT_URI} + +## openai settings +#ai.openai.api-key=${OPENAI_API_KEY} +#ai.openai.chat.options.model=${OPENAI_API_MODEL} +#ai.openai.chat.options.temperature=${OPENAI_API_tmp} diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..c5f5ddf --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,15 @@ +# Prod mysql settings +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=${PROD_DB_URL} +spring.datasource.username=${PROD_DB_USERNAME} +spring.datasource.password=${PROD_DB_PASSWORD} + +## Prod OAUTH2 +spring.security.oauth2.client.registration.naver.redirect-uri=${CLOUD_NAVER_OAUTH_REDIRECT_URI} +spring.security.oauth2.client.registration.google.redirect-uri=${CLOUD_GOOGLE_OAUTH_REDIRECT_URI} +spring.security.oauth2.client.registration.kakao.redirect-uri=${CLOUD_KAKAO_OAUTH_REDIRECT_URI} + +## openai settings +#ai.openai.api-key=${OPENAI_API_KEY} +#ai.openai.chat.options.model=${OPENAI_API_MODEL} +#ai.openai.chat.options.temperature=${OPENAI_API_tmp} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..20d8468 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,50 @@ +spring.application.name=SearchWeb + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +# mybatis settings +mybatis.mapper-locations=classpath:mapper/*.xml +logging.level.org.mybatis=DEBUG + +#logging.level.org.springframework.security=TRACE +logging.level.org.springframework.security=DEBUG + + +##### Oauth2 session login settings ##### +#naver settings +#registration +spring.security.oauth2.client.registration.naver.client-name=naver +spring.security.oauth2.client.registration.naver.client-id=${NAVER_CLIENT_ID} +spring.security.oauth2.client.registration.naver.client-secret=${NAVER_CLIENT_SECRET} +spring.security.oauth2.client.registration.naver.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.naver.scope=name,email +#provider +spring.security.oauth2.client.provider.naver.authorization-uri=https://nid.naver.com/oauth2.0/authorize +spring.security.oauth2.client.provider.naver.token-uri=https://nid.naver.com/oauth2.0/token +spring.security.oauth2.client.provider.naver.user-info-uri=https://openapi.naver.com/v1/nid/me +spring.security.oauth2.client.provider.naver.user-name-attribute=response + + +#google settings +#registration +spring.security.oauth2.client.registration.google.client-name=google +spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID} +spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET} +spring.security.oauth2.client.registration.google.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.google.scope=profile,email + + +#kakao settings +#registration +spring.security.oauth2.client.registration.kakao.client-name=kakao +spring.security.oauth2.client.registration.kakao.client-id=${KAKAO_CLIENT_ID} +spring.security.oauth2.client.registration.kakao.client-secret=${KAKAO_CLIENT_SECRET} +spring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post +spring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.kakao.scope=profile_nickname, account_email +#provider +spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize +spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token +spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me +spring.security.oauth2.client.provider.kakao.user-name-attribute=id + +#spring.config.import=optional:dotenv:.env