فهرست منبع

整合docker-compose

nnkwrik 6 سال پیش
والد
کامیت
7a94f49eae
27فایلهای تغییر یافته به همراه262 افزوده شده و 98 حذف شده
  1. 8 0
      auth-service/Dockerfile
  2. 13 0
      auth-service/src/main/resources/application-dev.yml
  3. 10 0
      auth-service/src/main/resources/application-docker.yml
  4. 2 15
      auth-service/src/main/resources/application.yml
  5. 7 3
      common/src/main/java/io/github/nnkwrik/common/token/RSAKeysReader.java
  6. 2 2
      dev/mysql/shart.sh
  7. 52 22
      docker-compose.yml
  8. 8 0
      eureka/Dockerfile
  9. 6 0
      eureka/src/main/resources/application-dev.yml
  10. 6 0
      eureka/src/main/resources/application-docker.yml
  11. 2 4
      eureka/src/main/resources/application.yml
  12. 8 0
      gateway/Dockerfile
  13. 6 0
      gateway/src/main/resources/application-dev.yml
  14. 6 0
      gateway/src/main/resources/application-docker.yml
  15. 2 7
      gateway/src/main/resources/application.yml
  16. 8 0
      goods-service/Dockerfile
  17. 15 0
      goods-service/src/main/resources/application-dev.yml
  18. 13 0
      goods-service/src/main/resources/application-docker.yml
  19. 2 11
      goods-service/src/main/resources/application.yml
  20. 8 0
      im-service/Dockerfile
  21. 18 0
      im-service/src/main/resources/application-dev.yml
  22. 15 0
      im-service/src/main/resources/application-docker.yml
  23. 2 16
      im-service/src/main/resources/application.yml
  24. 8 0
      user-service/Dockerfile
  25. 18 0
      user-service/src/main/resources/application-dev.yml
  26. 15 0
      user-service/src/main/resources/application-docker.yml
  27. 2 18
      user-service/src/main/resources/application.yml

+ 8 - 0
auth-service/Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:8-jre
+MAINTAINER nnkwrik nnkwrik@gmail.com
+
+ENV SPRING_PROFILE_ACTIVE=docker
+
+COPY target/auth-service-0.0.1-SNAPSHOT.jar /auth-service.jar
+
+ENTRYPOINT ["java","-jar","/auth-service.jar"]

+ 13 - 0
auth-service/src/main/resources/application-dev.yml

@@ -0,0 +1,13 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/
+spring:
+  rabbitmq:
+    host: localhost
+    port: 5672
+    username: guest
+    password: guest
+
+server:
+  port: 8803

+ 10 - 0
auth-service/src/main/resources/application-docker.yml

@@ -0,0 +1,10 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://fangxianyu-eureka:8080/eureka/
+spring:
+  rabbitmq:
+    host: fangxianyu-rabbitmq
+    port: 5672
+    username: guest
+    password: guest

+ 2 - 15
auth-service/src/main/resources/application.yml

@@ -1,19 +1,9 @@
-eureka:
-  client:
-    service-url:
-      defaultZone: http://localhost:8801/eureka/
-
-
 spring:
   application:
     name: auth-service
   profiles:
-    include: secret
-  rabbitmq:
-    host: localhost
-    port: 5672
-    username: guest
-    password: guest
+    include: secret #删掉这行!
+    active: ${SPRING_PROFILE_ACTIVE:dev}
   cloud:
     stream:
       bindings:
@@ -21,9 +11,6 @@ spring:
           destination: register
           content-type: application/json
 
-server:
-  port: 8803
-
 #写入你的小程序信息
 wx:
   miniapp:

+ 7 - 3
common/src/main/java/io/github/nnkwrik/common/token/RSAKeysReader.java

@@ -2,9 +2,12 @@ package io.github.nnkwrik.common.token;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.util.FileCopyUtils;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.security.KeyFactory;
 import java.security.PrivateKey;
@@ -72,10 +75,11 @@ public class RSAKeysReader {
 
     private static String getData(String fileName) {
         String data = "";
+        ClassPathResource cpr = new ClassPathResource(fileName);
         try {
-            File file = new ClassPathResource(fileName).getFile();
-            log.info("试图读取秘钥文件, 文件路径 : [{}]", file.getPath());
-            data = new String(Files.readAllBytes(file.toPath()));
+            byte[] bdata = FileCopyUtils.copyToByteArray(cpr.getInputStream());
+            log.info("试图读取秘钥文件, 文件路径 : [{}]", cpr.getPath());
+            data = new String(bdata, StandardCharsets.UTF_8);
         } catch (IOException e) {
             log.info("文件读取失败");
             e.printStackTrace();

+ 2 - 2
dev/mysql/shart.sh

@@ -3,8 +3,8 @@ cur_dir=`pwd`
 docker stop fangxianyu-mysql
 docker rm fangxianyu-mysql
 
-docker run -d --name fangxianyu-mysql \
+docker run  --name fangxianyu-mysql \
 -v ${cur_dir}/conf:/etc/mysql/conf.d \
 -v ${cur_dir}/data:/var/lib/mysql \
--v ${cur_dir}/log:/var/log/mysql \
 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234  mysql:5.7
+

+ 52 - 22
docker-compose.yml

@@ -11,7 +11,6 @@ services:
     volumes:
     - ./dev/mysql/conf:/etc/mysql/conf.d
     - ./dev/mysql/data:/var/lib/mysql
-    - ./dev/mysql/log:/var/log/mysql
     restart: always
 
   rebbitmq:
@@ -31,24 +30,55 @@ services:
     ports:
     - "6379:6379"
 
-#  eureka:
-#    build: ./eureka
-#    container_name: fangxianyu-eureka
-#    restart: always
-#  zuul:
-#    build: ./zuul
-#    container_name: fangxianyu-zuul
-#    restart: always
-#    depends_on:
-#    - eureka
-#  auth-service:
-#    build: ./auth-service
-#    container_name: fangxianyu-auth-service
-#    restart: always
-#    depends_on:
-#    - eureka
-#    - mysql
-#  goods-service:
-#    build: ./goods-service
-#    container_name: fangxianyu-goods-service
-#    restart: always
+  eureka:
+    build: ./eureka
+    container_name: fangxianyu-eureka
+    restart: always
+  user-service:
+    build: ./user-service
+    container_name: fangxianyu-user-service
+    restart: always
+    depends_on:
+    - mysql
+    - rebbitmq
+    - eureka
+  auth-service:
+    build: ./auth-service
+    container_name: fangxianyu-auth-service
+    restart: always
+    depends_on:
+    - mysql
+    - rebbitmq
+    - eureka
+    - user-service
+  goods-service:
+    build: ./goods-service
+    container_name: fangxianyu-goods-service
+    restart: always
+    depends_on:
+    - mysql
+    - eureka
+    - user-service
+  im-service:
+    build: ./im-service
+    container_name: fangxianyu-im-service
+    restart: always
+    depends_on:
+    - mysql
+    - redis
+    - eureka
+    - user-service
+    - goods-service
+  gateway:
+    build: ./gateway
+    container_name: fangxianyu-gateway
+    ports:
+    - "8080:8080"
+    restart: always
+    depends_on:
+    - eureka
+    - user-service
+    - auth-service
+    - goods-service
+    - im-service
+

+ 8 - 0
eureka/Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:8-jre
+MAINTAINER nnkwrik nnkwrik@gmail.com
+
+ENV SPRING_PROFILE_ACTIVE=docker
+
+COPY target/eureka-0.0.1-SNAPSHOT.jar /eureka.jar
+
+ENTRYPOINT ["java","-jar","/eureka.jar"]

+ 6 - 0
eureka/src/main/resources/application-dev.yml

@@ -0,0 +1,6 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/
+server:
+  port: 8801

+ 6 - 0
eureka/src/main/resources/application-docker.yml

@@ -0,0 +1,6 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://eureka:8080/eureka/
+server:
+  port: 8080

+ 2 - 4
eureka/src/main/resources/application.yml

@@ -1,12 +1,10 @@
 eureka:
   client:
-    service-url:
-      defaultZone: http://localhost:8801/eureka/
     register-with-eureka: false
   server:
     enable-self-preservation: false
 spring:
   application:
     name: eureka
-server:
-  port: 8801
+  profiles:
+    active: ${SPRING_PROFILE_ACTIVE:dev}

+ 8 - 0
gateway/Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:8-jre
+MAINTAINER nnkwrik nnkwrik@gmail.com
+
+ENV SPRING_PROFILE_ACTIVE=docker
+
+COPY target/gateway-0.0.1-SNAPSHOT.jar /gateway.jar
+
+ENTRYPOINT ["java","-jar","/gateway.jar"]

+ 6 - 0
gateway/src/main/resources/application-dev.yml

@@ -0,0 +1,6 @@
+server:
+  port: 8080
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/

+ 6 - 0
gateway/src/main/resources/application-docker.yml

@@ -0,0 +1,6 @@
+server:
+  port: 8080
+eureka:
+  client:
+    service-url:
+      defaultZone: http://fangxianyu-eureka:8080/eureka/

+ 2 - 7
gateway/src/main/resources/application.yml

@@ -1,13 +1,8 @@
-server:
-  port: 8080
-eureka:
-  client:
-    service-url:
-      defaultZone: http://localhost:8801/eureka/
-
 spring:
   application:
     name: cloud-gateway
+  profiles:
+    active: ${SPRING_PROFILE_ACTIVE:dev}
   cloud:
     gateway:
       discovery:

+ 8 - 0
goods-service/Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:8-jre
+MAINTAINER nnkwrik nnkwrik@gmail.com
+
+ENV SPRING_PROFILE_ACTIVE=docker
+
+COPY target/goods-service-0.0.1-SNAPSHOT.jar /goods-service.jar
+
+ENTRYPOINT ["java","-jar","/goods-service.jar"]

+ 15 - 0
goods-service/src/main/resources/application-dev.yml

@@ -0,0 +1,15 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/
+spring:
+  datasource:
+    url: jdbc:mysql://localhost:3306/goods_service
+    username: root
+    password: 1234
+    driver-class-name: com.mysql.cj.jdbc.Driver
+
+server:
+  port: 8804
+
+

+ 13 - 0
goods-service/src/main/resources/application-docker.yml

@@ -0,0 +1,13 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://fangxianyu-eureka:8080/eureka/
+spring:
+  datasource:
+    url: jdbc:mysql://fangxianyu-mysql:3306/goods_service
+    username: root
+    password: 1234
+    driver-class-name: com.mysql.cj.jdbc.Driver
+
+
+

+ 2 - 11
goods-service/src/main/resources/application.yml

@@ -1,23 +1,14 @@
-eureka:
-  client:
-    service-url:
-      defaultZone: http://localhost:8801/eureka/
 spring:
   application:
     name: goods-service
-  datasource:
-    url: jdbc:mysql://localhost:3306/goods_service
-    username: root
-    password: 1234
-    driver-class-name: com.mysql.cj.jdbc.Driver
   jackson:
     default-property-inclusion: non_null  #如果值为null,构造json时不加入
     date-format: yyyy-MM-dd HH:mm    #指定Json中Date对象的传输格式.对于DTO还是使用以往的方式
     locale: zh_CN
     time-zone: Asia/Shanghai
+  profiles:
+    active: ${SPRING_PROFILE_ACTIVE:dev}
 
-server:
-  port: 8804
 
 mybatis:
   configuration:

+ 8 - 0
im-service/Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:8-jre
+MAINTAINER nnkwrik nnkwrik@gmail.com
+
+ENV SPRING_PROFILE_ACTIVE=docker
+
+COPY target/im-service-0.0.1-SNAPSHOT.jar /im-service.jar
+
+ENTRYPOINT ["java","-jar","/im-service.jar"]

+ 18 - 0
im-service/src/main/resources/application-dev.yml

@@ -0,0 +1,18 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/
+
+spring:
+  datasource:
+    url: jdbc:mysql://localhost:3306/im_service
+    username: root
+    password: 1234
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  redis:
+    port: 6379
+    host: localhost
+    timeout: 30s
+
+server:
+  port: 8805

+ 15 - 0
im-service/src/main/resources/application-docker.yml

@@ -0,0 +1,15 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://fangxianyu-eureka:8080/eureka/
+
+spring:
+  datasource:
+    url: jdbc:mysql://fangxianyu-mysql:3306/im_service
+    username: root
+    password: 1234
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  redis:
+    port: 6379
+    host: fangxianyu-redis
+    timeout: 30s

+ 2 - 16
im-service/src/main/resources/application.yml

@@ -1,27 +1,13 @@
-eureka:
-  client:
-    service-url:
-      defaultZone: http://localhost:8801/eureka/
 spring:
   application:
     name: im-service
-  datasource:
-    url: jdbc:mysql://localhost:3306/im_service
-    username: root
-    password: 1234
-    driver-class-name: com.mysql.cj.jdbc.Driver
-  redis:
-    port: 6379
-    host: localhost
-    timeout: 30s
   jackson:
     default-property-inclusion: non_null  #如果值为null,构造json时不加入
     date-format: yyyy-MM-dd HH:mm    #指定Json中Date对象的传输格式.对于DTO还是使用以往的方式
     locale: zh_CN
     time-zone: Asia/Shanghai
-
-server:
-  port: 8805
+  profiles:
+    active: ${SPRING_PROFILE_ACTIVE:dev}
 
 mybatis:
   configuration:

+ 8 - 0
user-service/Dockerfile

@@ -0,0 +1,8 @@
+FROM openjdk:8-jre
+MAINTAINER nnkwrik nnkwrik@gmail.com
+
+ENV SPRING_PROFILE_ACTIVE=docker
+
+COPY target/user-service-0.0.1-SNAPSHOT.jar /user-service.jar
+
+ENTRYPOINT ["java","-jar","/user-service.jar"]

+ 18 - 0
user-service/src/main/resources/application-dev.yml

@@ -0,0 +1,18 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/
+spring:
+  datasource:
+    url: jdbc:mysql://localhost:3306/user_service
+    username: root
+    password: 1234
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  rabbitmq:
+    host: localhost
+    port: 5672
+    username: guest
+    password: guest
+
+server:
+  port: 8802

+ 15 - 0
user-service/src/main/resources/application-docker.yml

@@ -0,0 +1,15 @@
+eureka:
+  client:
+    service-url:
+      defaultZone: http://fangxianyu-eureka:8080/eureka/
+spring:
+  datasource:
+    url: jdbc:mysql://fangxianyu-mysql:3306/user_service
+    username: root
+    password: 1234
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  rabbitmq:
+    host: fangxianyu-rabbitmq
+    port: 5672
+    username: guest
+    password: guest

+ 2 - 18
user-service/src/main/resources/application.yml

@@ -1,27 +1,14 @@
-eureka:
-  client:
-    service-url:
-      defaultZone: http://localhost:8801/eureka/
-
 spring:
   application:
     name: user-service
-  datasource:
-    url: jdbc:mysql://localhost:3306/user_service
-    username: root
-    password: 1234
-    driver-class-name: com.mysql.cj.jdbc.Driver
-  rabbitmq:
-    host: localhost
-    port: 5672
-    username: guest
-    password: guest
   cloud:
     stream:
       bindings:
         register-input:
           destination: register
           group: registerGroup
+  profiles:
+    active: ${SPRING_PROFILE_ACTIVE:dev}
 
 mybatis:
   configuration:
@@ -31,6 +18,3 @@ logging:
   level:
     org.springframework.web: info
     io.github.nnkwrik.userservice: debug
-
-server:
-  port: 8802