Closed devopsadmin-james closed 4 years ago
Created a shell-script task of gradle, somthing like this
task Test() { doLast { exec { executable "./test.sh" } } }
Contents inside test.sh like this
jar=$(find ./build/libs/ -type f -exec grep -l 'Web' {} \; | cut -d/ -f4) echo " " echo "$jar" sed -i "s|ADD\ .*|ADD\ $jar\ java.jar|g" ./src/main/docker/Dockerfile
So just copied everything from 'build/libs' into 'buidl/docker' at gradle task run time to get desired result.
task buildDocker(type: Docker, dependsOn: build) { push = false tag = 'test/java' tagVersion = getDate() dockerfile = file('src/main/docker/Dockerfile') doFirst { copy {
// from 'build/libs/"${jar}"' //from 'build/libs/Test-2.1.0-0.jar' from 'build/libs/'' into 'build/docker' } } }
I have used this "https://jgitver.github.io" plugin to build jar files based on git tags. With its usage gradle build jars are built based on git tags and git commits history(after new tag is created something like say git tag is v2.1.0 then build jar would be test-2.1.0-0.jar on master branch & test-2.1.0-0-dev.jar on a dev branch and after few commits say two more commits that built jar would be test-2.1.0-2.jar ).
So i have a below gradle task which will build docker image using that jar file with the help of your "Transmode/gradle-docker" plugin.
task buildDocker(type: Docker, dependsOn: build) { push = false tag = 'test/java' tagVersion = getDate() dockerfile = file('src/main/docker/Dockerfile') doFirst { copy {
// from 'build/libs/"${jar}"' from 'build/libs/Test-2.1.0-0.jar' into 'build/docker' } } }
So i have to update this jar file into this gradle task based on the current built jars dynamically and also into one of external Dockerfile (which is below) dynamically
FROM openjdk:8-jre
VOLUME /tmp
ADD Test-2.1.0-0.jar java.jar
RUN bash -c 'touch /java.jar'
EXPOSE 8080
How should we proceed to achieve this scenario.