Ratpack on CloudFoundry

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Ratpack on CloudFoundry

glaforge
Hi all,

I wanted to play a bit with Ratpack, and deploying a demo app on CloudFoundry.

I took the latest Ratpack lazybones template.

I tried to follow the instructions from Tomas here:
http://fbflex.wordpress.com/2013/08/07/ratpack-to-cloudfoundry-with-java-buildpack/

The cf push command needs an update because the convention for the Ratpack run scripts have changed a bit (build/install/yourappname/bin/yourappname instead of build/install/server/bin/server)

I even added a settings.gradle file to be explict about my app name (rather than defaulting to the name of the base directory of my project) as Dan showed for the Heroku deployment: http://slideshare.net/danveloper/slides-27337436

I also tried with the buildpack from Tomas:
https://github.com/tomaslin/heroku-buildpack-ratpack
(although it's for Heroku, most Heroku buildpacks are working more or less as is on CloudFoundry)

But despite all those trials and errors... I invariably get "Application failed to stage" from CloudFoundry.

So my question: has anyone succeeded in creating and deploying a Ratpack that deploys well on CloudFoundry?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

Luke Daley
Administrator
Any more detail on the error? Any logs?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
Well, no.
The various ways of getting some more information from CloudFoundry don't give anything meaningful.
Asking to some CloudFoundry-knowledgeable persons, it seems the old approach used by Tomas won't like work anymore.
But now... what is the correct approach...


On Mon, Jan 13, 2014 at 12:08 PM, Luke Daley [via Ratpack Forum] <[hidden email]> wrote:
Any more detail on the error? Any logs?



If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Ratpack-on-CloudFoundry-tp308p309.html
To unsubscribe from Ratpack on CloudFoundry, click here.
NAML



--
Guillaume Laforge
Groovy Project Manager
Pivotal, Inc.

Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
If I want to run my Ratpack app with Ratpack's main class, I *just* need to call the GroovyRatpackMain class? Or do I have to pass particular parameters?
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

rus
Have you tried pushing a fat jar?  I think your start command would then just be "java -jar <appname>-fat.jar"
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
Nope, I haven't tried that.
./gradlew fatJar
fails with a Java Heap Space issue :-)
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
And giving it a bit more memory with -Xmx1024m it then fails with:
> Could not create an instance of type org.gradle.api.internal.tasks.DefaultTaskCollection_Decorated.
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

Luke Daley
Administrator
In reply to this post by glaforge
You don't need to pass anything, but your deployed version of src/ratpack must either be the JVM working directory, or be on the classpath and contain a ratpack.properties file.
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

Luke Daley
Administrator
In reply to this post by glaforge
Error messages, Guillaume… we need them.

Please run with -s and provide the trace.
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
Yeah that one was my fault, I didn't properly give it enough memory the right way (as the -Xmx param has to be passed through GRADLE_OPTS instead).

So I successfully created the fatjar, but I'm more and more convinced the problem likely lies on the CloudFoundry side :-(
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

Luke Daley
Administrator
I'll take a shot at this tonight and see if I have any more luck.
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

rus
In reply to this post by glaforge
I have this working with AppFog which is built on CloudFoundry.

If you now have a fat jar then navigate into build/libs and do the follwing (but you may need to change af with cf):

af push ratpack-app

Accept the defaults but for start command use "java $JAVA_OPTS -Dratpack.port=$VCAP_APP_PORT -jar <myapp>-fat.jar"

And make sure you enter a deployed url e.g. <myapp>.eu01.aws.af.cm

My ouptput looks like:
Would you like to deploy from the current directory? [Yn]:
Detected a Standalone Application, is this correct? [Yn]:
1: clr20
2: clr40
3: java
4: node04
5: node06
6: node08
7: node10
8: php
9: python2
10: ruby18
11: ruby192
12: ruby193
Select Runtime [java]:
Selected java
Start Command: java $JAVA_OPTS -Dratpack.port=$VCAP_APP_PORT -jar myapp-fa
t.jar
1: AWS US East - Virginia
2: AWS EU West - Ireland
3: AWS Asia SE - Singapore
4: HP AZ 2 - Las Vegas
Select Infrastructure: 2
Application Deployed URL [None]: ratpack.eu01.aws.af.cm
Memory reservation (128M, 256M, 512M, 1G, 2G) [512M]:
How many instances? [1]:
Bind existing services to 'ratpack'? [yN]:
Create services to bind to 'ratpack'? [yN]:
Would you like to save this configuration? [yN]:
Creating Application: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (0K): OK
Push Status: OK

Staging Application 'ratpack': OK

Starting Application 'ratpack': OK

Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

jamesbayer
In reply to this post by glaforge
Guillaume, we're about to add much more helpful error messages for failures during the staging process into the mainline Cloud Foundry OSS. There is a staging environment you could try pushing the app to where these additional logging values are create.

Here are some troubleshooting tips if you are pushing to run.pivotal.io which runs with the latest OSS build.

1) use the new golang version of the cli [1], which has support for the log aggregation from multiple system and app sources and streams it back to the client using websocket. once the app is being pushed (not before the app exists), you can do:
gcf logs APPNAME
the logs are finally becoming a much improved single place to look for app troubeshooting including staging, starting, and running your app.

2) 'gcf events APPNAME' should show you if your app has exited at all (for example if it was killed for not having enough memory or if it exitted on its own due a 'command not found' or similar error.

3) if the app is failing the health check (if you have a route mapped to your app), then you have 1 min post-start by default (can ask for up to 3 min) for the port that was assigned by the container in $PORT to start listening for TCP connections. if that is your problem, you can get further by not mapping the route to your app when you are starting (if it's already mapped now, you can use the unmap-route command in gcf). if your app starts correctly, your app will not be accessible by the router without a route, but you can get more time to review the logs to see if your app started. one thing i like to review is:
gcf files APPNAME staging_info.yml which shows the start command issued. which is something like [2] using the java buildpack with tomcat.

[1] https://github.com/cloudfoundry/cli#downloading-edge
[2]
---
detected_buildpack: openjdk=1.7.0_45 tomcat=7.0.47 tomcat-buildpack-support=1.1.1
start_command: JAVA_HOME=.java JAVA_OPTS="-Dhttp.port=$PORT -Djava.io.tmpdir=$TMPDIR
  -XX:MaxPermSize=64M -XX:OnOutOfMemoryError=./.buildpack-diagnostics/killjava -Xmx160M
  -Xss853K" .tomcat/bin/catalina.sh run

let me know if you need more help.
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

rus
In reply to this post by glaforge
For CF V2 create a file in build/libs called manifest.yml with the following content and then do "cf push ratpack"



---
applications:
- name: ratpack  memory: 512M
  instances: 1
  host: ratpack
  domain: de.a9sapp.eu
  path: .
  command: java $JAVA_OPTS -Dratpack.port=$PORT -jar ratpack-fat.jar
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

Luke Daley
Administrator
Might need a blog post on this at some point Rus :)
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

rus

It's on the list :)

On 13 Jan 2014 19:57, "Luke Daley [via Ratpack Forum]" <[hidden email]> wrote:
Might need a blog post on this at some point Rus :)



If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/Ratpack-on-CloudFoundry-tp308p322.html
To start a new topic under Ratpack Forum, email [hidden email]
To unsubscribe from Ratpack Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
I've had success deploying my Ratpack app on Cloud Foundry, thanks to Ben Hale's help and his custom Ratpack-dedicated Cloud Foundry buildpack.

The steps I followed (more or less) can be seen here in my sample project on Github:
https://github.com/glaforge/ratpack-demo-cloudfoundry/blob/master/README.md

The idea is to actually use the distZip distribution, which is easier / faster to upload to Cloud Foundry.
And Ben's buildpack setups the port appropriately for Ratpack.

It'd be nice to have Ratpack also read environment variables for things like the port, for instance it could look up RATPACK_PORT as env var?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

glaforge
I created an issue for Ratpack support in Cloud Foundry's Java buildpack:
https://github.com/cloudfoundry/java-buildpack/issues/32

And also a ticket to Ratpack's issue tracker to allow Ratpack to read environment variables for the port:
https://github.com/ratpack/ratpack/issues/239
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

rus
In reply to this post by glaforge
Glad you got it working.

Ratpack does read a system property for the port "ratpack.port" which can be set to an env var.  Like in my command I was using "java $JAVA_OPTS -Dratpack.port=$VCAP_APP_PORT -jar test-fat.jar"

I still don't entirely understand why the fatjar method doesn't work, but it does on Anynines.  All the Twitter comments were around having problems uploading a jar with a large amount of files in it.  But I'm not sure what the number of files in the jar has to do with it.  When you run distZip for the example-books project it still produces a 14MB zip file which is the same size as the jar file.  There's something I'm not understanding here.

Anyway, at least you're up and running.
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack on CloudFoundry

rus
Well, you're up and running for now.  What happens for real world apps where there are more dependencies and more class files of your own.  What's the limit to the number of files in a zip CF can handle????
12