New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker image generation issues #7722
Comments
I have fixed this issues in my project with this alternate file buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.2.0'
classpath 'gradle.plugin.com.garyclayburg:dockerPreparePlugin:1.3.2'
}
}
apply plugin: com.bmuschko.gradle.docker.DockerRemoteApiPlugin
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
apply plugin: com.garyclayburg.docker.DockerPreparePlugin
dockerprepare {
dockerSrcDirectory "${project.rootDir}/src/main/dockerlayer"
commonService = ['org.springframework.boot:spring-boot-starter-web']
}
task buildDocker(type: DockerBuildImage, dependsOn: 'dockerLayerPrepare') {
springBoot.executable = false
description = "Package application as Docker image"
group = "Docker"
inputDir = project.file(dockerprepare.dockerBuildDirectory)
tags = ["synconsole:latest".toString(), "synconsole:${project.version}".toString()]
}
The docker tags used here are particular to my project, but the rest is fairly generic. It should be usable in any gradle based jhipster project. A few things about this solution:
So what do you guys think, would something like this be useful to the project? |
Thanks for the feedback ! Please let us some time to review your suggestion. Just a few remarks that I can do upfront : I like that you are trying to solve the "big layer" problem inherent in the fact that we are using fat jars. I have thought of a few ways to fix this using for example the spring-boot-thin-wrapper (but I never implemented it yet). However I would much rather prefer if the solution would use an existing Dockerfile so that it can be customized by the user, even if this dockerfile is actually modified in the build process. Also I would much rather prefer a solution that would work for both gradle and maven and keep it simple and stable. Concerning running the process inside docker as a user other than root, yes we would welcome improvements on this part, remember that some of it was first implemented over 2 years ago ! As for being able to pass command line args, it's would be a nice thing to have but I personally prefer to use env variables. Thanks again for the feedback, I wished more people would reach out to us with suggestions like this ! |
Thanks for your feedback @gclayburg. Here some comments:
|
@gclayburg Apparently creating layered images is currently under investigation by the spring boot team: spring-projects/spring-boot#12545 |
You are right about KILL, @pascalgrimaud. The way it is right now, if you run a One way to fix it to do something like this in the Docker file:
and this at the end of bootrunner.sh:
This does 2 things actually - it allows us to pass command like arguments to the docker image being run and it allows OS signals to reach the JVM. This is important if you are stopping the container with the docker tools or other higher level tools like kubernetes. There are some cases where command line options to the app work better than environment variables. For my app,I ran into an issue back with spring boot 1.4.x where certain parameters were not parsed consistently by Spring. I could get it to work using the command line arguments, but not with environment variables. BTW, the Spring team has since fixed that issue with Spring Boot 1.5 If you don't do the The full
And yes all but the layering issue can be addressed with a simple replacement default Dockerfile and bootrunner.sh. I could see about creating a PR for you if it would help. |
About the layering issue, I understand you would prefer to share a single |
I have just done some testing using https://github.com/dsyer/spring-boot-thin-launcher and I am able to create a layered build although with only 2 layers: |
I wonder how well that kind of solution would work over time in a docker environment. As the app evolves, dependencies will get upgraded. Wouldn't that lead to a docker image that has lots of unused old dependencies? Once the docker layers are added, the files in there are always there. |
I don't think so. Anyway you will need to clean your build dir when you rebuild the Docker image otherwise it might increase in size every time you change dependencies. |
Ok, I created a Dockerfile and bootrunner.sh to fix these issues that will also work with both maven and gradle. I put them in a vanilla spring boot starter project here These files will also work in a jhipster generated project if they are placed in I'm not sure if it makes sense or not, but I had to play some games with the Dockerfile and emptyfile.txt since it doesn't really support conditional ADD commands. |
…pster#7722 - use a specific jhipster user instead of root - use an entrypoint to allow passing docker run cli args to the docker process - prepend the `java` command with exec to correctly respond to QUIT and TERM signals
I have started implementing things. For now I have not added the following:
|
Guys, sorry about some off topic.
it's replaced with more simple construction without additional version definition in pugins section:
May be in upcoming 5 version update this section? |
I have implemented many of the suggested improvements so I'm closing this issue. If additional improvements to our docker build are needed in the future, please open other feature requests. @gclayburg I'm sorry I don't think we can base our gradle build on your plugin for now even though I recognize that it's quite nice ! |
lost when merging jhipster#7722
Overview of the issue
I have been using jhipster for a while now and love the project. There are certainly top-notch integration techniques with many technologies here.
However, I noticed a few issues with the way docker images are generated. I have fixed these myself and I'm curious if this project might like to use some of these as a default. Here are the issues I ran into:
docker stop
command will take a little longer to shutdown the app while it times out and sends a KILL signal. This means that your app will not get a chance to run any Spring @Predestroy Java beans and your app may not shutdown correctly.You can however pass environment variables with the docker --env flag.
Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix
See follow-up below
JHipster Version(s)
4.14.4 using gradle
JHipster configuration
Entity configuration(s)
entityName.json
files generated in the.jhipster
directoryBrowsers and Operating System
The text was updated successfully, but these errors were encountered: