Issue
Approach 1: Using Jenkins, clone and build the code using gradle plugin, then add the JAR in the dockerfile with JRE as a base image. As we have the JAR packed in the image, we can pull the image and run the container.
FROM openjdk:8-jre-alpine
ADD build/libs/abcd.jar abcd.jar
ENTRYPOINT ["java", "-jar", "/abcd.jar"]
Approach 2: Create a dockerfile with all build dependencies now using Jenkins just build the dockerfile. Upload the image on dockerhub or ACR and for deploying just pull the image and run.
FROM openjdk:8-jre
"install gradle set the path variable"
"Run the gradle build"
"deploy the jar"
Just asking in a generalized way. Which will be better?
Solution
Approach 2 does not make sense at all. This would mean you have all the build tools and artifacts in your deployment unit (the image).
Approach 1 is pretty much the standard way to build a docker image as the deployment unit.
Answered By - EricSchaefer