It is not necessary to provide settings for the com.garyclayburg.dockerprepare gradle plugin. In this case, we will use this Dockerfile:
FROM openjdk:8u131-jre-alpine
RUN adduser -D -s /bin/sh springboot
COPY ./bootrunner.sh /home/springboot/bootrunner.sh
RUN chmod 755 /home/springboot/bootrunner.sh && chown springboot:springboot /home/springboot/bootrunner.sh
WORKDIR /home/springboot
USER springboot
ADD dependenciesLayer/ /home/springboot/app/
ADD classesLayer/ /home/springboot/app/
ARG ORG_LABEL_SCHEMA_VCS_REF
ARG ORG_LABEL_SCHEMA_VCS_URL
ARG ORG_LABEL_SCHEMA_BUILD_DATE
ARG ORG_LABEL_SCHEMA_VERSION
ARG ORG_LABEL_SCHEMA_DESCRIPTION
ARG MAINTAINER
LABEL maintainer=${MAINTAINER:-"https://github.com/gclayburg"} \
org.label-schema.vcs-ref=${ORG_LABEL_SCHEMA_VCS_REF} \
org.label-schema.vcs-url=${ORG_LABEL_SCHEMA_VCS_URL} \
org.label-schema.build-date=${ORG_LABEL_SCHEMA_BUILD_DATE} \
org.label-schema.version=${ORG_LABEL_SCHEMA_VERSION} \
org.label-schema.schema-version="1.0" \
org.label-schema.description=${ORG_LABEL_SCHEMA_DESCRIPTION}
VOLUME /tmp
EXPOSE 8080
ENV JAVA_OPTS=""
ENTRYPOINT ["./bootrunner.sh"]
And this bootrunner.sh
#!/bin/sh
date_echo(){
datestamp=$(date "+%F %T")
echo "${datestamp} $*"
}
#exec the JVM so that it will get a SIGTERM signal and the app can shutdown gracefully
if [ -d "${HOME}/app" ]; then
#execute springboot expanded jar, which may have been constructed from several image layers
date_echo "exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -cp ${HOME}/app org.springframework.boot.loader.JarLauncher $*"
# shellcheck disable=SC2086
exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -cp "${HOME}/app" org.springframework.boot.loader.JarLauncher "$@"
elif [ -f "${HOME}/app.jar" ]; then
# execute springboot jar
date_echo "exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar ${HOME}/app.jar $*"
# shellcheck disable=SC2086
exec java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar "${HOME}/app.jar" "$@"
else
date_echo "springboot application not found in ${HOME}/app or ${HOME}/app.jar"
exit 1
fi
If you need to override these files or add others you can put this in your build.gradle
dockerlayer {
dockerSrcDirectory "${project.rootDir}/dockerroot"
}
| Type | Name and description |
|---|---|
java.lang.Object |
commonService |
java.lang.String |
commonServiceDependenciesDirectory |
java.lang.String |
dockerBuildClassesDirectory |
java.lang.String |
dockerBuildDependenciesDirectory |
java.lang.String |
dockerBuildDirectory |
java.lang.String |
dockerSrcDirectory |
org.gradle.api.Project |
project |
| Constructor and description |
|---|
DockerPreparePluginExt
(org.gradle.api.Project project) |
DockerPreparePluginExt
() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
commonService(java.lang.String[] commonService) |
|
void |
dockerBuildDirectory(java.lang.String buildD)This plugin will copy your application files and supporting docker files to this directory. |
|
void |
dockerSrcDirectory(java.lang.String sourceDirectory)All files or directories in this directory will be copied to the dockerBuildDirectory. |
|
java.lang.Object |
dockerprepare(groovy.lang.Closure closure)Apply settings via closure, e.g. in build.gradle:
dockerprepare{
dockerSrcDirectory "${project.rootDir}/mydocker"
dockerBuildDirectory "${project.buildDir}/mydockerbuild"
}
|
|
void |
setCommonService(java.lang.String[] commonService) |
|
void |
setDockerBuildDirectory(java.lang.String dockerBuildDirectory)This plugin will copy your application files and supporting docker files to this directory. |
|
void |
setDockerSrcDirectory(java.lang.String dockerSrcDirectory) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
This plugin will copy your application files and supporting docker files to this directory. If needed, you could build a docker image by hand from this directory using a command like this:
docker build -t myname/myimage .You could also use a gradle task to build the image directly from these files.
Defaults to "${project.buildDir}/docker"
dockerBuildDirectory - staging area for creating a docker imageAll files or directories in this directory will be copied to the dockerBuildDirectory. If you want to use a custom Dockerfile to create your image, it should be placed here. If the directory does not exist or is empty, a default Dockerfile and start script for your app will be placed in the dockerBuildDirectory
Defaults to "${project.buildDir}/docker"
sourceDirectory - Source directory for adding files to dockerApply settings via closure, e.g. in build.gradle:
dockerprepare{
dockerSrcDirectory "${project.rootDir}/mydocker"
dockerBuildDirectory "${project.buildDir}/mydockerbuild"
}
If there is no dockerprepare section in build.gradle, these defaults are used:
dockerSrcDirectory = "${project.rootDir}/src/main/docker"
dockerBuildDirectory = "${project.buildDir}/docker"
closure - settings to overrideThis plugin will copy your application files and supporting docker files to this directory. If needed, you could build a docker image by hand from this directory using a command like this:
docker build -t myname/myimage .You could also use a gradle task to build the image directly from these files.
Defaults to "${project.buildDir}/docker"
dockerBuildDirectory - staging area for creating a docker imageGroovy Documentation