Painless Microservice Development

Painless Microservice Development

How to develop microservices with a Vagrant, Ansible and Nginx

https://github.com/Vorago/painless-microservice-development

D540c621bcede03dc99d1c6f1cac6dd7?s=128

Andrew Naydyonock

May 26, 2016
Tweet

Transcript

  1. Painless microservice development

  2. Andrew Naydyonock andrew.naydyonock vorago vorago Software Engineer Team Lead Teacher

    Java DevOps
  3. None
  4. Microservice development Issues Solutions Advices

  5. Usual problems

  6. Not enough RAM

  7. Selenium test won’t run without a tweak

  8. Functional tests take forever to finish

  9. Infrastructure requires maintenance

  10. None
  11. Possible resolutions • Buy more RAM • Don’t run selenium

    on a local machine • Infrastructure maintenance on Friday morning • Give up
  12. We actually bought RAM

  13. But it did not solve our problems

  14. Core concept Painless microservice development

  15. Service A Service B Front end All local Local

  16. Service A Service B Front end VM All in a

    VM
  17. Nginx Service A Service B Front end VM All in

    a VM + Nginx
  18. Where we are now

  19. Nginx Service A Service B Front end Service A Service

    B Front end VM One service running from IDE Local
  20. Nginx Service A Service B Mock Front end Service A

    Service B Front end VM How about a mock? Local
  21. Nginx Service A Mock Service B Front end Service A

    Service B Front end VM Developing Service B Local
  22. Nginx Service A Mock Service B Mock Front end Service

    A Service B Front end VM Front end Local
  23. Nginx Service A Service B Front end VM Selenium Local

  24. Summary

  25. Not enough RAM Mock irrelevant services

  26. Selenium requires tweaks Production-like environment

  27. Functional tests are slow Personal Selenium Grid

  28. Infrastructure maintenance Automated provisioning

  29. How to make it real?

  30. Tools Ansible Vagrant Nginx Wiremock

  31. Ansible • Agentless • Idempotent • YAML-configured Build production-like VMs

    for development
  32. For both production and local environments ---
 - hosts: vagrant


    become: true
 become_user: root
 tasks: 
 - name: Install nginx
 apt:
 name: nginx
 state: present 
 - name: Autostart nginx
 service:
 name: nginx
 enabled: yes
 state: started
  33. Build production-like VMs for development • Easy to use •

    Light configuration • Works seamlessly with Ansible Vagrant
  34. ansible-provision.sh Vagrantfile Vagrant.configure('2') do |config|
 config.vm.box = 'ubuntu/trusty64'
 config.vm.synced_folder '.',

    '/vagrant'
 config.vm.network 'forwarded_port', guest: 80, host: 8080 config.vm.provision :shell, path: 'bootstrap.sh'
 config.vm.provision :shell, path: 'ansible-provision.sh'
 end
 cd /vagrant/ansible
 ansible-playbook setup.yml -i inventory/local
  35. • Reverse proxy • Reload config on the fly Nginx

    Webserver
  36. • Fluent API • Lightweight WireMock Java framework for HTTP

    stubbing new WireMockServer(8888).start();
 WireMock.configureFor("localhost", 8888);
 
 stubFor(get(urlEqualTo("/hello"))
 .willReturn(aResponse()
 .withHeader("Content-Type", "text/plain")
 .withBody("Hello world!")));
  37. A piece of cake git pull vagrant up

  38. Important bits

  39. Service discovery etcd + confd

  40. Nginx configuration Go for configuration file per service Bunch of

    includes in nginx.conf is easier to handle
  41. Databases Deploy all databases inside a Vagrant

  42. Databases & Vagrant Vagrant.configure('2') do |config|
 config.vm.box = 'ubuntu/xenial64'
 config.vm.synced_folder

    '.', '/vagrant'
 config.vm.provision 'shell', path: 'bootstrap.sh'
 config.vm.network 'forwarded_port', guest: 80, host: 8080
 config.vm.network 'forwarded_port', guest: 5432, host: 5432
 config.vm.provision :shell, path: 'ansible-provision.sh'
 end
 
 Don’t forget to forward your ports
  43. VirtualBox dynamic port forwarding VBoxManage controlvm "VM name" natpf1 “postgres,tcp,,5432,,5432”

    VBoxManage controlvm "VM name" natpf1 delete postgres
  44. Selenium grid Having a selenium grid and a fistful of

    nodes will speed up your testing
  45. Docker Using docker inside a Vagrant makes your Ops tasks

    a breeze
  46. Q & A Proof of Concept vorago/painless-microservice-development