gclayburg / dockerprepareplugin Goto Github PK
View Code? Open in Web Editor NEWGradle plugin to generate docker layer-friendly directory for spring boot applications
License: Apache License 2.0
Gradle plugin to generate docker layer-friendly directory for spring boot applications
License: Apache License 2.0
From:
Transmode/gradle-docker#64
@liqweed
I have a code base with multiple projects, some of them are Spring Boot services. Each project has it's own unique dependencies but all share a common dependency on a 'common-service' project which in turn depends on Spring Boot etc. It would be great if there was a Docker layer for this 'common-service' (including common 3rd parties that don't change that often), a layer for the unique dependencies of each Spring Boot project and then a layer for the project's jar. I'm deploying on-prem so this could reduce the overall size considerably.
In older versions of spring boot, if the jarfile did not exist, then the project might be generating a war.
This is no longer the case at least with spring boot 2.5.2. If a war is being created in the project,
the spring boot plugin has both a 'bootJar' and a 'bootWar' task. It creates files like this:
18745412 18896 -rw-rw-r-- 1 gclaybur gclaybur 19344528 Jul 10 10:05 build/libs/java252war8-0.0.1-SNAPSHOT.war
18745551 13184 -rw-rw-r-- 1 gclaybur gclaybur 13496175 Jul 10 10:05 build/libs/java252war8-0.0.1-SNAPSHOT-plain.war
18745416 18892 -rw-rw-r-- 1 gclaybur gclaybur 19339926 Jul 10 10:05 build/libs/java252war8-0.0.1-SNAPSHOT.jar
Since the boot jar file exists, this plugin assumes it is NOT generating a war based project.
The resulting docker image seems to work, but it is NOT using anything from the war
To get this to work, we would need to rework this section to mimic what the jar section
above does with classifiers and archiveClassifiers and all that fun stuff.
Maybe this can be done if we have a project that needs a war AND uses spring boot 2.5+ AND
wants to use this plugin for better docker images.
Hi,
Your plugin looks fantastic, but is it possible to use it without having to add SpringBoot plugin ?
Thanks
We this error message during a build:
$ ./gradlew clean build
> Task :expandBootJar
no war file or jar file found to prepare for Docker
> Task :jar
Execution optimizations have been disabled for task ':jar' to ensure correctness due to the following reasons:
- Gradle detected a problem with the following location: '/home/gclaybur/dev/demos/groovy252/build/libs/groovy252-0.0.1-SNAPSHOT-plain.jar'. Reason: Task ':expandBootJar' uses this output of task ':jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
Hi,
I'm using this plugin to create a Dockerfile with correct layers for my springboot project, but I'm facing a strange error in my CI during docker build process and I have no clue what is wrong so I open this issue for some help.
Snippet of the error:
2021-11-09T13:25:56.3034681Z Step 9/19 : ADD snapshotLayer3/ /home/springboot/app/ 2021-11-09T13:25:57.0138269Z ---> 7c22a09f9c43 2021-11-09T13:25:57.0138749Z Step 10/19 : ADD classesLayer4/ /home/springboot/app/ 2021-11-09T13:25:58.0385717Z failed to export image: failed to create image: failed to get layer sha256:89bc8fa8b17002644dbde60c1e677adfce8c26d60f8c24c3dbb32a4a9d36c3b9: layer does not exist 2021-11-09T13:25:58.0512683Z ##[error]failed to export image: failed to create image: failed to get layer sha256:89bc8fa8b17002644dbde60c1e677adfce8c26d60f8c24c3dbb32a4a9d36c3b9: layer does not exist 2021-11-09T13:25:58.0528976Z ##[error]The process '/usr/bin/docker' failed with exit code 1 2021-11-09T13:25:58.0556179Z ##[section]Finishing: Build an image
I'm using SpringBoot 2.5.6 with Java 11 and Gradle 7.2
The complete CI Build image log, Dockerfile and build.gradle are attached .
CI-error.txt
Dockerfile.txt
build.gradle.txt
Thanks for all the help.
Hi,
Can you update to fix for Spring boot M7 compatibility? I get :
Caused by: java.lang.NullPointerException: Cannot invoke method isIncluded() on null object
at com.garyclayburg.docker.DockerPreparePlugin.failWhenExecutable(DockerPreparePlugin.groovy:156)
at com.garyclayburg.docker.DockerPreparePlugin$_apply_closure1.doCall(DockerPreparePlugin.groovy:56)
When using this dockerprepare config:
dockerprepare {
commonService = ['org.springframework.boot:spring-boot-starter-web']
}
and spring boot 2.4.2, I get this error:
$ ./gradlew clean build
> Task :expandBootJar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':expandBootJar'.
> Warning: Could not find file /home/gclaybur/dev/gvsync/upbannerdemo/build/docker/dependenciesLayer2/BOOT-INF/lib/spring-boot-starter-web-2.4.2.jar to copy.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 5s
8 actionable tasks: 8 executed
You can get a fatal error like this:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':policyconsole:expandBootJar'.
>
WARNING!!! one or more commonService dependencies not found in your project
commonService = [org.springframework.boot:spring-boot-starter-web, org.springframework.boot:spring-boot-actuator]
but,
found = [org.springframework.boot:spring-boot-starter-web]
when org.springframework.boot:spring-boot-actuator
is actually defined in a subproject instead of the same project where this plugin is applied.
Don't have access https://plugins.gradle.org/m2/, please publish this plugin to maven center repository.
thx!
more background:
Transmode/gradle-docker#64
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.