From 2077ef2ef6fa09878be3745bcf669582f3760d4d Mon Sep 17 00:00:00 2001 From: Songyi Kim <52441906+songyi00@users.noreply.github.com> Date: Sun, 10 Nov 2024 19:47:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8A=AC=EB=9E=99=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EC=B1=84=EB=84=90=20=EC=97=B0=EB=8F=99=20(#91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 슬랙 알림 채널 연동 * feat: properties.xml 추가 * chore: webhook uri 재생성 및 노출 제외 * feat: prod logback 분리 --- .github/workflows/cd.yml | 1 + build.gradle | 3 ++ docker-compose.yml | 1 + .../goalpanzi/GoalpanziApplication.java | 16 +++++++-- .../resources/appenders/slack-appender.xml | 34 +++++++++++++++++++ src/main/resources/application-prod.yml | 2 ++ src/main/resources/application.yml | 3 ++ .../{logback-spring.xml => logback-prod.xml} | 7 ++++ src/main/resources/properties.xml | 4 +++ 9 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/appenders/slack-appender.xml rename src/main/resources/{logback-spring.xml => logback-prod.xml} (87%) create mode 100644 src/main/resources/properties.xml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 66d9f125..b5fab306 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -74,6 +74,7 @@ jobs: export OBJECT_STORAGE_ACCESS_KEY_ID=${{ secrets.OBJECT_STORAGE_ACCESS_KEY_ID }} export OBJECT_STORAGE_SECRET_KEY=${{ secrets.OBJECT_STORAGE_SECRET_KEY }} export ENCODED_FIREBASE_ADMIN_SDK=${{ secrets.ENCODED_FIREBASE_ADMIN_SDK }} + export SLACK_WEBHOOK_URI=${{ secrets.SLACK_WEBHOOK_URI }} sudo docker rm -f $(docker ps -qa) diff --git a/build.gradle b/build.gradle index d37dd739..3551686f 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,9 @@ dependencies { // firebase implementation 'com.google.firebase:firebase-admin:9.3.0' + // slack + implementation 'com.github.maricn:logback-slack-appender:1.6.1' + compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' diff --git a/docker-compose.yml b/docker-compose.yml index b13d935f..d41e7d91 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: OBJECT_STORAGE_ACCESS_KEY_ID: ${OBJECT_STORAGE_ACCESS_KEY_ID} OBJECT_STORAGE_SECRET_KEY: ${OBJECT_STORAGE_SECRET_KEY} ENCODED_FIREBASE_ADMIN_SDK: ${ENCODED_FIREBASE_ADMIN_SDK} + SLACK_WEBHOOK_URI: ${SLACK_WEBHOOK_URI} restart: always volumes: - ./logs:/logs diff --git a/src/main/java/com/nexters/goalpanzi/GoalpanziApplication.java b/src/main/java/com/nexters/goalpanzi/GoalpanziApplication.java index 50c0590d..ae8f7423 100644 --- a/src/main/java/com/nexters/goalpanzi/GoalpanziApplication.java +++ b/src/main/java/com/nexters/goalpanzi/GoalpanziApplication.java @@ -1,13 +1,23 @@ package com.nexters.goalpanzi; +import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.util.TimeZone; + @SpringBootApplication public class GoalpanziApplication { - public static void main(String[] args) { - SpringApplication.run(GoalpanziApplication.class, args); - } + public static void main(String[] args) { + var ctx = SpringApplication.run(GoalpanziApplication.class, args); + TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); + var serverPort = ctx.getEnvironment().getProperty("server.port"); + var profile = ctx.getEnvironment().getProperty("spring.profiles.active"); + // startup notification + String banner = String.format("GoalpanziApplication started (profile=%s, port=%s)", profile, serverPort); + System.out.println(banner); + LoggerFactory.getLogger("ServerBoot").info(banner); + } } diff --git a/src/main/resources/appenders/slack-appender.xml b/src/main/resources/appenders/slack-appender.xml new file mode 100644 index 00000000..711743f6 --- /dev/null +++ b/src/main/resources/appenders/slack-appender.xml @@ -0,0 +1,34 @@ + + + + + [%thread] %-5level traceId:"%X{traceId:-}" spanId:"%X{spanId:-}"%n%msg%n + + + ${SLACK_WEBHOOK_URI} + ${SLACK_USERNAME} + ${SLACK_CHANNEL} + :bell: + true + + ! + + + + ERROR + + + + + + + *Server Name:* `${HOSTNAME:-}` %n%msg%n + + + ${SLACK_WEBHOOK_URI} + ${SLACK_USERNAME} + ${SLACK_CHANNEL} + :bell: + true + + diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 6ec905ce..934e235e 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -64,3 +64,5 @@ oauth: iss: https://appleid.apple.com client-id: ${OAUTH_APPLE_CLIENT_ID} +logging: + config: classpath:logback-prod.xml \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c92e1cb8..f04b40db 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,6 @@ +server: + port: 8080 + spring: h2: console: diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-prod.xml similarity index 87% rename from src/main/resources/logback-spring.xml rename to src/main/resources/logback-prod.xml index a9a1b8d5..0706ff53 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-prod.xml @@ -1,5 +1,7 @@ + + @@ -36,5 +38,10 @@ + + + + + diff --git a/src/main/resources/properties.xml b/src/main/resources/properties.xml new file mode 100644 index 00000000..82cc13e2 --- /dev/null +++ b/src/main/resources/properties.xml @@ -0,0 +1,4 @@ + + + +