diff --git a/pom.xml b/pom.xml index 5bc273c9a6fb6541a4a552470e47fff5f6bb2923..7f67177601785998e6cf625666fd8843774eecd2 100755 --- a/pom.xml +++ b/pom.xml @@ -2,6 +2,11 @@ 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.6 + com.alex spring-boot-build-docker @@ -10,66 +15,36 @@ spring-boot-build-docker - 22 - 22 - 22 + 21 + 21 + 21 UTF-8 UTF-8 - 3.2.6 org.springframework.boot spring-boot-starter-web - ${spring-boot.version} + + org.graalvm.buildtools + native-maven-plugin + org.springframework.boot spring-boot-maven-plugin - 3.2.6 - ${project.artifactId}:latest + ${project.artifactId}-native:latest ${maven.build.timestamp} - - com.google.cloud.tools - jib-maven-plugin - 3.4.2 - - - eclipse-temurin:22.0.1_8-jre-ubi9-minimal - - - ${project.artifactId}:latest - - - com.alex.springbootbuilddocker.SpringBootBuildDockerApplication - USE_CURRENT_TIMESTAMP - - - - - - - - - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.3.0 - diff --git a/readme.md b/readme.md index 9c2d0049d7307388c441345bbf9cacb843316e3a..8231ed4e0393f366ba778a2f7c768ccb744f766f 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,44 @@ # spring-boot 容器化构建 ## docker镜像构建的三种方式 -1. springboot -2. jib -3. docker +1. spring-boot-maven-plugin +2. jib-maven-plugin +3. docker-maven-plugin -Global Jib Configuration +## native 镜像构建 -Some options can be set in the global Jib configuration file. The file is at the following locations on each platform: -Linux: [config root]/google-cloud-tools-java/jib/config.json, where [config root] is $XDG_CONFIG_HOME ($HOME/.config/ if not set) -Mac: [config root]/Google/Jib/config.json, where [config root] is $XDG_CONFIG_HOME ($HOME/Library/Preferences/ if not set) -Windows: [config root]\Google\Jib\Config\config.json, where [config root] is %XDG_CONFIG_HOME% (%LOCALAPPDATA% if not set) \ No newline at end of file +### 环境参数 + +- 操作系统:WSL 2: Ubuntu 22.04.4 LTS jammy +- graal版本: Oracle GraalVM 21.0.3+7.1 (build 21.0.3+7-LTS-jvmci-23.1-b37) +- docker版本:Docker version 26.1.1, build 4cf5afa + +1. 构建本地可执行文件 + +``` shell +./mvnw clean native:compile -Pnative +``` + +该命令依赖gcc和zlib,需要先执行 + +```shell +sudo apt-get install gcc +sudo apt-get install zlib1g-dev +``` +构建成功后,启动应用,执行 + +```shell +./target/spring-boot-build-docker +``` + +启动速度极快,几十毫秒 + +该方式无需联网,可以构建后通过Dockerfile继续构建docker镜像,但是需要保持构建环境和运行环境的类库兼容性。可以考虑通过同一个基础镜像构建构建镜像和运行镜像。 + +2. 构建oci镜像 + +``` shell +./mvnw clean spring-boot:build-image -Pnative +``` +通过docker-compose.yaml启动容器,同样也是极快启动 + +该方式是通过paketobuildpacks在docker镜像中编译和构建镜像,能保证编译环境与运行环境的一致性,屏蔽了不同操作系统版本的影响。该方式是比较适合方式。但是构建过程中有些依赖需要从github上下载,有网络联通问题,且插件参数不能配置镜像或离线构建。 \ No newline at end of file