Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Painless Microservice Development

Painless Microservice Development

How to develop microservices with a Vagrant, Ansible and Nginx

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

Andrew Naydyonock

May 26, 2016
Tweet

Other Decks in Programming

Transcript

  1. Painless microservice
    development

    View Slide

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

    View Slide

  3. View Slide

  4. Microservice development
    Issues
    Solutions
    Advices

    View Slide

  5. Usual problems

    View Slide

  6. Not enough RAM

    View Slide

  7. Selenium test won’t run
    without a tweak

    View Slide

  8. Functional tests take
    forever to finish

    View Slide

  9. Infrastructure requires
    maintenance

    View Slide

  10. View Slide

  11. Possible resolutions
    • Buy more RAM

    • Don’t run selenium on a local machine

    • Infrastructure maintenance on Friday morning

    • Give up

    View Slide

  12. We actually bought RAM

    View Slide

  13. But it did not solve our
    problems

    View Slide

  14. Core concept
    Painless microservice development

    View Slide

  15. Service A
    Service B
    Front end
    All local
    Local

    View Slide

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

    View Slide

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

    View Slide

  18. Where we are now

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  24. Summary

    View Slide

  25. Not enough RAM
    Mock irrelevant services

    View Slide

  26. Selenium requires
    tweaks
    Production-like environment

    View Slide

  27. Functional tests are slow
    Personal Selenium Grid

    View Slide

  28. Infrastructure
    maintenance
    Automated provisioning

    View Slide

  29. How to make it real?

    View Slide

  30. Tools
    Ansible
    Vagrant
    Nginx
    Wiremock

    View Slide

  31. Ansible
    • Agentless

    • Idempotent

    • YAML-configured
    Build production-like VMs
    for development

    View Slide

  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

    View Slide

  33. Build production-like VMs
    for development
    • Easy to use

    • Light configuration

    • Works seamlessly with Ansible
    Vagrant

    View Slide

  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

    View Slide

  35. • Reverse proxy

    • Reload config on the fly
    Nginx
    Webserver

    View Slide

  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!")));

    View Slide

  37. A piece of cake
    git pull

    vagrant up

    View Slide

  38. Important bits

    View Slide

  39. Service discovery
    etcd + confd

    View Slide

  40. Nginx configuration
    Go for configuration file per service

    Bunch of includes in nginx.conf is easier to handle

    View Slide

  41. Databases
    Deploy all databases inside a Vagrant

    View Slide

  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

    View Slide

  43. VirtualBox dynamic port
    forwarding
    VBoxManage controlvm "VM name" natpf1 “postgres,tcp,,5432,,5432”
    VBoxManage controlvm "VM name" natpf1 delete postgres

    View Slide

  44. Selenium grid
    Having a selenium grid and a fistful of nodes will
    speed up your testing

    View Slide

  45. Docker
    Using docker inside a Vagrant makes your Ops
    tasks a breeze

    View Slide

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

    View Slide