update compose

This commit is contained in:
dzj 2023-10-29 19:48:16 +08:00
parent 4da7049cb5
commit c778bd5291
6 changed files with 136 additions and 13 deletions

View File

@ -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"

26
compose-demo01-jvm.yml Normal file
View File

@ -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

26
compose-demo01-native.yml Normal file
View File

@ -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

62
pom.xml
View File

@ -21,11 +21,6 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.ecwid.consul</groupId>
<artifactId>consul-api</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
@ -89,6 +84,7 @@
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
@ -99,12 +95,60 @@
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<mainClass>net.risesoft.demo.Demo01Application</mainClass>
<image>
<env>
<BP_NATIVE_IMAGE>false</BP_NATIVE_IMAGE>
<BP_JVM_VERSION>17</BP_JVM_VERSION>
</env>
<name>svn.youshengyun.com:9923/${project.artifactId}-jvm:${project.version}</name>
<publish>true</publish>
</image>
<docker>
<publishRegistry>
<username>publisher</username>
<password>83204585</password>
</publishRegistry>
</docker>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jib</id>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<skip>false</skip>
<to>
<image>svn.youshengyun.com:9923/${project.artifactId}-jib</image>
<tags>
<tag>${project.version}</tag>
</tags>
<auth>
<username>publisher</username>
<password>83204585</password>
</auth>
</to>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<build>
@ -135,7 +179,15 @@
<BP_JVM_VERSION>17.0.9</BP_JVM_VERSION>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--enable-preview</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
<name>svn.youshengyun.com:9923/${project.artifactId}-native:${project.version}</name>
<publish>true</publish>
</image>
<docker>
<publishRegistry>
<username>publisher</username>
<password>83204585</password>
</publishRegistry>
</docker>
</configuration>
<executions>
<execution>

View File

@ -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

View File

@ -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<User> findAll(){
@GetMapping({"", "/"})
public List<String> hosts(HttpServletRequest request){
List<String> list = new ArrayList<String>();
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<User> users(){
return userRepository.findAll();
}
}