From c778bd5291a83fbd2d01be2638dce897785814f2 Mon Sep 17 00:00:00 2001 From: dingzhaojun Date: Sun, 29 Oct 2023 19:48:16 +0800 Subject: [PATCH] update compose --- compose-demo01.yml => compose-demo01-jib.yml | 10 +-- compose-demo01-jvm.yml | 26 ++++++++ compose-demo01-native.yml | 26 ++++++++ pom.xml | 62 +++++++++++++++++-- readme.txt | 10 ++- .../demo/controller/UserController.java | 15 ++++- 6 files changed, 136 insertions(+), 13 deletions(-) rename compose-demo01.yml => compose-demo01-jib.yml (74%) create mode 100644 compose-demo01-jvm.yml create mode 100644 compose-demo01-native.yml diff --git a/compose-demo01.yml b/compose-demo01-jib.yml similarity index 74% rename from compose-demo01.yml rename to compose-demo01-jib.yml index 5e93f3b..51cc2ee 100644 --- a/compose-demo01.yml +++ b/compose-demo01-jib.yml @@ -1,9 +1,9 @@ version: '3.9' -name: demo01 +name: demo01-jib services: - demo01: - image: docker.io/library/demo01:1.0 - container_name: demo01 + demo01-jib: + image: svn.youshengyun.com:9924/demo01-jib:1.0 + container_name: demo01-jib restart: unless-stopped extra_hosts: - "host.docker.internal:host-gateway" @@ -11,6 +11,8 @@ services: - y9-share-net ports: - "7055:7055" + environment: + 'server.servlet.context-path': '/demo01' labels: - "traefik.enable=true" - "traefik.http.routers.demo01.entrypoints=web" diff --git a/compose-demo01-jvm.yml b/compose-demo01-jvm.yml new file mode 100644 index 0000000..1a1b31b --- /dev/null +++ b/compose-demo01-jvm.yml @@ -0,0 +1,26 @@ +version: '3.9' +name: demo01-jvm +services: + demo01-jvm: + image: svn.youshengyun.com:9924/demo01-jvm:1.0 + container_name: demo01-jvm + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - y9-share-net + ports: + - "17055:7055" + environment: + 'server.servlet.context-path': '/demo02' + labels: + - "traefik.enable=true" + - "traefik.http.routers.demo02.entrypoints=web" + - "traefik.http.routers.demo02.rule=PathPrefix(`/demo02`)" + #- "traefik.http.services.demo01.loadbalancer.server.scheme=http" + #- "traefik.http.services.demo01.loadbalancer.server.port=7055" + #- "traefik.docker.network=y9-share-net" + +networks: + y9-share-net: + external: true \ No newline at end of file diff --git a/compose-demo01-native.yml b/compose-demo01-native.yml new file mode 100644 index 0000000..cdd6227 --- /dev/null +++ b/compose-demo01-native.yml @@ -0,0 +1,26 @@ +version: '3.9' +name: demo01-native +services: + demo01-native: + image: svn.youshengyun.com:9924/demo01-native:1.0 + container_name: demo01-native + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - y9-share-net + ports: + - "27055:7055" + environment: + 'server.servlet.context-path': '/demo03' + labels: + - "traefik.enable=true" + - "traefik.http.routers.demo03.entrypoints=web" + - "traefik.http.routers.demo03.rule=PathPrefix(`/demo03`)" + #- "traefik.http.services.demo01.loadbalancer.server.scheme=http" + #- "traefik.http.services.demo01.loadbalancer.server.port=7055" + #- "traefik.docker.network=y9-share-net" + +networks: + y9-share-net: + external: true \ No newline at end of file diff --git a/pom.xml b/pom.xml index 77b75c4..593ac2f 100644 --- a/pom.xml +++ b/pom.xml @@ -21,11 +21,6 @@ - - com.ecwid.consul - consul-api - 1.4.5 - org.springframework.cloud spring-cloud-dependencies @@ -89,6 +84,7 @@ org.graalvm.buildtools native-maven-plugin + org.springframework.boot spring-boot-maven-plugin @@ -99,12 +95,60 @@ lombok + net.risesoft.demo.Demo01Application + + + false + 17 + + svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version} + true + + + + publisher + 83204585 + + + + jib + + + + com.google.cloud.tools + jib-maven-plugin + 3.4.0 + + false + + svn.youshengyun.com:9923/${project.artifactId}-jib + + ${project.version} + + + publisher + 83204585 + + + + + + install + + build + + + + + + + native @@ -135,7 +179,15 @@ 17.0.9 --enable-preview + svn.youshengyun.com:9923/${project.artifactId}-native:${project.version} + true + + + publisher + 83204585 + + diff --git a/readme.txt b/readme.txt index 2b144db..d6d2ab3 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,16 @@ +./mvnw.cmd clean install -Pjib -Dmaven.test.skip=true +./mvnw.cmd clean spring-boot:build-image -Dmaven.test.skip=true ./mvnw.cmd clean spring-boot:build-image -Pnative -Dmaven.test.skip=true docker image ls -docker run --name demo01 --net y9-share-net -ti -p 7055:7055 demo01:1.0 +docker run --name demo01-jib --net y9-share-net -ti -p 7055:7055 svn.youshengyun.com:9924/demo01-jib:1.0 +docker run --name demo01-jvm --net y9-share-net -ti -p 17055:7055 svn.youshengyun.com:9924/demo01-jvm:1.0 +docker run --name demo01-native --net y9-share-net -ti -p 27055:7055 svn.youshengyun.com:9924/demo01-native:1.0 -docker compose -f compose-demo01.yml up -d +docker compose -f compose-demo01-jib.yml up -d +docker compose -f compose-demo01-jvm.yml up -d +docker compose -f compose-demo01-native.yml up -d #最好在x64 Native Tools Command Prompt for VS 2022中打开 ./mvnw.cmd native:compile -Pnative \ No newline at end of file diff --git a/src/main/java/net/risesoft/demo/controller/UserController.java b/src/main/java/net/risesoft/demo/controller/UserController.java index 49ba43e..22332e3 100644 --- a/src/main/java/net/risesoft/demo/controller/UserController.java +++ b/src/main/java/net/risesoft/demo/controller/UserController.java @@ -1,11 +1,13 @@ package net.risesoft.demo.controller; +import java.util.ArrayList; import java.util.List; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import jakarta.servlet.http.HttpServletRequest; import net.risesoft.demo.entity.User; import net.risesoft.demo.repository.UserRepository; @@ -20,8 +22,17 @@ public class UserController { this.userRepository = userRepository; } - @GetMapping({"", "/", "/api/users"}) - public List findAll(){ + @GetMapping({"", "/"}) + public List hosts(HttpServletRequest request){ + List list = new ArrayList(); + list.add("request.getServerName()=" + request.getServerName()); + list.add("request.getLocalAddr() =" + request.getLocalAddr()); + list.add("request.getLocalAddr() =" + request.getLocalName()); + return list; + } + + @GetMapping({"/api/users"}) + public List users(){ return userRepository.findAll(); } }