From 78c5fae80a9a06d996c927eaa9f9eb4c46ba433f Mon Sep 17 00:00:00 2001 From: gabang2 Date: Sat, 1 Jun 2024 14:40:59 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80:=20firebase=20key=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 8 ++++++++ Dockerfile | 1 + .../project/backend/global/config/FirebaseConfig.java | 11 ++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 28e341c..aee7fe8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,14 @@ jobs: java-version: '11' distribution: "adopt" + - name: create firebase key + run: | + cd ./src/main/resources + ls -a . + touch ./firebase-service-key.json + echo "${{ secrets.FIREBASE_KEY }}" > ./firebase-service-key.json + shell: bash + - name: Build with Gradle run: | chmod +x ./gradlew diff --git a/Dockerfile b/Dockerfile index 28e6b79..22a0003 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ COPY ${JAR_FILE} app.jar # firebase-service-key.json 파일을 컨테이너로 복사 COPY src/main/resources/firebase-service-key.json /app/resources/firebase-service-key.json +COPY src/main/resources/firebase-service-key.json /app/src/main/resources/firebase-service-key.json # 애플리케이션 실행 ENTRYPOINT ["java", "-jar", "/app.jar"] diff --git a/src/main/java/project/backend/global/config/FirebaseConfig.java b/src/main/java/project/backend/global/config/FirebaseConfig.java index 15e6371..ebc13ff 100644 --- a/src/main/java/project/backend/global/config/FirebaseConfig.java +++ b/src/main/java/project/backend/global/config/FirebaseConfig.java @@ -5,21 +5,18 @@ import com.google.firebase.FirebaseOptions; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; -import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; @Configuration public class FirebaseConfig { @Bean public FirebaseApp initializeFirebaseApp() throws IOException { - String firebaseConfig = System.getenv("FCM_SECRET"); - if (firebaseConfig == null) { - throw new IOException("FCM_SECRET environment variable is not set."); - } - - ByteArrayInputStream serviceAccount = new ByteArrayInputStream(firebaseConfig.getBytes()); + ClassPathResource resource = new ClassPathResource("firebase-service-key.json"); + InputStream serviceAccount = resource.getInputStream(); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount))