himynameisjonas/jekyll-heroku-unicorn
を参考に設定します。
バージョンは
ruby 2.0.0
jekyll 1.4.2
です。
Gemのインストール
Gemfile
ruby '2.0.0' #herokuでruby 2.0を利用にするために設定
gem 'jekyll'
gem 'rack-jekyll', github: 'adaoraul/rack-jekyll', ref: '6a4b832c5b2350c8c1263b534ebf02135deb6363'
gem 'unicorn'
unicorn.rbの作成
unicornの設定ファイルを作成します。(細かい説明は端折ります)
unicorn.rb
worker_processes 1
timeout 30
preload_app true
config.ruの作成
config.ruを作成します。
config.ru
require "bundler/setup"
Bundler.require(:default)
run Rack::Jekyll.new(:destination => '_site')
_config.ymlの設定
jekyllの_config.ymlファイルに以下のように
(サイトに必要のない)不要なファイルを表示します。
_config.yml
exclude: ["vendor",".rbenv-version", ".gitignore", "README.md", "Gemfile", "Gemfile.lock", "Procfile", "unicorn.rb", "config.ru"]
※vendor
を入れないと、herekuでサーバを立ち上げる時に
「Post 0000-00-00-welcome-to-jekyll.markdown.erb does not have a valid date. (Jekyll::FatalException)」のエラーが発生します。
Procfileの作成
herokuで起動するためにProcfileを作成します。
Procfile
web: bundle exec unicorn -p $PORT -c ./unicorn.rb
$ foreman start
で起動することが確認できればOK
$ foreman start
01:07:26 web.1 | started with pid 83446
01:07:27 web.1 | I, [2013-12-29T01:07:27.402502 #83447] INFO -- : Refreshing Gem list
01:07:28 web.1 | Configuration file: /***/****/_config.yml
01:07:28 web.1 | I, [2013-12-29T01:07:28.181070 #83447] INFO -- : listening on addr=0.0.0.0:5000 fd=9
01:07:28 web.1 | I, [2013-12-29T01:07:28.181171 #83447] INFO -- : worker=0 spawning...
01:07:28 web.1 | I, [2013-12-29T01:07:28.183126 #83447] INFO -- : master process ready
01:07:28 web.1 | I, [2013-12-29T01:07:28.184675 #83582] INFO -- : worker=0 spawned pid=83582
01:07:28 web.1 | I, [2013-12-29T01:07:28.189126 #83582] INFO -- : worker=0 ready
herokuの作成と開始
ここからはいつものherokuの開始と同じ。
$ git init
$ git add .
$ git commit -m ‘first commit’
$ heroku create
$ git push heroku master
$ heroku open
で、うまく行けばxxxx.herokuapp.comで表示できるかと思います。