3

I've been setting up my rails application to run under jruby/warbler inside a java container (JBoss/wildfly). I'm used to running my rails apps on linux machines, more or less with init.d scripts and the like, and I've been using DATABASE_URL to set the connection without putting my credentials in the source.

Warbler itself is created a pre-packaged WAR, I can deploy that to wildfly(jboss) fine.. but there is no examples of how to set environment variables in the context of that application.

I've googled links, but they are cryptic as hell, there's even a stack overflow question here, but the accepted answer seems to be make your own service between to do this?.

Is there an easy way to pass config to wars in jboss?, or do all java enterprisey applications just store the credentials/urls in the war themselves O.O

Beau Trepp
  • 2,610
  • 4
  • 22
  • 30

2 Answers2

2

You could setup a datasource on the application server https://docs.jboss.org/author/display/WFLY8/DataSource+configuration

And in your application you will need to use ActiveRecord-JDBC-Adapter https://github.com/jruby/activerecord-jdbc-adapter

Or you can also set environment variables in the application servers's startup script (bin/standalone.sh or bin/domain.sh)

cego
  • 194
  • 7
  • 1
    Looking at that, if I edited the standalone.sh(well .bat in my case... windows). It would be available for all the 'apps' deployed in JBOSS. That seems... wrong. I would prefer it to be set per application itself. ActiveRecord uses DATABASE_URL if present, so If I ran two different applications I would have to edit one to be aware of that. Is it possible to use those datasources from ruby itself?. I'm not sure how I would plug into that in my rails code. – Beau Trepp Jun 16 '14 at 08:17
  • 1
    If you want per application configurations then you really have to setup datasources. In your application you need to use something like ActiveRecord-JDBC-Adapter. Will update my answer to cover mention this. – cego Jun 16 '14 at 15:53
1

if you're using Warbler (JRuby-Rack) the environment can be isolated using a context-parameter setting in the deployment descriptor e.g. :

<context-param>
  <param-name>jruby.runtime.env</param-name>
  <param-value>
    DATABASE_URL=mysql://192.168.1.11/mydb
    PATH=/usr/local/bin,HOME=/home/tomcat
  </param-value>
</context-param>

it's pretty easy to set with Warbler's configuration file (generate one at config/warbler.rb using warble config) https://github.com/jruby/jruby-rack/wiki/ENV-Isolation#warbler

kares
  • 7,076
  • 1
  • 28
  • 38
  • 1
    That is still equivalent to me putting the database details in database.yml though. My WAR file has the configuration inside it. To deploy to a different machine (with say a different user/name password) I would have to run warble again?. Maybe I'm viewing wars in the completely wrong way, but I feel the idea of which database to point to would not be what gets packaged in the shipped/compiled product. Or is that context param section part of the jboss configuration files? Where does it live? – Beau Trepp Jun 18 '14 at 01:58
  • it seems really not 100% clear what you want ... from the previous answer I get the impression that you'd like to deploy multiple apps on a single server and read a "different" `DATABASE_URL` from `ENV` ? – kares Jun 18 '14 at 20:07
  • it seems really not 100% clear what you want, from the previous ... in that case maybe the easiest way is to introduce some conventions e.g. **[context-name].env** file on the class-path read from upon initialization that updates `ENV` (just put the code under **WEB-INF/init.rb**) – kares Jun 18 '14 at 20:33
  • 1
    I got the impression from jbossw/wildfly that it's used to host multiple apps. If for instance I put a second rails app on the server, I would want different DATABASE_URL env variables for them. I guess the point is I was trying to keep the database config out of the WAR file, in other situations storing things like usernames/passwords in binaries (which is what a war file seems to feel like) is considered bad practice). I'm getting the impression that the ENV-Isolation in warbler will add files to the war?, its just like adding the database.yml to the compiled files but under a different name – Beau Trepp Jun 20 '14 at 03:29
  • 1
    I guess I'm after either a way similar to a) deploy a war like I would upload to heroku. or b) at least keep the information about what database to use outside of the war, like how I would have an /etc/app/database.conf folder on a linux machine. – Beau Trepp Jun 20 '14 at 03:30