_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: [email protected]: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 [email protected]: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/”.

這篇算筆記, 有可能會有一些失落環節在, 主要從create Facebook application到可以在local端執行

Facebook這月稍早時跟Heroku合作, 讓建立一個Facebook應用程式(含後端)更加方便: http://developers.facebook.com/blog/post/558/ (有些步驟可以從這看)

我選了Node.js當做開發的平台, 以下就是我的步驟:

建立Facebook application

首先到Facebook application page https://developers.facebook.com/apps/ 建立一個新的應用程式

跟以往有點不太一樣的是, 在Application settings裡面多了一個"Cloud Services" -

_2011-09-21_4

目前只有Heroku可以選, 我猜以後搞不好會有更多合作對象吧

選了Provider之後, 接下來就要選擇平台, 目前有PHP, Python, Ruby, Node.js可選, 選擇算蠻多的了, 這邊選Node.js

_2011-09-21_4

經過一些有的沒的之後, 就會有這畫面, 這邊已經完成這個應用程式的基本雛形了

_2011-09-21_4

設定你的heroku應用程式

到 https://api.heroku.com/myapps 去設定你的應用程式, 在這邊你可以修改應用程式名稱, 不過比較麻煩的是, 這邊的修改並不會同步回Facebok, 因此修改後還是需要回Facebook去更改相關設定:

_2011-09-21_4

在你的電腦執行

一般在程式沒完成前大多都不會想直接佈署上去, 能在自己電腦先執行驗證過是比較容易抓蟲的

以下是先需要安裝的

heroku command line -

heroku是用gem安裝的, 所以安裝前要先確認你電腦有沒安裝Ruby, heroku安裝方法很簡單, 只要執行 “gem install heroku”

安裝好後先用"heroku keys"看看有沒存在的key, 有的話可能會讓之後要用git抓資料有問題, 有的話用"heoku keys:remove"先移除, 這樣login會產生新的public key

用"heroku login"登入heroku, 第一次使用可能會要求產生public key

登入後就可以用"git clone [email protected]:ff8.git"抓下原始碼(ff8是heroku application name)

node.js -

這當然是必須安裝的(在這例子), 如果是在mac上, 又是brew的使用者, 那只要用"brew install node"即可

npm (node package manager) -

安裝方式很簡單, 只要"curl http://npmjs.org/install.sh | sh"

安裝好後, 在git clone下來的目錄下"npm install", 它自然會裝好所有所需的package

foreman -

文件裡面有建議裝, 不過由於這範例只是一個單純的web, 並沒其他worker, 可以不裝

設定Facebook application

因為要在本地端執行而不是heroku的雲, 所以要把url都指向本地端, 像這樣:

_2011-09-23_5
設定環境變數

export FACEBOOK_APP_ID=122348222122778

export FACEBOOK_SECRET=1ba1beed9f7b5be9192bf4540c231234

export PORT=5000

(我跑在5000)

如果使用foreman, 就把這些寫在.env中

執行

“node web.js"就可以將server跑起來(或是foreman start), 然後到http://localhost:5000/就可以看到結果