Archive for category Software Development

AWS CloudFront invalidation

It is now possible to invalidate objects (files) inĀ AWS CloudFront distributions. Handy when someone, like me, occasionally publishes files with the wrong content type. Here is how I implement this invalidation in python.

Tags: , , , ,

JRuby rake and maven

I cannot stand Maven. It makes me nauseous. However that does not seem to be the case for other institutionalised developers. Here’s what I did on a project where I wanted to isolate its craziness and still use jruby and rake.

namespace :maven do

  M2_HOME = "binaries/apache-maven-3.0.3"

  desc "Run the maven package goal"
  task :package => :clean do
    mvn "package"
  end

  desc "Run the application"
  task :application => :clean do
    mvn "test-compile", "exec:java", "-Dexec.mainClass=com.example.Application", "-Dexec.classpathScope=test"
  end

  desc "Run the maven dependencies report"
  task :dependencies do
    mvn "dependency:tree", "-DoutputFile=deps.txt"
  end

  def mvn(*args)
    require 'java'

    m2_conf = "#{M2_HOME}/bin/m2.conf"
    classpath = "#{M2_HOME}/boot/plexus-classworlds-2.4.jar"

    java.lang.System.setProperty('maven.home', M2_HOME)
    java.lang.System.setProperty('classworlds.conf', m2_conf)

    require classpath
    include_class Java::org.codehaus.plexus.classworlds.launcher.Launcher
    exit_code = Launcher.mainWithExitCode(args.flatten.to_java(:string))
    puts "Maven has completed with exit code: #{exit_code}"
    fail 'Build failed' if exit_code != 0
  end

end

You foul rancid beast.

Tags: , , ,

RubyGems in a JAR

On a few projects now I’ve used jruby with rake. I know that I can use rvm and just fetch the gems per project, but for developers stuck on windows that way is a little more than difficult. So here’s how I package up rubygems in a JAR.

#!/bin/bash
mkdir gemjar
java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar haml --version 3.1.2 --no-rdoc --no-ri
java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar net-scp --version 1.0.4 --no-rdoc --no-ri
java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar jruby-openssl --version 0.7.4 --no-rdoc --no-ri
java -jar jruby-complete-1.6.3.jar -S gem install -i ./gemjar fpm --version 0.3.7 --no-rdoc --no-ri
jar cf ruby-gems.jar -C gemjar .
rm -rf gemjar

You then invoke jruby rake via:

#!/bin/bash
java -jar jruby-complete-1.6.3.jar -rruby-gems.jar -S rake build.rb $@

This means that you can then invoke the following useful little nuggets:

task :list_gems do
  require "rubygems/gem_runner"
  Gem::GemRunner.new.run ["list"]
end

task :sass_watch do
  require 'haml'
  require 'haml/exec'
  opts = Haml::Exec::Sass.new ['--watch', 'src/main/sass:src/main/webapp/static/css']
  opts.parse!
end

task :ssh_copy, :file do |t, args|
  require "net/ssh"
  require "net/scp"
  Net::SSH.start("repository.remote", "user") do |ssh|
    ssh.scp.upload!(args.file, "/tmp/files/")
  end
end

task :make_rpm => :make_war do
  fail "Please install rpm-build to make RPMs!" unless system("rpmbuild --version")

  require "fpm"
  require "fpm/program"
  exit_code = FPM::Program.new.run([
    "-s", "dir", "-t", "rpm", "-n", APPLICATION_NAME, "-v", RPM_VERSION_NUMBER, "-a", "all",
    "--post-install", "target/rpmbuild/opt/application/bin/post_install.sh",
    "--pre-uninstall", "target/rpmbuild/opt/application/bin/pre_uninstall.sh",
    "-C", "target/rpmbuild", "opt"
  ])

  fail "Build failed" if exit_code != 0
end

How awesome is this?

Tags: , , , , , , , , ,