Herokuä¸ã§ã¹ã¯ãªã¼ã³ã·ã§ãããµã¼ããåãã
前回ãPhantomJSã®buildpackãä½æããã®ã§ãHerokuä¸ã§PhantomJSã®ããã»ã¹ãèªç±ã«ç¨¼åããããã¨ãã§ããããã«ãªã£ãã
PhantomJSã¯GUIç°å¢ã®ãªã(Headless) WebKitãã©ã¦ã¶ã§ããããããã©ã¦ã¶ä¸ã®JavaScriptã®åä½ãã¹ãorçµåãã¹ãããµã¼ãä¸ã§èµ°ããã¦ãç¶ç¶çã¤ã³ãã°ã¬ã¼ã·ã§ã³ã«çµã¿è¾¼ããªã©ã®å©ç¨æ¹æ³ãããã ããããããèå³æ·±ããããã¯ã§ã¯ãããã©ãããã§ã¯è§¦ããªãã
ä»åã¯PhantomJSã®ç»é¢ã¬ã³ããªã³ã°ã®æ©è½ã使ã£ã¦ãã¹ã¯ãªã¼ã³ã·ã§ãããµã¼ããHerokuä¸ã«æ§ç¯ããã
æ§æã¨å¦çããã¼
PhantomJSã«ã¯webãµã¼ãæ©è½ãå«ã¾ãã¦ãããåç¬ã§HTTPãµã¼ãã¨ãã¦ãªã¯ã¨ã¹ããåãåãäºãã§ããããå®ãµã¼ãã¹ã§å©ç¨ãããããªã·ãã¢ãã§ã¯ãªãããã®ããã¯ã©ã¤ã¢ã³ããããªã¯ã¨ã¹ããåãåãNode.jsã®ãµã¼ããå¥ã«ç«ã¦ããä»åã¯ãããHerokuä¸ã§è¡ãªã£ã¦ããã
Node.jsã®ã¢ããªã±ã¼ã·ã§ã³ã¯ãSocket.IOãµã¼ãã¨ãã¦ç¨¼åãã2ã¤ã®channelãæã¤ã
1ã¤ãã®request channelã§ã¯ããã©ã¦ã¶ããã®ã¹ã¯ãªã¼ã³ã·ã§ããåå¾ãªã¯ã¨ã¹ããåãåãããã¼ã¸ã®URLããã¥ã¼ã«å
¥ããã
ãã1ã¤ã®render channelã§ã¯ãPhantomJSã®ã¹ã¯ãªã¼ã³ã·ã§ãããµã¼ãã¨æ¥ç¶ãããPhantomJSã¯ã¹ã¯ãªã¼ã³ã·ã§ãããµã¼ãã§ããããSocket.IOçã«ã¯ã¯ã©ã¤ã¢ã³ãã«ãªããã¹ã¯ãªã¼ã³ã·ã§ããã®ãªã¯ã¨ã¹ãã¯ãæ¥ç¶ä¸ã®PhantomJSã¯ã©ã¤ã¢ã³ãã®ãã¡ã®1ã¤ã«dispatchãããã
PhantomJSã®ã¢ããªã±ã¼ã·ã§ã³ã¯ãPushãµã¼ãã¨ãã¦ã®Node.jsã«Socket.IOã§æ¥ç¶ããã¹ã¯ãªã¼ã³ã·ã§ããã®ãªã¯ã¨ã¹ããå¾ ã¤ããã¼ã¸ã®URLãããã·ã¥ãããæç¹ã§ãPhantomJSã¯ãã¼ã¸ã«ã¢ã¯ã»ã¹ããã¹ã¯ãªã¼ã³ã·ã§ããã®ã¬ã³ããªã³ã°ãéå§ããã
ã¹ã¯ãªã¼ã³ã·ã§ããã¯ç»åãã¡ã¤ã«ã¨ãã¦PhantomJSã®ãã¼ã«ã«ãã¡ã¤ã«ã·ã¹ãã ã«ä¿åããããããã®ã¾ã¾ã§ã¯ã©ããããã¢ã¯ã»ã¹ã§ããªãã®ã§ãã¤ã¡ã¼ã¸ãµã¼ãã§ããAmazon S3ã«ã¢ãããã¼ããããããã§ããã¡ã¤ã«ãã¼ã¿ãNode.jsã«æ»ããã¨ãªããPhantomJSããç´æ¥Browser Post Formãå©ç¨ãã¦S3ã«ã¢ãããã¼ãããï¼postã®éã«å¿ è¦ã«ãªãsignatureã¯äºåã«Node.jså´ã§çæããã¦ãããããã·ã¥éç¥ã®éã«ãã¼ã¸URLã¨å ±ã«åæã«æ¸¡ã£ã¦ããï¼
æå¾ã«ãPhantomJSã¯ã¢ãããã¼ãããã¹ã¯ãªã¼ã³ã·ã§ããã®URLãNode.jsã«éç¥ããããã®å¾ãNode.jsã¯request channelã«æ¥ç¶ãã¦ããã¯ã©ã¤ã¢ã³ãå
¨ã¦ã«å¯¾ãã¦ã¹ã¯ãªã¼ã³ã·ã§ããã®URLãããã¼ããã£ã¹ãããï¼ãã©ã¦ã¶ã¯ãããåãåã£ã¦æç»ããï¼
å©ç¹
ã¹ã¯ãªã¼ã³ã·ã§ãããµã¼ããã¯ã©ã¦ãä¸ã§æ§ç¯ããå ´åãä»ã¾ã§ã¯EC2ãªã©ã®IaaSä¸ã§GUIç°å¢ãå«ãOSã稼åããããã¨ãå¤ãã£ããã常æèµ·åã«ãããªã½ã¼ã¹ã®æå¹å©ç¨ããã³ã¹ã±ã¼ã«æã®VMã®ä¸ãä¸ãã®ã³ã¹ããåé¡ç¹ã¨ãã¦ãã£ãã
ããããHeadlessã®PhantomJSã§ã¹ã¯ãªã¼ã³ã·ã§ãããæ®ãããããHerokuä¸ã§åä½ããããã¨ã«ãããã¹ã¯ãªã¼ã³ã·ã§ãããµã¼ãã®ã¹ã±ã¼ã«ã¢ã¦ããã¹ãã¼ãã£ãã¤å®¹æã«ãªã£ã¦ããã
ãã¨ãã°ã以ä¸ã®ã³ãã³ãã§ã¤ã³ã¹ã¿ã³ã¹ãç¬æã«*1ä¸ãä¸ãå¯è½ã§ããã
$ heroku ps:scale renderer=4
è³æ
- ã¹ã©ã¤ã: Phantomjs Screenshot Server on Heroku
- ã½ã¼ã¹: https://github.com/stomita/heroku-screenshot
- å®éã«ãããã¤ããã¢ããªï¼ãã¢ç¨éã®ã¿ï¼äºåãªãè½ã¨ãå ´åãããã¾ãï¼: http://heroku-screenshot-nodejs.herokuapp.com