How to deploy Ratpack API into remote server? - java

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?

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:
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'
}
Have your CI server or you manually execute `gradlew installShadowApp
SCP/FTP this artifact from your build/installShadow directory to your target server
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

Related

How to run java Google App Engine locally with app-gradle-plugin for yaml?

I am using Google App Engine gradle plugin with yaml file, but the plugin version for it has no task appengineRun or appengineStart like the appengine-web.xml version.
TL;DR appengineRun is only available for appengine-web.xml based projects. If you want to use app.yaml, you must provide your own server, for example Spring Boot with Jetty or Tomcat.
To run your application locally, you must provide your own server.
This guide shows how to test your application using app.yaml alongside with the app-gradle-plugin, on section Testing your application with the development server:
During the development phase, you can run and test your application at any time in the development server by invoking Gradle:
gradle jettyRun
Alternatively, you can run Gradle without installing it by using the Gradle wrapper.
As said on this comment on GitHub:
If you want to use app.yaml from your root directory, you must upgrade to Java 11. Learn more here. With the Java 11 runtime, you must provide your own server, for example Spring Boot with Jetty or Tomcat. The appengine:run goal does not work for app.yaml based projects because each server has a different start up command i.e. spring-boot:run for Spring Boot.

How can I Trigger local maven project from remote Jenkins?

I have created a simple Selenium+java maven project locally on my machine. I am able to execute the testing locally triggering it with Maven.
I want to trigger it from Jenkins (which is installed on a remote machine (my company's QA server))
I am using the option 'custom workspace' of Jenkins.
As the Jenkins is on the server, it's not able to understand/locate the local path
'C:\Automation\MavenProject\'
How I can achieve this?
You can do it with master-slave concepts in Jenkins. Slave machine would be your windows machine which will connect to master Jenkins with the help of some jars. You need to create a node on your Jenkins server and after adding the configuration, you need to download the corresponding slave jars on your machine. Once you execute those jars on your local machine, it will interact with Jenkins server. Your Jenkins job can then perform further activities on your slave machine.
Also in the Jenkins job, you need to refer to this node by enabling the following option.
Restrict where this project can be run
1)Create a Maven Project in Jenkins, you may have to install some plugin if its not visible
Pushing your code to some type of version Control like Github
You need to configure Jenkins to provide GitHub build information and POM Location
Since you Jenkins is hosted up in the server, you have be able to access it public, you need to download Github integration plugin and configure jenkins to provide GitHub hook trigger for GITScm polling and similar action in github itself
This should get you going, also google or youtube, lots of solution , one example
https://www.youtube.com/watch?v=PhxZamqYJws

How to rollback on Tomcat in case of unstable build using Jenkins?

I am using Jenkins to set-up a DevOps pipeline for a Java project. And am stuck at one scenario of deployment. If somehow there has to be roll-back of build on Tomcat server and build that has to replace this one has to be last stable build.
Suppose build#20 is deployed on server which is stable and build#21 is deployed in next build cycle but after deployment its found that this new build has issues. Now i want to replace this build by the previous build that is build#20.
The plugin I am using on Jenkins doesn't provide the facility of roll-back. Please help me out.
Plugin for deployment : https://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin
Just re-build build#20, call it build#22, and deploy it.
"Deploy" your build results to a deploy-candidate location and only (really) deploy them to Tomcat from there after it has turned out that your complete build process is stable.

How can I automatically deploy a war from Nexus to Tomcat?

How can I automatically deploy a war from Nexus to Tomcat?
I have a maven web project which gets built and deployed (both SNAPSHOT and release versions) on Nexus successfully. I would like to know if there is feature/plugin in Nexus where it picks the released war and deploys on remote Tomcat automatically?
I know that you can deploy the war to remote Tomcat using maven-tomcat-plugin but would like to know if there is an alternative solution.
Please guide.
Typically you'd use a CI tool like Jenkins to run the Maven build that publishes your War file into Nexus. Nexus would then be used by whatever tool you're using to push the War onto the target tomcat environment:
There are lots and lots of options.
Jenkins post build SSH script
Run a post-build SSH task from Jenkins that does something like this on the target tomcat server:
curl "http://myrepo/nexus/service/local/artifact/maven/redirect?r=releases&g=myorg&a=myapp&v=1.1&e=war" \
-o /usr/local/share/tomcat7/webapps/myapp.war
service tomcat7 restart
Rundeck
My preference is to use Rundeck for deployments, because it has a Nexus plugin, providing convenient drop-down menus of available releases.
There is also a Rundeck plugin for Jenkins that can be used to orchestrate a CI process with Jenkins performing the build, hand-over to Rundeck for deployment, followed by a Jenkins call-back to run the integration tests.
Chef
I also use chef which can be used to automatically deploy software in a pull fashion.
The artifact cookbook has direct support for Nexus, whereas the application_java cookbook uses a more generic "pull from a URL" approach that also works well.
..
..
The list goes on, so I hope this helps.
We used UrbanCode for the deployment automation, retrieves war from Artifactory/Nexus and deploy to the target server.
I used the Nexus Rest-API, these endpoints downloads the artifact to Jenkins workspace.
In order to deploy Snapshot & Release to Tomcat we can create a Jenkins parameterized job and pass the parameters to the REST endpoint, also to deploy to a server like Tomact "Deploy WAR/EAR" Jenkins plugin will help.
We can parameterize the endpoint and use as part of "Build" step along with "Execute Shell script" option for the build.
wget --user=${UserName} --password=${Password} "http://192.168.49.131:8080/nexus/service/local/artifact/maven/redirect?r=releases&g=${GroupId}&a=${ArtifactId}&v=${Version}&e=${TypeOfArtifact}" --content-disposition
Actual endpoints to Nexus looks something like below.
wget --user=admin --password=admin123 "http://localhost:8080/nexus/service/local/artifact/maven/redirect?r=snapshots&g=org.codezarvis.artifactory&a=hushly&v=0.0.1-SNAPSHOT&e=jar" --content-disposition
wget --user=admin --password=admin123 "http://localhost:8080/nexus/service/local/artifact/maven/redirect?r=releases&g=org.codezarvis.artifactory&a=hushly&v=0.0.5&e=jar" --content-disposition
Thanks
-Sudarshan

Maven/Jenkins automatic download/copy

I'm in a team to develop plugins in java.
We got Maven, a repository and Jenkins,
And I got myself a debian-server to test my applications.
When I push my commits, this happens:
Push in repository, upload and build in Jenkins.
Users download these .jar files and upload these to their server
What I want to be happen:
There are two ways,
First: After building with Jenkins: Download these files,
Second: When pressing "maven build", maven builds my applications and copy these to my server
How can I do this?
(Sorry for my bad English: I'm German)
If I understand you correctly, following scenario should help.
create two jobs
first job builds your artifact and archives it: user will be able to download it, job is triggered by source modification
second job is only executed manually (and requires two plugins, listed below), copies artifacts from first job and then uploads them to the server
Following plugins you would need to install:
copy artifact plugin to enable jenkins to copy artifacts from another job
publish over ssh plugin to enable jenkins to upload binaries and run commands on remote servers
You want when you push your SCM repository, to get Jenkins build into your local projet (update your jars), then manipulate send your final build to your server. Is that you want ?
If yes, I think that plugin would be interesting :
http://evgeny-goldin.com/wiki/Jenkins-maven-plugin#Supported_Plugins
you can manage jenkins goals from your pom.xml but I am not sure if you can get jenkins build.

Categories