share facebook facebook twitter menu hatena pocket slack

2014.11.13 THU

たった 15 分の Play で Heroku が Eroku て泣けた(簡単に始めることが出来ました)

川原 洋平


cloudpack の 自称 Sensu芸人 の かっぱこと 川原 洋平@inokara)です。


Play という Web フレームワークがあることを教えてもらってググると Heroku だったら簡単に動かせるらしいので、まずはどげなもんかを試してみました。


Play Framework

  • Play framework
  • Play Framework
  • Scala と Java 言語で書かれたオープンソースの Web アプリケーションフレームワーク
  • MVC アーキテクチャを採用
  • 元々は Java 書かれていたが Scala 言語をサポート、その後はコア部分を Scale で書き直された
  • Ruby on Rails と Django から大きな影響を受けている
  • Webサーバーは Netty


  • Heroku
  • 泣く子も黙る PaaS の決定版
  • OS は Debian 又は Ubuntu
  • Ruby や Node.js や Scala 等をサポート
  • データベースは PostgreSQL や MySQL や Couchbase 等をサポート

Heroku の準備



Heroku Toolbelt

heroku をコマンドラインから利用出来るツールです。
ここから DL して展開してインストールしましょう。

Play Framework


MacOS X Marvericks に brew で一発。

brew install play


play コマンドを help してみる

bash-3.2$ play help
 _ __ | | __ _ _  _
| '_ \| |/ ' | || |
|  /|_|\____|\ /
||            |__/

play 2.2.3 built with Scala 2.10.3 (running Java 1.7.0_60),
Welcome to Play 2.2.3!

These commands are available:

license Display licensing informations. new [directory] Create a new Play application in the specified directory. You can also browse the complete documentation at



play new ${APP_NAME} でアプリケーションのひな形を生成します。

bash-3.2$ play new test-app
 _ __ | | __ _ _  _
| '_ \| |/ ' | || |
|  /|_|\____|\ /
||            |__/

play 2.2.3 built with Scala 2.10.3 (running Java 1.7.0_60),

The new application will be created in /Users/kappa/git/myrepo/play/test-app

What is the application name? [test-app]

Which template do you want to use for this new application?

1             - Create a simple Scala application
  2             - Create a simple Java application

> 2
OK, application test-app is created.

Have fun!

2 を選択して Java アプリケーションのひな形を作成します。

play run でアプリケーションを起動

play run でアプリケーションを起動します。

bash-3.2$ play run
[info] Loading project definition from /path/to/test-app/project
[info] Set current project to test-app (in build file:/path/to/test-app/)
[info] Updating {file:/path/to/test-app/}test-app...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

簡単ですね…。ちなみにアプリケーションはポート 9000 番で Listen しています。

Heroku で Play Framework を動かす: アプリケーション起動

初めての Heroku で Play

次はこのアプリケーションのひな形をあきこのままで(そのままで)Heroku にデプロイしてみましょう。

heroku コマンドを help する

bash-3.2$ heroku help
Usage: heroku COMMAND [--app APP] [command-specific-options]

Primary help topics, type "heroku help TOPIC" for more details:

addons    #  manage addon resources
  apps      #  manage apps (create, destroy)
  auth      #  authentication (login, logout)
  config    #  manage app config vars
  domains   #  manage custom domains
  logs      #  display logs for an app
  ps        #  manage dynos (dynos, workers)
  releases  #  manage app releases
  run       #  run one-off commands (console, rake)
  sharing   #  manage collaborators on an app

Additional topics:

certs        #  manage ssl endpoints for an app
  drains       #  display syslog drains for an app
  features     #  manage optional features
  fork         #  clone an existing app
  git          #  manage git for apps
  help         #  list commands and display help
  keys         #  manage authentication keys
  labs         #  manage optional features
  maintenance  #  manage maintenance mode for an app
  members      #  manage membership in organization accounts
  orgs         #  manage organization accounts
  pg           #  manage heroku-postgresql databases
  pgbackups    #  manage backups of heroku postgresql databases
  plugins      #  manage plugins to the heroku gem
  regions      #  list available regions
  stack        #  manage the stack for an app
  status       #  check status of heroku platform
  twofactor    #
  update       #  update the heroku client
  version      #  display version

アプリケーションを Heroku に登録する


bash-3.2$ ls
myapp           test-app
bash-3.2$ cd test-app/


git init

Heroku のアプリケーションは git を介してデプロイされます。

bash-3.2$ git init
Initialized empty Git repository in /Users/kappa/git/myrepo/play/test-app/.git/

heroku create ${アプリケーション名} を実行して Heroku にアプリケーションを登録します。

bash-3.2$ heroku create xxxxx-test-app
Creating xxxxx-test-app... done, stack is cedar |
Git remote heroku added


続いて git add して git commit でローカルのリポジトリにアプリケーションを登録します。

bash-3.2$ git add -A .
bash-3.2$ git commit -m "test commit"
[master (root-commit) bcf5064] test commit
 Committer: kappa <kappa@kappa-at-clp.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

git config --global &quot;Your Name&quot;
git config --global
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
15 files changed, 229 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100644 app/controllers/ create mode 100644 app/views/index.scala.html create mode 100644 app/views/main.scala.html create mode 100644 build.sbt create mode 100644 conf/application.conf create mode 100644 conf/routes create mode 100644 project/ create mode 100644 project/plugins.sbt create mode 100644 public/images/favicon.png create mode 100644 public/javascripts/jquery-1.9.0.min.js create mode 100644 public/stylesheets/main.css create mode 100644 test/ create mode 100644 test/ bash-3.2$

git push heroku master を実行して heroku にアプリケーションをでぷろーいします。

bash-3.2$ git push heroku master
Initializing repository, done.
Counting objects: 27, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (27/27), 37.01 KiB | 0 bytes/s, done.
Total 27 (delta 0), reused 0 (delta 0)

-----> Play 2.x - Java app detected
-----> Installing OpenJDK 1.6...done
-----> Downloading SBT...done
-----> Priming Ivy cache (Scala-2.10, Play-2.2)... done
-----> Running: sbt update
       [info] Loading global plugins from /tmp/scala_buildpack_build_dir/.sbt_home/plugins
       [info] Updating {file:/tmp/scala_buildpack_build_dir/.sbt_home/plugins/}global-plugins...
       [info] Resolving org.scala-lang#scala-library;2.10.2 ...
       [info] Resolving org.scala-sbt#sbt;0.13.0 ...
       [info] Resolving org.scala-sbt#main;0.13.0 ...
       [info] Resolving org.scala-sbt#actions;0.13.0 ...
       [info] Resolving org.scala-sbt#classpath;0.13.0 ...
       [info] Resolving org.scala-sbt#launcher-interface;0.13.0 ...
       [info] Resolving org.scala-sbt#interface;0.13.0 ...
       [info] Resolving org.scala-sbt#io;0.13.0 ...
       [info] Resolving org.scala-sbt#control;0.13.0 ...
       [info] Resolving org.scala-lang#scala-compiler;2.10.2 ...
       [info] Resolving org.scala-lang#scala-reflect;2.10.2 ...
       [info] Resolving org.scala-sbt#completion;0.13.0 ...
       [info] Resolving org.scala-sbt#collections;0.13.0 ...
       [info] Resolving org.pegdown#pegdown;1.4.0 ...
       [info] Resolving org.parboiled#parboiled-java;1.1.5 ...
       [info] Resolving org.parboiled#parboiled-core;1.1.5 ...
       [info] Resolving org.ow2.asm#asm;4.1 ...
       [info] Resolving org.ow2.asm#asm-tree;4.1 ...
       [info] Resolving org.ow2.asm#asm-analysis;4.1 ...
       [info] Resolving org.ow2.asm#asm-util;4.1 ...
       [info] Resolving commons-io#commons-io;2.4 ...
       [info] Resolving org.scala-lang#scala-compiler;2.10.3 ...
       [info] Resolving org.scala-lang#jline;2.10.3 ...
       [info] Resolving org.fusesource.jansi#jansi;1.4 ...
       [info] downloading ...
       [info]   [SUCCESSFUL ];2.2.3!play-java-jdbc_2.10.jar (50ms)
       [info] downloading ...
       [info]   [SUCCESSFUL ];2.2.3!play-java-ebean_2.10.jar (46ms)
       [info] downloading ...
       [info]   [SUCCESSFUL ];2.2.3!play-cache_2.10.jar (49ms)
       [info] downloading ...
       [info]   [SUCCESSFUL ] org.avaje.ebeanorm#avaje-ebeanorm;3.2.2!avaje-ebeanorm.jar (234ms)
       [info] downloading ...
       [info]   [SUCCESSFUL ] org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Final!hibernate-jpa-2.0-api.jar (149ms)
       [info] downloading ...
       [info]   [SUCCESSFUL ];2.2.3!play-test_2.10.jar (53ms)
       [info] downloading ...
       [info]   [SUCCESSFUL ];2.2.3!play-docs_2.10.jar (379ms)
       [info] Done updating.
       [success] Total time: 17 s, completed Oct 30, 2014 2:27:54 PM
-----> Running: sbt compile stage
       [info] Loading global plugins from /tmp/scala_buildpack_build_dir/.sbt_home/plugins
       [info] Loading project definition from /tmp/scala_buildpack_build_dir/project
       [info] Set current project to test-app (in build file:/tmp/scala_buildpack_build_dir/)
       [info] Compiling 4 Scala sources and 2 Java sources to /tmp/scala_buildpack_build_dir/target/scala-2.10/classes...
       [info] 'compiler-interface' not yet compiled for Scala 2.10.3. Compiling...
       [info]   Compilation completed in 15.768 s
       [success] Total time: 25 s, completed Oct 30, 2014 2:28:28 PM
       [info] Wrote /tmp/scala_buildpack_build_dir/target/scala-2.10/test-app_2.10-1.0-SNAPSHOT.pom
       [info] Packaging /tmp/scala_buildpack_build_dir/target/scala-2.10/test-app_2.10-1.0-SNAPSHOT.jar ...
       [info] Done packaging.
       [success] Total time: 1 s, completed Oct 30, 2014 2:28:28 PM
-----> Dropping ivy cache from the slug
-----> Dropping compilation artifacts from the slug
-----> Discovering process types
       Procfile declares types           -> (none)
       Default types for Play 2.x - Java -> web

-----> Compressing... done, 193.3MB
-----> Launching... done, v6 deployed to Heroku

 * [new branch]      master -> master

必要なモジュール等が順次導入されていきます。そして、最後に… deployed to Heroku


早速 にアクセスしてみましょう。

Heroku で Play Framework を動かす: 動作確認

ペラ一枚のページですが、git に push しただけででぷろーい(公開)が完了しました。


ホントに触ってみただけですが、ここまで 15 分、Play が Heroku で Eroku てビックリしました…。

たった 15 分の Play で Heroku が Eroku て泣けた(簡単に始めることが出来ました)