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 @@ + + + +