Friday, July 22, 2016

Setting up development environment with Docker, Maven and IntelliJ

This post walks through the setup of development environment for Docker with IntelliJ using Maven. We will use a Spring boot application and configure IntelliJ for iterative development.

Spring Boot Application

The demo application is a simple one page app which displays a chart of VIX index. We will wire Quandl’s web service to fetch the historical data about VIX index and use CanvasJS charting library to display the chart. You can learn more about Spring Boot application with this Spring GuideHere are some highlights:

Application.java

@SpringBootApplication is the convenience annotation that marks the class as an entry point.


AppConfig.java

Setup Spring wiring using java in this class. It is any class that is marked with @Configuration annotation.


View - JSPs

Application’s view pages are under /webapp/WEB-INF/jsp.  application.properties file provided configuration to wire Spring’s view resolver.

Static Content

Application’s static content under src/main/resources/static as below.




You can find entire source code here on github


pom.xml

spring-boot-maven-plugin make executing lifecycle events easier. If you open IntelliJ’s Maven window, you will see all spring-boot-run, which will allow you to run the project. You can also create run configuration for easy access.





Setting up Docker

You can setup Docker environment by following instructions from docker for mac documentation.


Docker, Maven and IntelliJ

We will use docker-maven-plugin from com.spotify

Docker file
Create src/main/docker/Dockerfile. 


pom.xml
Configuration for docker plugin


ServerId tag specifies the docker repository you want to push to. The credentials to the serverId needs to be provided in your maven settings.xml. You have option of mvn encrypting the password. Follow instructions here



Run Configuration
To get it running in IntelliJ, you can setup Run Configuration as follows: 
1. Open Run -> Edit Configuration
2. Add Maven Configuration
3. Provide maven command line as clean package docker:build

4. Go to the Runner tab and provide environment variables


     5. Similarly, you can also create docker:push run configuration, if you want to push docker image to docker registry. 




No comments: