From 3a6b192789805f1770867b1f33b1e0bd99d05cf2 Mon Sep 17 00:00:00 2001 From: SR Date: Fri, 5 Aug 2022 17:04:51 +0900 Subject: [PATCH] fix: fix application.yml setting for using .env --- .gitignore | 4 ++- Dockerfile | 4 +-- docker-compose.yml | 32 +++++++++++++++---- nginx/Dockerfile | 4 +-- nginx/nginx.conf | 4 +-- .../global/config/SpringFoxConfig.java | 2 +- src/main/resources/application.yml | 13 +++++--- 7 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 8b50228..149af72 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,6 @@ out/ src/main/resources/application.properties src/main/resources/application-oauth.properties src/main/resources/application-cloud.properties -/settings/.env \ No newline at end of file +src/main/resources/application-springboot.yml +/.env +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3234dd8..be3ca9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM openjdk:17-jdk-slim -ADD ./build/libs/*.jar app.jar +ADD ./build/libs/backend_e-weather-0.0.1-SNAPSHOT.jar app.jar -CMD ["java", "-jar", "app.jar"] \ No newline at end of file +CMD java -jar -Dspring.profiles.active=${active} app.jar \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5556717..9e89d81 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,43 @@ version: "3" services: - backend: + server1: build: context: . dockerfile: Dockerfile + image: spring + container_name: server1 ports: - - 8080:8080 + - 8082:8082 volumes: - ./:/app working_dir: /app - expose: - - 8080 env_file: - - ./settings/.env + - .env + environment: + active: prod1 + + server2: + build: + context: . + dockerfile: Dockerfile + image: spring + container_name: server2 + ports: + - 8083:8083 + volumes: + - ./:/app + working_dir: /app + env_file: + - .env + environment: + active: prod2 + nginx: build: ./nginx ports: - 80:80 depends_on: - - backend + - server1 + - server2 diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 778fdc0..4db05b5 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,6 +1,6 @@ FROM nginx:latest -RUN rm /etc/nginx/conf.d/default.conf -COPY nginx.conf /etc/nginx/conf.d +#RUN rm /etc/nginx/conf.d/default.conf +#COPY nginx.conf /etc/nginx/conf.d CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index bffec31..45a7889 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,11 +1,11 @@ proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off; upstream api { - server backend:8080; + server spring:8080; } server { - listen 80 default_server; + listen 8080 default_server; charset utf-8; server_name _; diff --git a/src/main/java/efub/team4/backend_eweather/global/config/SpringFoxConfig.java b/src/main/java/efub/team4/backend_eweather/global/config/SpringFoxConfig.java index 1d94efa..4361f4f 100644 --- a/src/main/java/efub/team4/backend_eweather/global/config/SpringFoxConfig.java +++ b/src/main/java/efub/team4/backend_eweather/global/config/SpringFoxConfig.java @@ -22,8 +22,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration -//@EnableOpenApi @EnableSwagger2 +@Profile(value = "dev") public class SpringFoxConfig { public static final Contact DEFAULT_CONTACT = new Contact( diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 391cf9f..02630bc 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,7 @@ +application: + version: 1.0.0 + title: eweather + cloud: aws: credentials: @@ -10,6 +14,10 @@ cloud: stack: auto: 'false' spring: + config: + import: + - optional:file:.env[.properties] + - classpath:/application-springboot.yml jpa: generate-ddl: 'false' hibernate: @@ -19,8 +27,6 @@ spring: enable_lazy_load_no_trans: 'true' format_sql: 'false' database: mysql - profiles: - include: oauth datasource: driver-class-name: com.mysql.cj.jdbc.Driver password: ${DATABASE_PASSWORD} @@ -60,8 +66,5 @@ cors: allowed-methods: ${CORS_ALLOWED_METHODS} allowed-headers: ${CORS_ALLOWED_HEADERS} max-age: ${CORS_MAX_AGE} -application: - version: 1.0.0 - title: eweather jwt: secret: ${JWT_SECRET}