Search code examples
javaeclipsegroovydeploymentratpack

How to deploy Ratpack API into remote server?


I have created an API using Ratpack and Groovy. All the GET, POST apps are working locally. Now I want this to move it to some remote server(say dev environment). How can I do this? To start and run the app in local, I have to do either "gradle run" or "Run the Ratpack.groovy as a groovy script" from eclipse IDE. Then it says "Ratpack Server running in localhost:8080". And then I can use the APIs as localhost:8080/api/.../.../... but at the same time when I try to run it as JAVA Application, I am getting error as:

{"@timestamp":"2016-06-02T14:47:06.026+05:30","@version":1,"message":"Starting server...","logger_name":"ratpack.server.RatpackServer","thread_name":"main","level":"INFO","level_value":20000,"tags":null}
Exception in thread "main" java.io.UncheckedIOException: java.io.IOException: Is a directory
    at ratpack.util.Exceptions.uncheck(Exceptions.java:52)
    at ratpack.groovy.Groovy.ratpack(Groovy.java:112)
    at ratpack.groovy.Groovy$ratpack.callStatic(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:206)
    at Ratpack.run(Ratpack.groovy:22)

To deploy it in prod, I moved the jar to the server. After that what should I do to start the Ratpack server or rather API service?


Solution

  • I would recommend setting up a CI pipeline that builds a java jar and deploys the artifact to your target environment.

    I recommend using the Shadow Plugin from John Engleman https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow

    This plugin produces a shadow jar (similar to Maven's shaded jar) that can optionally include bash scripts or batch scripts for starting your application.

    High level suggestion:

    1. Add the shadow plugin to your gradle build file

      plugins { id 'io.ratpack.ratpack-groovy' version '1.3.3' id 'com.github.johnrengelman.shadow' version '1.2.3' }

    2. Have your CI server or you manually execute `gradlew installShadowApp

    3. SCP/FTP this artifact from your build/installShadow directory to your target server

    4. Invoke the shell script from build/installShadow/$appName/bin/$appName to start application

    For a more maintainable solution I would recommend registering this shell script as a service or with a solution like monit/upstart/ etc

    For a more detailed example on deploying to Heroku as an example take a look at my notes: http://danhyun.github.io/2016-gr8confeu-rapid-ratpack-groovy/#deploying_to_heroku