From e97d82cadd1137c03bc450a9d4f16167163bf6f5 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Mon, 30 Sep 2024 22:50:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Refac:=20yml=20=EB=B6=84=EB=A6=AC=20?= =?UTF-8?q?=EA=B7=9C=EC=B9=99=20=EB=B3=80=EA=B2=BD(=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20->=20=EA=B8=B0=EB=8A=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - src/main/resources/application-auth.yml | 19 +++++++ src/main/resources/application-db.yml | 76 +++++++++++++++++++++++++ src/main/resources/application-doc.yml | 14 +++++ src/main/resources/application.yml | 32 +++++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-auth.yml create mode 100644 src/main/resources/application-db.yml create mode 100644 src/main/resources/application-doc.yml create mode 100644 src/main/resources/application.yml diff --git a/.gitignore b/.gitignore index 439d796c..4496bc32 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,5 @@ out/ ### VS Code ### .vscode/ -/src/main/resources/**/*.yml src/main/resources/static/index.html .env \ No newline at end of file diff --git a/src/main/resources/application-auth.yml b/src/main/resources/application-auth.yml new file mode 100644 index 00000000..22ea8de3 --- /dev/null +++ b/src/main/resources/application-auth.yml @@ -0,0 +1,19 @@ +oauth2: # default + google: + client-id: ${GOOGLE_CLIENT_ID} + client-secret: ${GOOGLE_CLIENT_SECRET} + redirect-uri: ${GOOGLE_DEV_REDIRECT_URI} + token-uri: https://oauth2.googleapis.com/token + userinfo-uri: https://www.googleapis.com/oauth2/v3/userinfo +jwt: + secret: ${JWT_SECRET:aelakjfliwuebnkjshlkjaejdkjsjylakejhfksjdaelakjfliwuebnkjshlkjaejdkjsjylakejhfksjd} + access-token-expiration: 3600000 + refresh-token-expiration: 604800000 +--- +spring: + config: + activate: + on-profile: prod +oauth2: + google: + redirect-uri: ${GOOGLE_PROD_REDIRECT_URI} \ No newline at end of file diff --git a/src/main/resources/application-db.yml b/src/main/resources/application-db.yml new file mode 100644 index 00000000..a6cc44f0 --- /dev/null +++ b/src/main/resources/application-db.yml @@ -0,0 +1,76 @@ +spring: #default, test configuration (H2) + datasource: + url: jdbc:h2:mem:gdsc + username: sa + password: + driver-class-name: org.h2.Driver + jpa: + hibernate: + ddl-auto: create + show-sql: true + database-platform: org.hibernate.dialect.H2Dialect + properties: + hibernate: + default_batch_fetch_size: 100 + data: + redis: + host: 127.0.0.1 + port: 6379 +--- +spring: # mysql 공통 + config: + activate: + on-profile: local, dev, prod + datasource.driver-class-name: com.mysql.cj.jdbc.Driver + jpa.database-platform: org.hibernate.dialect.MySQL8Dialect +--- +spring: + config: + activate: + on-profile: local + datasource: + url: jdbc:mysql://localhost:3306/gdsc + username: root + password: 1234 + jpa: + hibernate: + ddl-auto: update + sql: + init: + mode: never +--- +spring: + config: + activate: + on-profile: dev + datasource: + url: ${DEV_DB_PATH} + username: ${DEV_DB_USERNAME} + password: ${DEV_DB_PASSWORD} + jpa: + hibernate: + ddl-auto: update + sql: + init: + mode: never + data: + redis: + host: ${REDIS_HOST} +--- +spring: + config: + activate: + on-profile: prod + datasource: + url: ${PROD_DB_PATH} + username: ${PROD_DB_USERNAME} + password: ${PROD_DB_PASSWORD} + jpa: + hibernate: + ddl-auto: none + sql: + init: + mode: never + data: + redis: + host: ${REDIS_HOST} \ No newline at end of file diff --git a/src/main/resources/application-doc.yml b/src/main/resources/application-doc.yml new file mode 100644 index 00000000..8a93bd6c --- /dev/null +++ b/src/main/resources/application-doc.yml @@ -0,0 +1,14 @@ +springdoc: + swagger-ui: + path: /api-docs + operations-sorter: alpha + paths-to-match: /api/** + use-fqn: true +--- +spring: + config: + activate: + on-profile: prod +springdoc: + api-docs: + enabled: false \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 00000000..b6452650 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,32 @@ +spring: + profiles: + include: + - db + - auth + - doc + cloud: + aws: + credentials: + access-key: ${AWS_ACCESS_KEY:default} + secret-key: ${AWS_SECRET_KEY:default} + region: + static: ${AWS_REGION:default} + s3: + bucket: ${AWS_S3_BUCKET:default} + stack: + auto: false + mail: + host: smtp.gmail.com + port: ${SMTP_PORT:default} + username: ${SMTP_USERNAME:default} + password: ${SMTP_PASSWORD:default} + properties: + mail: + smtp: + auth: true + starttls: + enable: true +logging: + discord: + webhook-url: ${DISCORD_WEBHOOK_URL:default} + From ddc45e76a8c8f46a43f1a4f721a86c81b1a7cbe3 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Mon, 30 Sep 2024 23:06:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C,=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-dev.yml | 13 +------------ src/main/resources/application-auth.yml | 6 +++--- src/main/resources/application.yml | 2 +- .../OfficialHomepageApplicationTests.java | 3 --- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test-dev.yml b/.github/workflows/test-dev.yml index fb47198d..521346b0 100644 --- a/.github/workflows/test-dev.yml +++ b/.github/workflows/test-dev.yml @@ -10,12 +10,9 @@ name: Test dev branch on: pull_request: branches: [ "dev" ] - - jobs: test: runs-on: ubuntu-latest - permissions: write-all # set up java @@ -27,14 +24,6 @@ jobs: java-version: '17' distribution: 'temurin' - # set up application file - - name: Create application.yml - run: | - mkdir -p ./src/main/resources - cd ./src/main/resources - echo "${{ secrets.APPLICATION }}" > application.yml - echo "${{ secrets.APPLICATION_TEST }}" > application-test.yml - # apply caching - name: Gradle Caching uses: actions/cache@v3 @@ -50,7 +39,7 @@ jobs: - name: Setup Gradle run: | chmod +x ./gradlew - ./gradlew clean build -Pprofile=test + ./gradlew clean build - name: Publish Test Result uses: EnricoMi/publish-unit-test-result-action@v1 diff --git a/src/main/resources/application-auth.yml b/src/main/resources/application-auth.yml index 22ea8de3..116805d9 100644 --- a/src/main/resources/application-auth.yml +++ b/src/main/resources/application-auth.yml @@ -1,8 +1,8 @@ oauth2: # default google: - client-id: ${GOOGLE_CLIENT_ID} - client-secret: ${GOOGLE_CLIENT_SECRET} - redirect-uri: ${GOOGLE_DEV_REDIRECT_URI} + client-id: ${GOOGLE_CLIENT_ID:default} + client-secret: ${GOOGLE_CLIENT_SECRET:default} + redirect-uri: ${GOOGLE_DEV_REDIRECT_URI:default} token-uri: https://oauth2.googleapis.com/token userinfo-uri: https://www.googleapis.com/oauth2/v3/userinfo jwt: diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b6452650..e66c512b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: auto: false mail: host: smtp.gmail.com - port: ${SMTP_PORT:default} + port: ${SMTP_PORT:0000} username: ${SMTP_USERNAME:default} password: ${SMTP_PASSWORD:default} properties: diff --git a/src/test/java/com/gdsc_knu/official_homepage/OfficialHomepageApplicationTests.java b/src/test/java/com/gdsc_knu/official_homepage/OfficialHomepageApplicationTests.java index 53cf4964..d58a5b31 100644 --- a/src/test/java/com/gdsc_knu/official_homepage/OfficialHomepageApplicationTests.java +++ b/src/test/java/com/gdsc_knu/official_homepage/OfficialHomepageApplicationTests.java @@ -5,9 +5,6 @@ import org.springframework.test.context.TestPropertySource; @SpringBootTest -@TestPropertySource(properties = { - "spring.config.location = src/main/resources/application.yml, src/main/resources/application-test.yml" -}) class OfficialHomepageApplicationTests { @Test From f9ac4716b7d62f9601fffc3bc152b10b8dc43333 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Mon, 30 Sep 2024 23:37:56 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20dev=20=EC=84=9C=EB=B2=84=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C=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-dev.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index ee94911b..4a9dfae5 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -10,12 +10,9 @@ name: Deploy dev branch on: push: branches: [ "dev" ] - - jobs: build: runs-on: ubuntu-latest - permissions: contents: read @@ -31,10 +28,7 @@ jobs: # set up application file - name: Create application.yml run: | - mkdir -p ./src/main/resources - cd ./src/main/resources - echo "${{ secrets.APPLICATION }}" > application.yml - echo "${{ secrets.APPLICATION_PROD }}" > application-prod.yml + echo "${{ secrets.ENV }}" >> ./env # apply caching - name: Gradle Caching @@ -51,7 +45,7 @@ jobs: - name: Setup Gradle run: | chmod +x ./gradlew - ./gradlew clean build -x test -Pprofile=prod + ./gradlew clean build -x test -Pprofile=dev # login dockerhub - name: docker login