How to generate a docker image - docker

I try to create a docker image based on my java gradle web application.
I add plugin and build in my build.gradle as shown below.
apply plugin: 'application'
apply plugin: 'docker'
buildscript {
repositories { mavenCentral() }
dependencies {
classpath 'se.transmode.gradle:gradle-docker:1.1'
}
}
I didn't specify the java version as in gradle's default sourceCompatibility is 1.7
After execute ./gradlew distDocker
build folder is generated
docker/application-b35a946bf5b.tgz
docker/Dockerfile
classes/
distributions/
libs/
resources/
scripts/
tmp/
Can i create docker images based on docker/application-b35a946bf5b.tgz and docker/Dockerfile
I am new to docker.
Any suggestion will be helpful.

Related

Isolate maven jar dependencies that are unavailable from maven central

I am attempting to refactor a maven build process, and I am trying to populate a local maven repository to help with this refactor.
My build depends on obsolete versions of jar files that exist only in a maven repo on my network (not in maven central). Example: org.foo:example:1.7:jar
I have been attempting to run my maven build in a docker image image with the hope that I could identify all of the obsolete components being pulled from my maven repository.
My goal is to explicitly pull down dependencies from my maven repo and then build the application using only maven central as an external repository.
I have a docker file to run the build
FROM maven:3-jdk-8 as build
WORKDIR /build
# This pom.xml file only references maven central.
COPY pom.xml .
# Explicitly download artifacts into /root/.m2/...
RUN mvn dependency:get -Dartifact=org.foo:example:1.7.jar \
-DrepoUrl=https://my.maven.repo
# Run the build making use of the dependencies loaded into the local repo
RUN mvn install
Unfortunately, I see an error: could not resolve dependencies for project ... The following artifacts could not be resolved: org.foo:example:jar:1.7.
I presume there might be some metadata in my local org.foo:example:1.7:pom that has an awareness of its origin repository. I had hoped I could satisfy this dependency by pulling it into my local repository.
I also attempted to add the following flag
RUN mvn install --no-snapshot-updates
After further investigation, I discovered that the downloads in my .m2/repository contained files named _remote.repositories.
Solution: set -Dmaven.legacyLocalRepo=true when running dependency:get
With this flag, the _remote.repositories files are not created.
RUN mvn dependency:get -Dmaven.legacyLocalRepo=true \
-Dartifact=org.foo:example:1.7.jar \
-DrepoUrl=https://my.maven.repo
This question helped to provide a solution: _remote.repositories prevents maven from resolving remote parent

run gradle test suit through jenkins: where do dependencies download

When a gradle test script is run through jenkins, should dependencies be downloaded to a folder?
When i run on my laptop i use MavenLocal in the build.gradle and every dependency is present in the .m2 folder.
Usually your dependencies will be downloaded from public repositories that you configured in the gradle script, e.g. mavenCentral() or jcenter().
If you have your own libraries, which cannot be downloaded from any public repository, you have to push them to your personal repository first, e.g. Nexus. After creating a user on Nexus, you set up the credentials in jenkins and pass them as environment variables to gradle.

Passing arguments to build.gradle

I am building a springboot application using gradle.
The build eventually outputs a docker container and I want my build.gradle to support multiple environments.
I am using gradlew build docker to build and the docker section of my build.gradle is :
docker {
dependsOn build
name "app-production"
files bootJar.archivePath, 'application.yml'
buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
}
I successfully passed arguments to the dockerfile but now I also want to pass arguments to the build.gradle file. Is it possible using gradlew build docker?
I need something like this : gradlew build docker --env=qa and then :
docker {
dependsOn build
name "app-${env}"
files bootJar.archivePath, 'application.yml'
buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
}
NOTE: ${bootJar.archiveName} is a local variable in my build.gradle, not an environment variable
Any ideas?
You can use Project Properties to pass values to your build script from command line, as follows:
gradlew build docker -Penv=qa
Then in your build script you can access this property :
docker {
name "app-${env}"
// ....
}

Jar versioning in Jenkins

On each maven build or release, how to get new jar version in Jenkins. I have tried it in Jenkins but only getting same jar file name as it is in pom file.
you can use maven-exec-plugin to print the version to stdout or write it in a file:
mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:exec

How can I build a Netbeans RCP application with SBT?

Netbeans RCP application are built with Ant. How can I build with SBT and integrate in Jenkins?
There's a SBT plugin which allows Ant targets to be called.
First build ant4sbt from sources:
git clone http://github.com/sbt/ant4sbt.git
cd ant4sbt
sbt publish-local
Create a file properties/sbt-ant4sbt.sbt like this:
addSbtPlugin("de.johoop" % "ant4sbt" % "1.1.2")
Create a build.sbt on the root of your Netbeans RCP application:
import de.johoop.ant4sbt.Ant4Sbt._
antSettings
addAntTasks("build-osgi") // creates task antRunBuildOsgi
addAntTasks("run-osgi") // creates task antRunRunOsgi
Now you can build OSGi bundles from command line and run it inside a container, like this:
sbt antRunBuildOsgi
sbt antRunRunOsgi
Building in Jenkins is as easy as calling sbt antRunBuildOsgi but you will have to copy dependencies to the library directory you defined in your Netbeans IDE. After the build you will also have to copy artifacts to the place you distribute artifacts of your builds.
See also: Cannot build OSGi bundle for a Netbeans RCP application

Resources