Getting up and running - Turbots/oraj-360-tool GitHub Wiki

Tooling

Vagrant and Docker

Several tools are being used to ease setup of development environments and facilitate the Continuous Integration and Delivery process.

The project contains a folder called 'backend/docker' which contains a Vagrantfile and folders per service which contain a Dockerfile. These files allow you as a developer to start a Virtual machine (using Vagrant) which will start all our microservices using Docker.

You can download the Vagrant command-line tools at https://www.vagrantup.com/downloads.html. You can download Docker from https://docs.docker.com/installation/#installation

Build automation tools

Travis

Setting up your development environment

Vagrantfile

VM config

Vagrant.configure("2") do |config|
  config.vm.box = "chef/ubuntu-14.04"
  config.vm.synced_folder "../threesixtytool", "/threesixtytool", create: true
  config.vm.network "forwarded_port", guest: 8888, host: 18888
  config.vm.network "forwarded_port", guest: 7980, host: 17980
  config.vm.network "forwarded_port", guest: 7981, host: 17981
  config.vm.network "forwarded_port", guest: 8080, host: 18080
  config.vm.network "forwarded_port", guest: 8081, host: 18081
  config.vm.network "forwarded_port", guest: 8082, host: 18082
  config.vm.network "forwarded_port", guest: 8989, host: 18989
  config.vm.network "forwarded_port", guest: 8761, host: 18761
  config.vm.network "forwarded_port", guest: 9900, host: 19900

  config.vm.provider "virtualbox" do |v|
    v.memory = 4096
    v.cpus = 2
  end

In the above piece of code from the vagrant file we see some config concerning the vm itself.

  • config.vm.box = "chef/ubuntu-14.04" indicates we're instantiating an ubuntu vm
  • config.vm.synced_folder "../threesixtytool", "/threesixtytool", create: true means we're defining ../threesixtytool (the folder containing our maven modules) as a synced_folder. This folder will be mounted to /threesixtytool on the vm. This also means, that when we perform a mvn clean install on our project, the jar files will be accessible on the vm in /threesixtytool.
  • Next, there are a bunch of ports being forwarded to the host machine (your actual machine). These are the ports which our dockerised microservices will be binding to. By forwarding them to our host machine, we can access our microservices, running on the vm, through localhost.
  • And finally, some memory and cpu's are being assigned to the vm. For performance reasons, the 4096Mb of memory might be adjusted to a lower number in the future.
  • The folder from which we run the vagrant up command will also automatically be mounted to the vm under /vagrant

Docker config

Configuring your vagrant instance is done by using provisioners. A Docker provisioner is available which will automatically download and install docker for you. This provisioner can then be used to configure your specific docker containers on the VM.

config.vm.provision "docker" do |d|
    d.build_image "--tag=mongodb /vagrant/mongodb"
    d.build_image "--tag=service-registry /vagrant/service-registry"
    d.build_image "--tag=config-server /vagrant/config-server"
    d.build_image "--tag=zuul /vagrant/zuul"
    d.build_image "--tag=hystrix /vagrant/hystrix"
    d.build_image "--tag=turbine /vagrant/turbine"
    d.build_image "--tag=person-service /vagrant/person-service"
    d.build_image "--tag=timeline-service /vagrant/timeline-service"

    d.run "mongodb",
      args: "-p 27017:27017 \
        -e MONGODB_USERNAME=threeSixtyAdmin \
    -e MONGODB_PASSWORD=password \
   	    -e MONGODB_DBNAME=threeSixty"

    d.run "service-registry",
      args: "-p 8761:8761 -v /threesixtytool:/threesixtytool"
    d.run "config-server",
      args: "-p 8888:8888 -v /threesixtytool:/threesixtytool --link service-registry:eureka"
    d.run "person-service",
      args: "-p 8081:8081 -v /threesixtytool:/threesixtytool --link service-registry:eureka --link mongodb:mongodb --link config-server:config-server"
    d.run "timeline-service",
      args: "-p 8082:8082 -v /threesixtytool:/threesixtytool --link service-registry:eureka --link mongodb:mongodb --link config-server:config-server"
    d.run "zuul",
      args: "-p 9900:9900 -v /threesixtytool:/threesixtytool --link service-registry:eureka"
d.run "hystrix",
      args: "-p 7980:7980 -v /threesixtytool:/threesixtytool --link service-registry:eureka"
    d.run "turbine",
      args: "-p 7981:7981 -v /threesixtytool:/threesixtytool --link service-registry:eureka"
  end

The above snippet of code show how the docker provisioner:

  • builds all images and gives them easy-to-remember names. The images are being built using the Dockerfiles in the /vagrant// folders
  • runs all images by referring to them using the names they were given when they were built. Each d.run command takes a number of arguments, being:
    • the '-p' argument for forwarding ports from the docker containers to the vagrant vm.
    • the '-v' argument for adding volumes to the docker container. Volumes are nothing more then folders being mounted to the docker containers. Recall that the /threesixtytool already was mounted to the vm in a similar fashion.
    • the '--link' arguments for linking docker containers together. By doing this, entries are being added to the docker's /etc/hosts file allowing us to contact these linked docker containers.

Running the development environment on a VM

  1. Download and install vagrant
  2. cd into the 360-tool/backend/docker folder
  3. execute following command to spin up your Dev environment vagrant up

The first time, you execute vagrant up, the vm image will be downloaded, all docker images will be built and the docker containers will be started.

Shutting down a VM is done by executing the vagrant halt command. This will shutdown your VM but preserve everything you've done on it.

Starting the VM after the first time can also be done by executing vagrant up. But now the docker containers are no longer started automatically. That's because the provisioner only runs the first time. You should explicitly mention that you want the provisioner to run on all consecutive runs. You can do this by executing vagrant up --provision or vagrant up followed by vagrant provision.

Running the front-end application

In the previous section we've explained how you can setup your development environment and how to start the microservices application. Now we'll explain how you can run the front-end application on your machine.