ä¿ãåã解æã¯ããã¾ã§ä¾ãªã®ã§ãããã«é¢ãã¦è©³ããç¥ããã人ã¯ä»ãããã£ã¦ãã ãããæ¬ç¨¿ã¯dokku(Bashã¹ã¯ãªããã§ä½ãããHerokuã©ã¤ã¯ãªãªã³ãã¬ãã¹PaaSç°å¢)ä¸ã§CaboChaãç¨ãã¦ä¿ãåã解æãããç°¡åãªAPIãä½æãããã¨ããã·ããªãªã§ãã·ã¹ãã ã³ãã³ããã¤ã³ã¹ãã¼ã«ãããããªè¤éãªã¢ããªã±ã¼ã·ã§ã³ã®ä½ææ¹æ³ã解説ãããã®ã§ãã
ã¨ãã£ã¦ãããã®æ¹æ³ã¯ãç²æ«ãªãã®ãªã®ã§ãããè¯ãæ¹æ³ãããããããã¾ãããããã¾ã§æ軽ã«å®é¨ãããã¨ãã§ãããç¨åº¦ã§èªãã§ãã ããã
dokkuã«ã¤ãã¦
dokkuã¯Bashã¹ã¯ãªããã§ä½ãããHerokuã©ã¤ã¯ãªãªã³ãã¬ãã¹PaaSç°å¢ã§ããDockerã³ã³ãããä½æããHerokuãæä¾ãã¦ããbuildpackãå©ç¨ãã¦ã¢ããªã±ã¼ã·ã§ã³ããããã¤ãã¾ããã¤ã³ã¹ãã¼ã«ãHTTPSåãªã©ã«ã¤ãã¦ã¯ä»¥ä¸ã御覧ãã ããã
ä¿ãåã解æã«ã¤ãã¦
ä¿ãåã解æã¨ããã¨é¦´æã¿ã®ãªãæ¹ãããã£ãããã¨æãã¾ããããæä¸ã®æç¯éã«ã©ã®ãããªä¿®é£¾(ä¿)ã»è¢«ä¿®é£¾(å)é¢ä¿ããããã解æãããã®ã§ããå½¢æ ç´ è§£æã§ã¯æãåè©ã«å解ããã¨ããã¾ã§ãè¡ãã¾ãããä¿ãåã解æããããã¨ã«ãããèªç¶è¨èªã®æãããã·ã¹ãã ãç解ããããããã«è½ã¨ããããã¨ãã§ãã¾ãã
æ¥æ¬èªã§ã¯CaboChaã使ãã®ãä¸è¬çã§ã¯ãªããã¨æãã¾ããä»åã¯ãã®CaboChaãç¨ãã¦ä¿ãåã解æãããAPIãµã¼ããä½æãããã¨ãããã¨ãç®æ¨ã«ãã¾ãã
æ¬é¡
ã¨ããããã§ãããããã¯cabocha-api
ã¨ããååã®ã¢ããªã±ã¼ã·ã§ã³ãä½æãã¦dokkuã«ãããã¤ããã¾ã§ã解説ãã¦ããã¾ããHerokuã§å°ãè¤éãªã¢ããªã±ã¼ã·ã§ã³ãä½ã£ããã¨ãããæ¹ã¯ããã«ç解ã§ãããã¨æãã¾ãã
dokkuã§heroku-buildpack-multiã使ã
buildpackã¨ã¯ãè¨èªããã¬ã¼ã ã¯ã¼ã¯ãã¢ããªã±ã¼ã·ã§ã³çãæ軽ã«å©ç¨ã§ããããããã±ã¼ã¸åãããã®ã§ããHerokuã«ãã£ã¦ä½ããããã®ããã¦ã¼ã¶ã«ãã£ã¦ä½ããããã®ãåå¨ãã¾ãã
é常ãHerokuã«ã¢ããªã±ã¼ã·ã§ã³ããããã¤ããéã¯1ã¤ã®buildpackãèªåçã«é¸æããã¾ããffmpegãmecabçã®buildpack使ãããå ´åã¯è¨èªã®buildpackã¨ãããã¦è¤æ°ã®buildpackãå©ç¨ã§ããããã«ããå¿ è¦ãããã¾ããè¤æ°ã®buildpackãæ±ãã«ã¯ãbuildpackã¨ãã¦heroku-buildpack-multiãæå®ãã¾ãã
$ dokku apps:create cabocha-api $ dokku config:set cabocha-api BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
ããã§dokkuã®ã¢ããªã±ã¼ã·ã§ã³ä½æã¨è¤æ°buildpackãæ±ãè¨å®ããããã¾ããã
buildpackãè¨å®ãã
Macã«Homebrewãããã®ã¨åãããLinuxã«ã¯Linuxbrewãããã¾ããLinuxbrewã¯Homebrewã®forkã§ãããã®ãããHomebrewã§å ¥ããããã¢ããªã±ã¼ã·ã§ã³ã®ã»ã¨ãã©ã¯Linuxbrewã§ãå ¥ãããã¨ãã§ãã¾ããæ¬ç¨¿ã§ã¯Linuxbrewãç¨ãã¦CaboChaãã¤ã³ã¹ãã¼ã«ãã¾ãã
ã¨ããããæ¬å®¶ã®Linuxbrewã§ã¯CaboChaãã¤ã³ã¹ãã¼ã«ãããã¨ãã§ãã¾ãããç´ ç´ã«ã¤ã³ã¹ãã¼ã«ãããã¨ããã¨libiconv
ããªããã¨ã¨ã©ã¼ãåãã¦ãããã¤ããã»ã¹ãå¼·å¶çµäºãã¾ããããã§ãç¬èªã®CaboChaã¤ã³ã¹ãã¼ã©ãå©ç¨ããããã«ä¿®æ£ãæ½ããheroku-buildpack-linuxbrewãç¨ãã¾ããã¾ããAPIãµã¼ããRubyã§æ¸ãã®ã§Rubyã®buildpackãè¨å®ãã¾ãã
以ä¸ã.buildpacks
ã«è¨è¿°ãã¦ãã ããã
https://github.com/masawada/heroku-buildpack-linuxbrew.git https://github.com/heroku/heroku-buildpack-ruby.git
CaboChaã®ã¤ã³ã¹ãã¼ã«ãè¨å®ãã
heroku-buildpack-linuxbrewã¯.cellar
ã¨ãããã¡ã¤ã«ã«ã¢ããªã±ã¼ã·ã§ã³åãè¨è¿°ããã ãã§ããããã¤æã«ãã®ã¢ããªã±ã¼ã·ã§ã³ãèªåçã«ã¤ã³ã¹ãã¼ã«ãã¾ããã¨ããããæ¬å®¶ã®heroku-buildpack-linuxbrewã§ã¯ç¬èªã®Homebrew formulaãå©ç¨ãããã¨ãã§ãã¾ãã(brew tapãããã¨ãã§ããªã)ãããã§masawada/heroku-buildpack-linuxbrewã§ã¯tapããããã¨ãã§ããããæ¹è¯ãæ½ãã¦ãã¾ãã
CaboChaã®formulaã«ã¯libiconvã®ãªãã·ã§ã³ãè¨å®ãã¦ããç®æãããããããæªãããã¦ããããããªãã·ã§ã³ãå¤ããç¬èªformulaãGitHubä¸ã«ç¨æãããããå©ç¨ãããã¨ã«ãã¾ãã
以ä¸ã®ããã«.cellar
ãè¨è¿°ãããã¨ã§ä¿®æ£ããCaboCha formulaãå©ç¨ãããã¨ãã§ãã¾ãã
tap masawada/cabocha-without-iconv install cabocha-without-iconv
ç°å¢å¤æ°ãè¨å®ãã
ããããã¯dokkuã®ã¢ããªã±ã¼ã·ã§ã³ã«ç°å¢å¤æ°ãå¹¾ã¤ãè¨å®ãã¦ããã¾ãããããè¡ããªãã¨Linuxbrewã§ã®ãã«ãããã¾ããããªãã£ããããµã¼ãã«ç¨ããcabocha.gem
ã®ã¤ã³ã¹ãã¼ã«ããã¾ããããªãã£ãããã¾ãã
$ dokku config:set cabocha-api LIBRARY_PATH=/app/.linuxbrew/lib $ dokku config:set cabocha-api LD_LIBRARY_PATH=/app/.linuxbrew/lib $ dokku config:set cabocha-api LD_INCLUDE_PATH=/app/.linuxbrew/include $ dokku config:set cabocha-api C_INCLUDE_PATH=/app/.linuxbrew/include $ dokku config:set cabocha-api CPLUS_INCLUDE_PATH=/app/.linuxbrew/include $ dokku config:set cabocha-api PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/.linuxbrew/bin
ãããã¤å¾ã«ç°å¢å¤æ°ãè¨å®ãã¦ããrebuildããã¨ãã¾ãè¨å®ãããªããããªã®ã§ãå¿ ãæåã«è¨å®ããããã«ãã¦ãã ããã
APIãµã¼ããæ¸ã
ããããã¯Rubyã¨Sinatraãç¨ãã¦APIãµã¼ããæ¸ãã¦ããã¾ãã
- Gemfile: ä¾åãã¡ã¤ã«
- server.rb: æ¬ä½
- Procfile: dokkuä¸ã§ã¢ããªã±ã¼ã·ã§ã³ãèµ·åããããã®ã¹ã¯ãªãã
web: command
ã¨ããå½¢å¼ã§æ¸ããã¨ã§ãã¢ããªã±ã¼ã·ã§ã³ãèµ·åãããªãã¼ã¹ãããã·ãè¨å®ãã
ã¾ããäºåã«bundle install
ãå®è¡ãã¦Gemfile.lock
ãçæãã¦ãã ãããããããªãå ´åããããã¤æã«ããã»ã¹ãå¼·å¶çµäºãã¾ãã
Gemfile
source 'https://rubygems.org' gem 'sinatra' gem 'cabocha'
server.rb
require 'sinatra' require 'cabocha' get '/' do parser = CaboCha::Parser.new tree = parser.parse(params["q"]) @result = tree.toString(CaboCha::OUTPUT_RAW_SENTENCE) erb :index end __END__ @@index <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style>pre { font: normal 14px/20px courier; }</style> </head> <body> <pre> <%= @result %> </pre> </body> </html>
Procfile
web: ruby server.rb -p $PORT
ãããã¤ãã
ããã¾ã§ããããã¤ãã©ãããããã¤ããã ãã§ããä¸è¨ã¾ã§ã®ä½æ¥ãgit commit
ããgit remote add dokku
ã§dokkuã®æ
å ±ãç»é²ãã¾ãã
$ git push dokku master
ã§ãããã¤ãå§ã¾ãã¾ããå¹¾ã¤ãã®ãã¡ã¤ã«ããã«ãããã®ã§ãå
¨ä½æ¥ãçµããã®ã«æ°åãããã¾ããä½æ¥ãçµããããµã¼ãã«ã¢ã¯ã»ã¹ãã¦ã¿ã¾ããããã«ã¼ãã«?q=æç«
ã¨ã¯ã¨ãªãã¤ãããã¨ã§ããã®æç« ã®ä¿ãåã解æãè¡ããã¨ãã§ãã¾ãã
ãã®ããã«è¡¨ç¤ºãããã°æåã§ãã
ã¾ã¨ã
å¤å°æé ã¯è¤éã§ããããä½æ¥éã¨ãã¦ã¯ãããªã«å¤ããªãã®ã§ã¯ãªããã¨æãã¾ããHerokuã®å ´åã§ãç°å¢å¤æ°ã®è¨å®ããã¾ãè¡ãã°å ¨ãåããªãã¸ããªããããã¤ã§ãããããªæ°ããã¾ããããªãã失æãã¾ãããä»åã¯dokkuã§åããã¾ã§ãã¨ãããã¨ã§ããã¾ã§ã«ãã¦ããã¾ãã
æå¾ã«ãããã§ä½æããã¢ããªã±ã¼ã·ã§ã³ã以ä¸ã®ãªãã¸ããªã«ç½®ãã¦ãã¾ãã®ã§ããããããã°ãæ´»ç¨ãã ãã(ãã®ã¾ã¾ä½¿ãã®ã¯è¯ããªãã§ããã¢ã¯ã»ã¹å¶éãããããå ¥åæååãå¶éãããªã©ããã»ããè¯ãããããã¾ãã)ã