顯示具有 Heroku 標籤的文章。 顯示所有文章
顯示具有 Heroku 標籤的文章。 顯示所有文章

2012年10月31日 星期三

[Go筆記] Heroku, Facebook

最近給自己一個作業寫了一個Go版的Facebook API, 本想要實作realtime api時想到, 我需要把這server開放給Facebook server可以存取

看來看去, 好像只有Google自家的GAE有支援Go, 這大概也是因為Go是他們親生子的關係吧, 不過之前一陣子用Heroku用習慣了, 而且, 想說Heroku有支援那麼多的語言平台, 不知道有沒有, 結果翻遍官方的文件, 卻沒發現Go的蹤影

正當要放棄時, 發現, 其實Heroku還蠻威的, 除了支援很多不同的語言平台外, 居然還可以讓你延伸, 而它就是透過開放"Buildpack"這東西:



而就有一個老兄寫了一個Go用的buildpack (這位老兄在Heroku工作):


基本上就是建立Procfile和.godir而已, 很簡單, 這樣地鼠同好就有除了GAE以外的選擇囉....

另外就是自己的作業, Facebook API for Go : https://github.com/julianshen/FacebookGoSDK
這是一個api實作可以用於server端, realtime API目前還寫的很簡陋, 詳細用法可以看 sample/server.go

這邊一個比較好玩的是, 在Go裡, 你要用這樣的package, 毋須把整個source抓回來build, 而只要使用這樣的方法import:

import facebook "github.com/julianshen/FacebookGoSDK"
這樣是import一個在github上的package, 當你使用"go run"或"go get"之類的來編譯執行程式時, Go自動會上github幫你把這些相關的package取回, 用這個Heroku buildpack做出的環境一樣適用

2012年4月16日 星期一

[筆記] Deploy Mojito app to Heroku

First, you need to follow this doc (http://developer.yahoo.com/cocktails/mojito/docs/quickstart/) to install Mojito as a global node module. Why install it globally? Because you need the Mojito command line to create your first app.

Create application with command line:

mojito create app mymojito

Change working directory to "mymojito".

Create a "Procfile" whose content is:

web: mojito start $PORT

Use the following command to create an application on heroku and deploy codes to it.

  • git init
  • git add .
  • git commit -am init
  • heroku create mymojitotest --stack cedar
  • git push heroku master

After successfully commit codes to heroku, you could check running process with "heroku ps". However, you cannot find any running process. That is because there is one important step missed:

heroku ps:scale web=1

This command adds one dyno for web process. After that, you will find one web process when you check with "heroku ps". And the server is now started up. You can check your app with browser.

2011年9月28日 星期三

[筆記] Building social networking service with DIASPORA* on Heroku

_2011-09-29_12

Looks familiar? It's not Google+. It's DIASPORA. An open source project that implements a distributed social networking service. This project was announced on APRIL 24, 2010 (Just right after Facebook f8 2010 that is at APRIL 21). Alpha version was released at NOV 23, 2010 (two days before my birthday :P). 

According to this, Mark Zuckerbug also donated to it just because it's a cool idea.

It's built on Ruby on rails. So it might be not so difficult to port it to Heroku platform which is a nice RoR host (althrough it still took me some time). It might be easier than build from scratch on a Linux. 

I'm a newbie to these two (Heroku and DIASPORA). I'm also not familar with RoR. Here records steps I tried. 

create an application on heroku

First, you need to create an application on Heroku. There are several platform stack on Heroku. Cedar stack might be the newest and most powerful one. It supports several languages and frameworks. And It also makes it very easy to deploy RoR applications. 

You need to install heroku CLI before creating an application. And use "heroku login" to login to your heroku account.

Run the following command to create a new cedar application (assume application name is "mysocialy") --

heroku create --stack cedar mysocialy

After the application created, you'll have a url "http://mysocialy.herokuapp.com/" for your site. And a git repository: git@heroku.com:mysocialy.git

import source codes

Get DIASPORA* source codes from git hub:

git clone git://github.com/diaspora/diaspora.git

Get your source codes from Heroku git repository (you'll get an empty folder):

git clone git@heroku.com:mysocialy.git

If you have trouble to download from Heroku. Try to use "heroku keys:add" to add your ssh public key and try again.

Copy all files except ".git" folder from "diaspora" to "mysocialy".

Initial configuration

Make new configuration files from example.

cd config

mv application.yml.example application.yml  

mv database.yml.example database.yml

Edit application.yml. Make "pod_url" to your host. In this case:

pod_url: "http://mysocialy.herokuapp.com/"

Deploy codes

Add and commit files:

git add .

git commit -am 'initial import'

Push them to Heroku

git push origin master

The coolest thing that Heroku does is that it makes deploy codes so easy. All you need to do is to push your codes to its git repository. And it could also install all related modules for you (that is configured in Gemfile). Super easy.

Ok, I must admit that I lie a little bit. There might be some problems. After I pushes all codes to Heroku, I found there is an error that it couldn't find 'pg' (postgresSQL). Looks like it does not install into gem.

I found the answer that it might be problem with gem version. Need to run "bundle install" at local.  This will generate a new Gemfile.lock. Push this new file to Heroku might solve this problem

Ok, that's all?

Not sure if I missed anything (I might). Anyway, what I did is alive at "http://mysocialy.herokuapp.com/".