From 0d943f9bb3d82b218bff60d6a909c5feb768f128 Mon Sep 17 00:00:00 2001 From: minjoon-98 <4kmj54321@gmail.com> Date: Mon, 22 Jul 2024 07:34:52 +0900 Subject: [PATCH] chore: Added firebase config path environment variable to Docker entrypoint --- Dockerfile | 2 +- .../ongjong/namanmoo/config/FirebaseConfig.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index ee1aaa2..2c35532 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,4 +19,4 @@ ENV FFMPEG_PATH=/usr/bin/ffmpeg ENV FFPROBE_PATH=/usr/bin/ffprobe # 기본 프로파일 실행 명령어 -ENTRYPOINT ["java", "-jar", "mooluck-spring.jar", "-Dspring.profiles.active=docker", "-Duser.timezone=Asia/Seoul"] \ No newline at end of file +ENTRYPOINT ["java", "-Dfirebase.config.path=/app/mooluck-fcm-firebase-adminsdk.json", "-jar", "mooluck-spring.jar", "-Dspring.profiles.active=docker", "-Duser.timezone=Asia/Seoul"] \ No newline at end of file diff --git a/src/main/java/ongjong/namanmoo/config/FirebaseConfig.java b/src/main/java/ongjong/namanmoo/config/FirebaseConfig.java index e4a541c..4da9c00 100644 --- a/src/main/java/ongjong/namanmoo/config/FirebaseConfig.java +++ b/src/main/java/ongjong/namanmoo/config/FirebaseConfig.java @@ -7,22 +7,24 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @Configuration public class FirebaseConfig { + @Value("${firebase.config.path}") private String firebaseConfigPath; @Bean public FirebaseApp initializeFirebase() throws IOException { - // FirebaseApp 인스턴스가 이미 존재하는지 확인 if (FirebaseApp.getApps().isEmpty()) { - InputStream serviceAccount = getClass().getClassLoader().getResourceAsStream(firebaseConfigPath); - - if (serviceAccount == null) { - throw new RuntimeException("Firebase config file not found" + firebaseConfigPath); + InputStream serviceAccount; + try { + serviceAccount = new FileInputStream(firebaseConfigPath); + } catch (Exception e) { + throw new IOException("Could not open Firebase config file: " + firebaseConfigPath); } FirebaseOptions options = new FirebaseOptions.Builder() @@ -33,4 +35,4 @@ public FirebaseApp initializeFirebase() throws IOException { } return FirebaseApp.getInstance(); } -} +} \ No newline at end of file