The goal of the Logistcs application is find out the best route between two places within a map. Once created, add routes to the map, as following:
The best route is the cheapest one, considering the truck autonomy (Km/l) and the fuel price (l). Based on the routes above, if the truck has to go from place A to place D, its autonomy is 10 Km/l and the litre of the fuel cost $2.50, the best route will be A -> B -> D, because it's the cheapest one: $6.25.
The Logistics application has quality in its core. Beyond unit tests, the following projects were developed in order to validate the whole solution:
|Project||Test type||Build status|
Static code analysis
The application code quality is evaluated with SonarQube. If you want to run the SonarScanner for Maven in order to take a look at the static code analisys' results, firstly execute (requires Docker):
docker run --name sonarqube -p 9000:9000 -d sonarqube:8.4.1-community
mvn clean install sonar:sonar
After running the analysis, the Logistics application dashboard will be available in http://localhost:9000/dashboard?id=br.com.esign%3Alogistics.
The CI/CD Pipeline
Each push to this repository triggers the pipeline below:
- Travis CI clones this GitHub repository;
- After compiling and performing several unit tests in the application source code, Maven triggers the SonarQube static code analisys, and the results are sent to SonarCloud;
- Once generated the Java artifacts, they are deployed to Sonatype OSSRH, a Nexus Repository Manager instance Sonatype uses to provide repository hosting service to open source projects binaries;
- The application EAR file is deployed in a Wildfly instance avaliable at esign.com.br. From there, the Logistics application connects to a MongoDB instance hosted by MongoDB Atlas;
- Several tests are triggered asynchronously. Each one is performed against the Wildfly instance where the latest version of application was deployed.
Running with Docker
docker run --name logistics -p 8080:8080 -e MONGODB_URI=mongodb://username:password@host:port/logistics -d esignbr/logistics
The environment variable MONGODB_URI is mandatory and must set the MongoDB connection URI. Remember to replace username and password with your MongoDB credentials as well as host and port with the appropriate values, according with where your MongoDB instance is avaliable on.
docker-compose up -d
The application will be available through the URL http://localhost:8080/logistics in your browser.
Deploying to a local VM
Alternatively, you can deploy both the application and the database to a local VM, by using the Ansible playbook. If you want to know how it works, first install Ansible, VirtualBox and Vagrant, and then run:
Once the local VM is up, open the URL http://192.168.33.10:8080/logistics in your browser, and give the Logistics application a try.
Finally, if you want to cleanup everything, execute the command:
vagrant destroy -f && rm -rf .vagrant/
Deploying to AWS
If you've already installed Ansible, you can make the deployment in the cloud too. In spite Ansible has support to several Cloud providers, at the moment we only provide a playbook to deploy Logistics into an EC2 instance of AWS. Once you have your AWS credentials, run:
Ansible uses Boto 3 in its Amazon modules. During the execution, the playbook creates all the infrastructure required for accessing the application through the Internet. The AMI used is codeyourinfra/docker, one of the Codeyourinfra's AWS AMIs.
Right after the deployment, check the output to find out what is the EC2 instance public IP address. You can get the IP from the inventory.yml file as well. Then, open the Logistics' URL in your browser, replacing the IP with the one you've just got. Finally, if you want to undo everything, just run:
The Logistics API documentation is generated through Swagger and can be checked by accessing the
/logistics/docs endpoint, after deploying the application. In the Esign Consulting website, for example, the Logistics API documentation is available on http://www.esign.com.br/logistics/docs.
The Logistics application has a feature toggles admin console that comes with Togglz. The console can be accessed through the
/logistics/togglz endpoint, after deploying the application. In the Esign Consulting website, for example, the Logistics Feature Flags console is available on http://www.esign.com.br/logistics/togglz.