Setting up docker agents in TFS - maven

We are using TFS in our organisation and we manage our whole build through shell scripts (which isn't great)...
Our agent have docker installed and we run our build script inside docker. We have several images for maven, gradle, NodeJs, ...
Because of our use of Docker we cant use the maven plugin for example.
I am wondering if I can somehow benefits from the maven plugin while still running on docker?

You could directly use Docker Integration instead of managing build through shell scripts.
The Docker extension adds a task that enables you to build Docker
images, push Docker images to an authenticated Docker registry, run
Docker images or execute other operations offered by the Docker CLI.
It also adds a Docker Compose task that enables you to build, push and
run multi-container Docker applications or execute other operations
offered by the Docker Compose CLI. Lastly, it offers a Docker Deploy
task that enables you to deploy single Docker images or
multi-container Docker applications into Azure.

Related

How to use the gradle jib plugin to push an image to the google cloud Container Registry

How to use the gradle jib plugin to push an image to the google cloud Container Registry
I am trying to deploy a simple Spring-Boot application and deploy it using google cloud and the Google Kubernetes Engine (GKE). I am also following the tutorial, however the tutorial uses maven and I want to try using gradle for my project. I am able to build my own docker image as well as run the docker image within google's cloud shell, but I cannot seem to figure out how to push the image to the container registry.
The maven command the tutorial gives is
./mvnw -DskipTests com.google.cloud.tools:jib-maven-plugin:build -Dimage=gcr.io/$GOOGLE_CLOUD_PROJECT/hello-java:v1
I have tried to use the gradle version, but something is wrong and I can't figure out what it is, as well as trying some instructables from the docs.
./gradlew build com.google.cloud.tools.jib:build -Dimage=gcr.io/$GOOGLE_CLOUD_PROJECT/hello-java:v3
I don't think I need to add the plugin in my build.gradle file but I could be wrong, I am new to using the jib tool.
I then would be able to run the image with the following
docker run -ti --rm -p 8080:8080 gcr.io/$GOOGLE_CLOUD_PROJECT/hello-java:v1
The repo I am wanting to deploy from is located here
As a secondary question, is it possible to publish images to the google cloud container registry from my local development environment, or do I have to push images to the registry via the Google Cloud Shell?
Update: I figured it out- I don't have to use jib although I would like to figure this out in the future. I am going to play around with my gradle configurations to see if that is a possible issue, but I am using Gradle 6.3 so I don't think that is the problem.
From my built docker image I can just use a docker push command like so
docker push gcr.io/<application-name>/<image-name>:<tag>
And my image shows up in the container registry after I allow access to the registry from the cloud shell.
https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#using-google-container-registry-gcr documents how to this in recent versions of JIB.
BTW watch https://github.com/GoogleContainerTools/jib/issues/3545 for adding documentation about how to push to Google Cloud Container Registry using Google Cloud Build.

How to build Quarkus container based on profile with Gradle?

8.1
I'm able to build my container image with Jib running: ./gradlew clean build -Dquarkus.container-image.build=true
And then I can run it with docker run
The container built is running using the production profile.
I have a separate dev/staging container environment, where I can actually deploy and obviously the configs for passwords and domains are different.
Is there a way to specify the profile during the container build, so for example when it runs it uses the dev profile configurations?
This did the trick:
./gradlew clean build -Dquarkus.container-image.build=true -Dquarkus.profile=dev

Running two maven projects in separate docker containers

I have two maven spring boot applications and I was set up two docker file for that.
Inside each container, I am performing the maven install.
The two containers are performing a lot of download for the dependencies and finally packing the application.
Since these two containers are built sequentially, Can I share the maven's local repository of the first container to the second container, so that the second container's maven install will skip the locally available dependency and only fetch extra libraries mentioned in its pom?
Yes, you can.
We do something similar so that our builds are always clean. But to save time on the maven download, we use a docker volume mounted to the m2 directory so that the downloads can be used between builds & docker containers.
docker run -v m2Repository:/root/.m2 some-image
docker run -v m2Repository:/root/.m2 some-other-image
First run takes a while, but the following builds are much faster.
You did not mention, which environment you are running builds on, so I would like to share my solution for Bitbucket Pipelines CI.
We build our ~20 containers in Bitbucket Pipelines CI and every container is Java application with almost same set of dependencies. Bitbucket Pipelines CI uses Docker images for running builds (yes, they are using Docker images to build Docker images). There is an option to specify which Docker image to use for builds.
To avoid downloading all dependencies over and over again and reduce build time, I built custom Docker image which contains all external dependencies of all our modules. All dependencies were gathered using Maven's command in each module:
mvn -Dmaven.repo.local=c:/projects/bitbucket-pipelines-baseimage/local-maven-repo clean install
After that I removed project's artifacts from temp repository "c:/projects/bitbucket-pipelines-baseimage/local-maven-repo" and built Docker image, which includes that temp repository. That image was deployed to Docker Hub and now all our build in Bitbucket Pipelines are using it. Build times were reduced drastically!

Docker | How to build and deploy war file in jboss container hosted in Docker

I have a jboss image hosted in Docker, along with several others. I am able to run the jboss image and use it as container to deploy webapps.
Currently using IntelliJ to configure a Docker configuration and deploy war files directly from IntelliJ and pointing to the docker configuration within IntelliJ.
I am looking for ways by which I can deploy this war file directly in my jboss image at Docker.
Basically looking at ways to deploy war file without any IntelliJ intervention, with the use of docker-compose to build jboss image along with added war targets successfully deployed.
What sort of changes need to be done in jboss.yml file and Dockerfile for jboss image?
If you want the .war file to be integral part of your image, then you just need to add it as a file resource to your jboss deployment dir during your image assembly via dockerfile. Say your docker file goes like this:
FROM jboss/wildfly
COPY myapp.war /opt/jboss/wildfly/standalone/deployments/
Of course you need to adjust the paths to match your setup and distribution, you can for example use maven docker plugin.
Other option is just to build your server without any deployments and use jboss cli or web admin interface to deploy it. Again you can automate it via maven or RUN command in dockerfile.

maven plugin for docker (e.g. to run with needed db)

Making an image for maven project should be straightforward, as maven know how to build (and can know how to run)
How to build docker image and run it with maven?
Let's say the app also needs MongoDB, that I can run as docker run -p 27017:27017 mongo. Is it possible also to specify with some maven plugin?
The maven plugin created by fabric8 allows you to do this:
the plugin and its documentation is available on github: https://github.com/fabric8io/docker-maven-plugin
The samples include for example https://github.com/fabric8io/docker-maven-plugin/blob/master/samples/data-jolokia-demo/pom.xml (which seems to be similar to what you plan).
An alternative could be using Docker-compose and some scripts outside maven, once the images are created.

Resources