Java Developer since: 1997
First Programming Language: Pascal
Favorite Programming Language: x86 Assembler
- http://www.jamesward.com
- http://twitter.com/_JamesWard
- http://plus.google.com/101156657838073927919
- http://github.com/jamesward
- http://www.linkedin.com/in/jamesward
- http://stackoverflow.com/users/77409
Seven steps to the Cloud
-
project.clj
(defproject hello-world "0.0.1" :dependencies [[org.clojure/clojure "1.3.0"] [ring/ring-jetty-adapter "1.0.1"]])
-
src/web.clj
(ns web (:use [ring.adapter.jetty :only [run-jetty]])) (defn app [req] {:status 200 :headers {"Content-Type" "text/plain"} :body "Hello, world"}) (defn -main [port] (run-jetty app {:port (Integer. port)}))
-
Procfile
web: lein trampoline run -m web $PORT
-
Commit the files to a Git repo:
git init git add Procfile project.clj src git commit -m init
-
Create a new app on Heroku:
heroku create
-
Push the app to Heroku:
git push heroku master
-
Open the app:
heroku open
So simple.
-
Copy git repo to Heroku:
git push heroku master
-
Heroku uses a "Buildpack" to compile code
-
Heroku creates a "slug" file
-
Heroku deploys "slug" onto a "dyno"
-
Heroku starts the process
User has 0 or more Applications
Application has 1 git repository
Application has 0 or more Processes
Process is defined in a Procfile
Process named "web" can listen on one port for HTTP
Process runs on 0 or more Dynos
Dynos are isolated (LXC) and managed execution environments
Application has 0 more more external resources - Heroku Add-ons
Buildpack receives a
git push
and produces a "slug"Slug contains the non-system dependencies for all Processes
Dynos are ephemeral and stateless
HTTP(s) requests are randomly routed to the "web" Dynos
$0.05 / dyno hour
750 free dyno hours per application per month
$ heroku help
-
Logplex = central logging system
All router messages -> Logplex
All dyno stdout -> Logplex
$ heroku logs -t
-
Allocate dynos to a process
$ heroku scale web=50
-
$ heroku ps
-
Config through Environment Variables
$ heroku config $ heroku config:add FOO=bar
-
Slug file changes, Config changes, and Add-on changes are all versioned
$ heroku releases $ heroku rollback
-
Give multiple users access to an application
$ heroku sharing:add [email protected]
-
Run a command on a new dyno
$ heroku run bash
Add-ons are third party cloud services for things like caching, databases, monitoring, management, etc
-
$ heroku addons:add loggly:mole
Small and simple is wonderful.
-
project.clj
(defproject hello-clojure-compojure "0.1.0-SNAPSHOT" :main web :dependencies [[org.clojure/clojure "1.4.0"] [noir "1.2.1"]])
-
src/web.clj
(ns web (:use noir.core) (:require [noir.server :as server])) (defpage "/" [] "hello, world") (server/start (Integer/parseInt (or (System/getenv "PORT") "8080")))
-
Procfile
web: lein trampoline run
Links to help you get started.
https://devcenter.heroku.com/articles/clojure
https://devcenter.heroku.com/articles/clojure-support
https://devcenter.heroku.com/articles/clojure-web-application
https://github.com/jamesward/hello-clojure-noir