The post How to Automate Docker Swarm Service deployment using Jenkins appeared first on Little Big Extra.
]]>Jenkins is a wonderful tool for continuous integration and continuous deployment. The plethora of plugins available makes it really powerful. In this tutorial, I will show you how to use Jenkins to automate swarm deployment.
To do a Docker Swarm deployment all you need is a docker-compose file which will contain the references to docker images along with the configuration settings like port, network name, labels, constraints etc and to run this file you need to execute a command called “docker stack deployment”
So all we need to do is to send this docker-compose.yml file over SSH to Manager node and execute the command
docker stack deployremotely. Let’s see how to achieve this.
We need to install a Jenkins plugins “Publish over SSH”, this plugin will allows us to
To add this plugin you need to go to Jenkins -> Manage Jenkins -> Manage Plugins -> Available and search for “Publish
Over SSH”. Install this plugin and restart Jenkins.
Navigate to Jenkins -> Manage Jenkins -> Configure System and scroll down until you find Publish over SSH.
Since we need to execute the docker stack deploy command on any manager node, we need to connect to a manager node in Docker Swarm. This plugin offers various ways to connect to remote hosts, I prefer SSH public/private key value pair. Keys can be generated with ssh_keygen. The private key must be kept on Jenkins server and the public key must be stored on the manager node.
Click on Test configuration and see if the connection is successful.
Have a look at the screenshot below ( please note that Remote Directory contains a swarm directory if it doesn’t exist either leave Remote Directory as blank or create a directory on manager node, in the next step we will use this directory to publish docker-compose file)
You can add multiple manager nodes if you want.
In this step, we need to tell Jenkins from where to get our docker-compose file and how to transfer using SSH to remote server and execute subsequently.
Now Under SSH server Select the manager node where you want to publish/send the docker-compose file. In the Transfers Set block,
cd /swarm docker stack deploy -c docker-compose.yml
This is how my configuration looks like for reference.
Now run this Jenkins Job using Build now and then check in Console Output to see the output of remote server. Hopefully, it will run fine !!
The post How to Automate Docker Swarm Service deployment using Jenkins appeared first on Little Big Extra.
]]>The post How to convert JSON schema to Java classes using maven plugin appeared first on Little Big Extra.
]]>We often need to convert JSON schema’s to Java classes, there is a jsonschema2pojo-maven-plugin which helps in generating POJO(plain old java objects) from JSON or JSON schema.
To use it all we need is add this plugin, update dependencies and run mvn generate
Add this plugin to your POM.XML under plugin section
<plugin> <groupId>org.jsonschema2pojo</groupId> <artifactId>jsonschema2pojo-maven-plugin</artifactId> <version>0.4.34</version> <configuration> <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory> <targetPackage>com.test.gen</targetPackage> <useCommonsLang3>true</useCommonsLang3> </configuration> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin>
The generated types depend on Commons Lang library for equals, hashCode and toString. Also, you need to add Jackson-databind which contains the data-binding functionality and tree-model for Jackson Data Processor, this jar has a transitive dependency on jackson-core and jackson-annotations so they will be downloaded automatically.
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency>
You can run
mvn generate-sourcesgoal to generate the java classes. All files will be added in the target/java-gen folder by default
${basedir}/src/main/gen
Make sure that generated folder is added as a source folder in your IDE (Properties ->Java build Path -> Add source folder in eclipse).
If you want to generate Java classes from JSON rather than JSON schema add
<sourceType>json</sourceType>
inside the configuration tag as default source type is JSON Schema.
The post How to convert JSON schema to Java classes using maven plugin appeared first on Little Big Extra.
]]>The post Using Jenkins to Build and Deploy Docker images appeared first on Little Big Extra.
]]>Jenkins is one of the most popular continuous integration tools and is widely used. It can be used to create pipelines, run jobs and do automated deployments.
There are many plugins available which can be added to Jenkins and makes it really powerful.
Recently I wanted to do an automated deployment of Docker Images to docker server and tried using docker-plugin but after spending some time it looked to me that if it asking for too much of information and for each operation you need to provide arguments, I would prefer a solution which is more dynamic and picks things automatically with user providing the bare essentials parameters arguments.
This is how it looks like
In a nutshell, all I wanted was
Once all 3 steps have been tested and completed all is left to be done in Jenkins is to Invoke the clean install goal as shown below.
If you want to push the docker image to some repository after building, testing and deploying.Please follow this link
The post Using Jenkins to Build and Deploy Docker images appeared first on Little Big Extra.
]]>The post How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin appeared first on Little Big Extra.
]]>
If you want to push a docker image to Docker Hub repository, it can be achieved using docker maven plugin from fabric8.io. This plugin lets you build images, start and stop containers and push it to Docker repositories
&nsbp;
<plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.20.0</version>....
<name>springboot-mongo-dockerimage:${project.version}</name> <alias>springboot-mongo-dockerimage</alias> <build> <dockerFileDir>${project.basedir}</dockerFileDir> </build>
<registry>registry.hub.docker.com/YOUR_DOCKER_HUB_USERNAME</registry>
<authConfig> <username>ENTER YOUR DOCKER HUB USERNAME LIKE abhishek</username> <password>ENTER YOUR DOCKER HUB PASSWORD</password> </authConfig>
<execution> <id>push</id> <phase>post-integration-test</phase> <goals> <goal>push</goal> </goals> </execution>
Here is the complete build section from the plugin, hope this help.
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.20.0</version> <configuration> <registry>registry.hub.docker.com/YOUR_DOCKER_HUB_USERNAME</registry> <images> <image> <name>springboot-mongo-dockerhub:${project.version}</name> <alias>springboot-mongo-dockerhub</alias> <build> <dockerFileDir>${project.basedir}</dockerFileDir> </build> <run> <namingStrategy>alias</namingStrategy> <dependsOn> <container>mongo</container> </dependsOn> <links> <link>mongo</link> </links> <ports> <port>9876:8080</port> </ports> <log> <prefix>TC</prefix> <date>default</date> <color>cyan</color> </log> </run> </image> </images> <authConfig> <username>ENTER YOUR DOCKER HUB USERNAME LIKE abhishek</username> <password>ENTER YOUR DOCKER HUB PASSWORD</password> </authConfig> </configuration> <executions> <execution> <id>start</id> <phase>pre-integration-test</phase> <goals> <goal>stop</goal> <goal>build</goal> <goal>start</goal> </goals> </execution> <execution> <id>push</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> <goal>push</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
If you get an error : io.fabric8:docker-maven-plugin:0.20.0:build failed: A tar file cannot include itself
The post How To Push Docker Images To Docker Hub Repository Using Docker Maven plugin appeared first on Little Big Extra.
]]>The post Build and deploy Docker Image with Docker Maven plugin appeared first on Little Big Extra.
]]>
The maven plugin for docker fabric8io/docker-maven-plugin helps us in building docker images and running containers. In case you are thinking about the difference between an image and container then please note that a running image is called container.
In this tutorial, we are going to
<plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.20.0</version>....
<name>springboot-mongo-dockerimage:${project.version}</name> <alias>springboot-mongo-dockerimage</alias> <build> <dockerFileDir>${project.basedir}</dockerFileDir> </build>
<dependsOn> <container>mongo</container> </dependsOn> <links> <link>mongo</link> </links>
<ports> <port>9876:8080</port> </ports>
<executions> <execution> <id>start</id> <phase>pre-integration-test</phase> <goals> <goal>stop</goal> <goal>build</goal> <goal>start</goal> </goals> </execution>
Here is the complete build section from the plugin, hope this help.
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.20.0</version> <configuration> <!--<dockerHost>tcp://REMOTE_IP:2375</dockerHost>--> <images> <image> <name>springboot-mongo-dockerimage:${project.version}</name> <alias>springboot-mongo-dockerimage</alias> <build> <dockerFileDir>${project.basedir}</dockerFileDir> </build> <run> <namingStrategy>alias</namingStrategy> <dependsOn> <container>mongo</container> </dependsOn> <links> <link>mongo</link> </links> <ports> <port>9876:8080</port> </ports> <log> <prefix>TC</prefix> <date>default</date> <color>cyan</color> </log> </run> </image> </images> </configuration> <executions> <execution> <id>start</id> <phase>pre-integration-test</phase> <goals> <goal>stop</goal> <goal>build</goal> <goal>start</goal> </goals> </execution> <!-- Uncommment this execution phase if you wan to remove container after testing -> <!--<execution> <id>clean image</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> --> </executions> </plugin> </plugins> </build>
If you get an error : io.fabric8:docker-maven-plugin:0.20.0:build failed: A tar file cannot include itself
The post Build and deploy Docker Image with Docker Maven plugin appeared first on Little Big Extra.
]]>The post How to enable jenkins to auto build with BitBucket server appeared first on Little Big Extra.
]]>One of the goals of Continuous Integration andContinuous deployment is that once the code is pushed to the repository it should be tested, built and then packaged for deployment. BitBucket webhook makes is possible to trigger real-time notifications to Jenkins server so the auto build starts as soon as the code is pushed.
In this tutorial, we will
Once you have installed BitBucket server on your machine, make sure that it is working. The default port is 7990, so you should be able to access it by using localhost: 7990.
The post How to enable jenkins to auto build with BitBucket server appeared first on Little Big Extra.
]]>The post How to Install Jenkins on Docker appeared first on Little Big Extra.
]]>Jenkins is a great tool to build and package artifacts, it can be either deployed independently as a service in docker, lets go through the steps required to install Jenkins on docker as a container.
In this tutorial, we will
docker pull Jenkins
docker volume create --name jenkins_data docker run --name jenkins -d -v jenkins_data:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins:latest
OR
docker run --name jenkins -d -v /Users/jenkins:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins:latest
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 041465f0254e jenkins:latest "/bin/tini -- /usr..." 43 hours ago Up 58 seconds 0.0.0.0:50000>50000/tcp, 0.0.0.0:8082->8080/tcp jenkins
The post How to Install Jenkins on Docker appeared first on Little Big Extra.
]]>The post How to Install Artifactory on Docker appeared first on Little Big Extra.
]]>JFrog Artifactory is a repository manager used for versioning deployable like a jar, war, docker image etc. Artifactory Pro is a licensed/paid version which will let you create repositories for docker images and much more.Artifactory OSS is open source and a restrective version where you can create maven repositories and few others.
In this tutorial, we will
Pull the Artifactory OSS Docker Image, it’s an open source image. For this tutorial, we will go ahead with Artifactory OSS
docker pull docker.bintray.io/jfrog/artifactory-oss:latest
docker run --name artifactory -d -p 8081:8081 docker.bintray.io/jfrog/artifactory-pro:latest
It is important to persist the artifacts which will be fed to Artifactory, so we have two options here
If artifactory was running using above command already then you need to stop the container using
docker stop artifactory docker rm artifactory
docker volume create --name artifactory5_data docker run --name artifactory-5.0.0 -d -v artifactory5_data:/var/opt/jfrog/artifactory -p 8081:8081 docker.bintray.io/jfrog/artifactory-pro:latest
OR
docker run --name artifactory-5.0.0 -d -v /Users/abhishek/jfrog/artifactory:/var/opt/jfrog/artifactory -p 8081:8081 docker.bintray.io/jfrog/artifactory-oss:latest
http://SERVER_DOMAIN:8081/artifactory
The post How to Install Artifactory on Docker appeared first on Little Big Extra.
]]>The post How to add remote archetype catalog in Eclipse appeared first on Little Big Extra.
]]>Maven remote catalogues are very useful in starting a project quickly and neatly. The project structure including src, test directory are created along with pom dependencies.
Follow below steps to add remote archetype catalogue
If you are behind a proxy you might need to go to Windows -> Preference-> Network and add the proxy details
Follow this Video for more details
The post How to add remote archetype catalog in Eclipse appeared first on Little Big Extra.
]]>