How to add/debug module in vagrant image (jar file)

Small guide for those who are trying to add and test own modules with vagrant integration for the first time. 

Step-by-step guide

  1. Download vagrant image from Folio vagrant storage. (Preferable 'folio/testing' or 'folio/testing-backend')
  2. Modify Vagrant file by adding following string

    config.vm.network "forwarded_port", guest: 5005, host: 5005
  3. Build the jar using 'mvn clean install' command and place '*-fat.jar' into shared folder with name .vagrant
  4. Run vagrant image

    vagrant up
    vagrant ssh
  5. Set DB config properties to the environment variables

    curl -w '\n' -D - -X POST  \
      -H "Content-type: application/json" \
      -d '{"name":"DB_HOST", "value":"10.0.2.15"}' \
      http://localhost:9130/_/env
    
    curl -w '\n' -D - -X POST  \
      -H "Content-type: application/json" \
      -d '{"name":"DB_PORT", "value":"5432"}' \
      http://localhost:9130/_/env
    
    curl -w '\n' -D - -X POST  \
      -H "Content-type: application/json" \
      -d '{"name":"DB_USERNAME", "value":"folio_admin"}' \
      http://localhost:9130/_/env
    
    curl -w '\n' -D - -X POST  \
      -H "Content-type: application/json" \
      -d '{"name":"DB_PASSWORD", "value":"folio_admin"}' \
      http://localhost:9130/_/env
    
    curl -w '\n' -D - -X POST  \
      -H "Content-type: application/json" \
      -d '{"name":"DB_DATABASE", "value":"okapi_modules"}' \
      http://localhost:9130/_/env

    DB_HOST value should be the same as nodeId (see step 7).

  6. Deploy ModuleDescriptor 
    (send ModuleDescriptor.json with request)
  7. Deploy module

    For debug
      "exec": "java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar /vagrant/.vagrant/<MOD-NAME>-fat.jar -Dport=%p"
    
    
    vagrant ssh -c "ip address show eth0 | grep 'inet ' | sed -e 's/^.*inet //' -e 's/\/.*$//'" # find IP to place for 'nodeId'
  8. Enable module for tenant

    http://localhost:9130/_/proxy/tenants # GET available tenants
  9. Open IDE and setup Debug Configuration 
  10. Set breakpoint and click on 'Debug' button
  11. Perform the call to module

    http://localhost:9130/hello
  12. Enjoy debugging