Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a clojure web application to Amazon EC2 (AWS Elastic Beanstalk + Leiningen + Compojure + Ring + Tomcat)

AS title,
My IDE is intellij idea 12.1.4 ,
What toolkit or plugin do I need to be able to deploy clojure web application to Amazon EC2?

Are there any link or reference or step by step solution ? thank you

like image 960
user2468652 Avatar asked Jun 10 '13 16:06

user2468652


1 Answers

If you are just deploying a war file with no other custom infrastructure then using EC2 directly is overkill and elastic beanstalk will do what you need far more easily. If you are growing something bigger, and want one click deployment then pallet is a great tool.

There is a lot to Pallet and it is a great library for writing amazingly small programs for doing this sort of thing (and much much more). Take some time to understand the pallet concepts of 'node' 'group' 'converge' etc, and give yourself plenty of patience. Once you get going with pallet it feels like magic.

The place to start is with the pallet getting started guide. go through the hello world example which will make sure your aws account is set up and keys are where they need to be. Then you can wite a bit of clojure code that creates an instance with the latest version of your webapp on it.

You will need:

  • pallet 0.8+
  • the pallet java crate
  • a group spec that installs java and copies the war file over.
  • the pallet lein plugin is nice though not required
  • lots of patience to get things up and running.

A rough outline of a group spec for this would look a bit like

(def java-server
  (java/server-spec
   {:vendor :oracle
    :components #{:jdk}
    :version [7]})) 

(def webserver
 (node-spec
   :image {:os-family :ubuntu} 
   :hardware {:min-cores 1 :min-ram (* 2 1024)}
   :phases {:configure
            (plan-fn
               (package-manager :update)
               (package "tomcat7")
            (remote-file "/var/lib/tomcat7/webapps/myapp.war"
               :local-file "target/myApp.war"
               :owner "tomcat7"
               :group "tomcat7"
               :mode 755))

(def web-group
 (group-spec
   "my-websertvers"
   webserver
   :extends [java-server]))

you would then call converge with web-group to either create or update your servers.

and please hop onto #pallet on freenode, where the friendly folks (my self included between ~10:00 and ~18:00 US-west) are eager to help.

like image 92
Arthur Ulfeldt Avatar answered Oct 01 '22 04:10

Arthur Ulfeldt