javalite / activeweb

ActiveWeb moved, see below

Home Page:http://javalite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Production

nibarulabs opened this issue · comments

My team and I have made some good progress using ActiveWeb for two big projects we're rolling out. We're all Rails app developers as well - for many years - so we understand the concepts thoroughly. We're actually happy someone has made a very close equivalent in Java - well done.

One of the things I find lacking is how-to for production. Development seems covered fairly well, but I'm setting up our production stack and making slow progress. Below will part answer (for anyone else looking) and question for things we still have not solved.

Seeds

At first we were creating a migration for seed data. But we soon found out that this conflicted with test data and later after looking thru the docs more, saw that migrations are only for structure, not data. So we have had to create a seeds directory at source level (still not sure if this is the right place) to keep them separate.

Question: How has anyone else done this for production? Best practices/hints?

Migrations / db creation

It looks like all the documentation points to using this with maven (our build tool). However, I don't think this is the right approach for production.
In Rails we would make rake tasks to kick off migrations/data updates, which would be the maven analog for AW, but I'm looking for a different way.

Question: I'd prefer not to install maven on our production instance(s) to get the db setup, but it's not clear to me what other alternative there is than scripts or calling the sql individually from a logged in db user.

Webapp deployment

This is also something that isn't really documented anywhere. There are lots of examples on jdbc settings and such for prod, but I didn't find any single source as to how I would get everything running on a deployed Jetty.

Obviously we package a war file and deploy that out, but I found it took me a while to configure the stack with the correct jndi entries for jdbc pooled connection. This was especially necessary since I need that pool for Async tasks (which my service uses a lot). There was a lot of going back and forth between the javalite site docs, jetty docs, stack overflow, google. It took me quite a while, but I got production jndi jdbc to work this morning.

Question: Again, what are the best practices for deployment stack?

I would consider providing a doc on how we did it since we're using Postgres and deploying on our own Digital Ocean instance(s) (I tried getting Elastic Beanstalk running and gave up after 3 days..).

Conclusion

All of the above I've done many times with Rails production systems. I left Java development many years ago (my team and I released some big production products in early 2000's using Spring & Hibernate - one of our devs was at BEA) because it wasn't productive for small teams. I came back into java this year for some projects me and my team are creating in the cryptocurrency space. Javalite seems to be the only Java web dev stack I've seen that makes me not want to smash something. But, there still needs to be some better docs on how to get production released. Hopefully, this can help get some of that rolling.

We are releasing our two projects over the next few days, so I will just do what needs to be done. But, it would be good to highlight how to do these things in AW that we did regularly in Rails. Let me know how I can help. And hopefully, we can answer the questions above. Thanks!

@nibarulabs, thanks for a very detailed question. I also have some experience (on and off) with Rails, but I have been building commercial systems for big brands on JavaLite for the last 9 years, and surely accumulated experience with deployments, migrations, etc.
One of the reasons this is not well documented is because JavaLite projects are standard J2EE projects, so deployment process is taken care of by documentation of a target container.

I will share my experiences in a form of additional pages on the JavaLite.io site and link from here in the next few days.

Additionally, there is a ton of approaches, dos and donts we accumulated as pertained to development with JavaLite (aka design patterns), and I need to sit down one day to do a brain dump ;)

Good luck with your deployment!

Understood. I think I have most of the container issues more or leas worked out.

My only question is do you have any recommendation for how you do migrations on production systems? Run mvn migrate on the prod db?

I’ll keep looking regardless, thx.

@nibarulabs , we use Jenkins for tasks like that. For instance, we have a script:

#!/bin/bash

if ! [ $# == 2 ]; then
  echo "You need to supply BRANCH and ENVIRONMENT as arguments"
  echo "example: ./run_migrations.sh master testenv"
  exit 0
fi

cd ~/projectname
git checkout $1
git pull --rebase

cd common
mvn db-migrator:migrate -Denvironments=$2

This script is installed on the Jenkins box. We also configured Jenkins job to run this script with two arguments:
selection_001364

So, when we need to deploy to a specific environment, we simply click a few buttons to run migration in that environment, then deploy the war files to all Tomcats in the cluster.

Another Jenkins job calls a different script that does actual deployment.
selection_001365

So, the process is simple so even a non-technical person can deploy if needed.

The Jenkins jobs display console output, and we then use Jenkins links to specific builds for release notes.

Needless to say, the Jenkins machine needs to have access to target databases.
The added benefit of using Jenkins is that you have a history of who did what/when

Ok, this makes sense and I get why.

I did not think about runnng the migrations from a different server connected to the prod db. So, technically, this could even be a local thing where I have a bastion server to tunnel thru to my prod db and then run the production migration through there.

Thanks, this gives me options!

Sure, but we prefer Jenkins for convenience and accountability.

Makes sense and I think we will eventually use the same model. Haven’t used Jenkins in a while, so I will have to dig back into that and replicate close enough to your screenshots. Thanks for sharing those. 👍