Monday, September 02, 2013

Building and Deploying Code. Trials and Tribulations.

Random notes for today's challenge: Packaging up my AWS web app for deployment.

The time it takes me to get something from "working" to "deployed" is somewhat annoying. Going to work on streamlining this. Making notes for future reference.

Tangent...

While testing...interesting that when a resource isn't found my customized web server just hangs. Should look into that. Shouldn't the connection get killed or time out or something? This happened with code that runs fine in Eclipse bug fails due to resource file being referenced in two different locations in a mountain of code.

Had an issue with recursive page loads - dumb code I forgot I left in last time I was playing around with these things. Put something in place to prevent but if happens again possibly a threshold to auto-block excessive requests. Had this before but reworking it...bad, bad, bad.

While creating a jar random things: 

The classpath and main class has to be in the manifest file. Can add that with ant build as noted in previous post.

To run  from bat file java -jar with appropriate command line arguments

Why does my properties file for Ant build script need a hard coded rather than relative path to the build script? Obviously that is being round relative to the executable or something.

Keeping Ant and Eclipse in sync...differences in code execution

Ant seems to be finding references to classes differently than Eclipse. What was working in Eclipse was failing in Ant so had to rearrange things a bit.

I also rearranged to remove extraneous 3rd party libraries from build which made Ant script take longer than necessary. I forgot my ant script was using that directory after not playing around with this for months.

When I rearranged things I move a jar to a more logical place Ant was happy but Eclipse no longer was, so I had to go fix my Eclipse projects...keeping all these things in sync is kind of a pain. Must be a more organized way to do this. Maybe they can all read the same config files or something. Maybe I could use Eclipse plugins but wanted to know exactly what was going on in my build scripts instead of having things happen automagically.

Most of my problems  - yes I know - are a result of sloppy piecing together of mountains of open source code, which I will fix by streamlining to remove duplicate nonsense. The initial goal was to prove a concept. Now must make it pretty and accurate and clean...it's bugging the crap out of me. If I was starting from scratch I would have it clean from the start but there are about 10 years of ideas floating around in this mess.

Testing AWS components

Once I got my code to work I uncommented and tried to run the piece that logs to SQS.

Was trying to just run my app locally compiled and built and the AWSCredentials file could not be found on the classpath. Built it in there temporarily just to make sure my compiled build works, but now have to take it out and run correctly using AWS IAM Roles.

Also had to change my build to use all the AWS 3rd party libraries that did not cause a compilation error but when built did not run without being included in the manifest classpath.

Next I had to build and run the queue reader service. After reminding myself how all my build scripts work above was built and running in one try. Amazing.

Environment Differences

Managing different environment configurations is always fun. I have to have my build add in the credential file if running and testing locally, and use IAM roles when building for deployment in production.

When building for deployment in production need to spin up an instance and deploy the code. Where to store the code securely, how to access it, who has permissions to view it...all questions with answers in my head to be proven at a later date.

Working with someone on CloudFormation scripts to spin up instances and somehow get the code on there but for now just going to deploy manually.

When deploying the code there are different configurations that need to be applied for domains and web requests. Possibly can put this in a database or s3 and load it up at run time. Getting there...

IAM Roles...

IAM Roles allow an instance to access a resource without hard coding credentials on the machine. I can't use IAM Role from my local machine since it's not an AWS instance. AWS IAM roles are better for many reasons as noted here:

http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html