From a66e3cd7e00a01411084f98905641377b08e6518 Mon Sep 17 00:00:00 2001 From: yennanliu Date: Sun, 18 Feb 2024 11:12:01 +0800 Subject: [PATCH 1/2] add BE app2 in docker-compose, update config, nginx conf --- .../src/main/resources/application.properties | 2 +- SpringDataPlatform/docker-compose.yml | 34 ++++++++++++++----- SpringDataPlatform/nginx/nginx.conf | 4 +-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/SpringDataPlatform/backend/DataPlatform/FlinkRestService/src/main/resources/application.properties b/SpringDataPlatform/backend/DataPlatform/FlinkRestService/src/main/resources/application.properties index de4a0f685..de70959e6 100644 --- a/SpringDataPlatform/backend/DataPlatform/FlinkRestService/src/main/resources/application.properties +++ b/SpringDataPlatform/backend/DataPlatform/FlinkRestService/src/main/resources/application.properties @@ -1,5 +1,5 @@ # spring -server.port=9999 +server.port=${SERVER_PORT:9999} # upload file server.tomcat.max-http-form-post-size=20MB diff --git a/SpringDataPlatform/docker-compose.yml b/SpringDataPlatform/docker-compose.yml index 770f55140..8837b168c 100644 --- a/SpringDataPlatform/docker-compose.yml +++ b/SpringDataPlatform/docker-compose.yml @@ -1,11 +1,12 @@ version: '3' services: - app: + app1: restart: always - build: ./backend/DataPlatform + build: ./backend/DataPlatform/FlinkRestService # backend dockerfile working_dir: /app volumes: - ./backend/DataPlatform:/app + - ~/.m2/repository:/root/.m2/repository # Mount Maven local repository ports: - "9999:9999" environment: @@ -16,7 +17,27 @@ services: - SPRING_JPA_SHOW_SQL=true - SPRING_JPA_HIBERNATE_DDL_AUTO=create # Set the Hibernate ddl-auto property here - SPRING_JPA_GENERATE_DDL=true - #- JAVA_HOME=/usr/local/openjdk-11 + depends_on: + - mysql + command: mvn clean spring-boot:run -DskipTests + + app2: + restart: always + build: ./backend/DataPlatform/FlinkRestService # backend dockerfile + working_dir: /app + volumes: + - ./backend/DataPlatform:/app + - ~/.m2/repository:/root/.m2/repository # Mount Maven local repository + ports: + - "9998:9998" # Port mapping for app2 + environment: + - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/data_platform + - SPRING_DATASOURCE_USERNAME=root + - SPRING_DATASOURCE_PASSWORD= + - SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.mysql.cj.jdbc.Driver + - SPRING_JPA_SHOW_SQL=true + - SPRING_JPA_HIBERNATE_DDL_AUTO=create # Set the Hibernate ddl-auto property here + - SPRING_JPA_GENERATE_DDL=true depends_on: - mysql command: mvn clean spring-boot:run -DskipTests @@ -35,8 +56,6 @@ services: image: mysql:5.7 restart: always environment: - #https://stackoverflow.com/questions/66831863/mysql-docker-container-keeps-restarting - #MYSQL_USER: root # NO NEED to create root user, since it is created automatically MYSQL_DATABASE: data_platform MYSQL_ROOT_PASSWORD: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" @@ -49,14 +68,13 @@ services: image: nginx restart: always ports: - #- "8080:80" - "8081:8081" volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx/index.html:/app/html:ro depends_on: - - app - #- app2 + - app1 + - app2 volumes: mysql-data: \ No newline at end of file diff --git a/SpringDataPlatform/nginx/nginx.conf b/SpringDataPlatform/nginx/nginx.conf index 6761e0140..d05a9e78b 100644 --- a/SpringDataPlatform/nginx/nginx.conf +++ b/SpringDataPlatform/nginx/nginx.conf @@ -12,8 +12,8 @@ http { keepalive_timeout 65; upstream dataPlatform { - server app:9999; - #server app2:9998; + server app1:9999; + server app2:9998; } server { From 62e020f34ae2ffdd03f82a88c948dc83e9390ae5 Mon Sep 17 00:00:00 2001 From: yennanliu Date: Sun, 18 Feb 2024 17:25:05 +0800 Subject: [PATCH 2/2] add server port in docker-compose env var, make BE app 2 can run --- SpringDataPlatform/README.md | 6 ++++++ SpringDataPlatform/docker-compose.yml | 2 ++ 2 files changed, 8 insertions(+) diff --git a/SpringDataPlatform/README.md b/SpringDataPlatform/README.md index fb7d643cc..49f2ca8a6 100644 --- a/SpringDataPlatform/README.md +++ b/SpringDataPlatform/README.md @@ -53,6 +53,12 @@ ARCHITECTURE : ```bash docker-compose up + +# rebuild (use updated java code) and run +docker-compose up --build + +# restart +docker-compose restart ``` diff --git a/SpringDataPlatform/docker-compose.yml b/SpringDataPlatform/docker-compose.yml index 8837b168c..2a721f6b1 100644 --- a/SpringDataPlatform/docker-compose.yml +++ b/SpringDataPlatform/docker-compose.yml @@ -17,6 +17,7 @@ services: - SPRING_JPA_SHOW_SQL=true - SPRING_JPA_HIBERNATE_DDL_AUTO=create # Set the Hibernate ddl-auto property here - SPRING_JPA_GENERATE_DDL=true + - SERVER_PORT=9999 depends_on: - mysql command: mvn clean spring-boot:run -DskipTests @@ -38,6 +39,7 @@ services: - SPRING_JPA_SHOW_SQL=true - SPRING_JPA_HIBERNATE_DDL_AUTO=create # Set the Hibernate ddl-auto property here - SPRING_JPA_GENERATE_DDL=true + - SERVER_PORT=9998 depends_on: - mysql command: mvn clean spring-boot:run -DskipTests