Continuous development 包含了很多的面向,譬如說比較常聽到的 Continuous delivery 或 Continuous deployment 等等。
而等等要介紹的 Shippable 和 Heroku 的運用確實可以達成上述的這些 term
Shippable 是一個強大的平台讓開發者能夠快速的做專案的整合(integrate)與建構(build)
它能夠自動同步你 GitHub 或是 Bitbucket 內的專案來進行建構,方便的是
假如你今天有一個專案在 GitHub 上,並且你也同步到了 Shippable
之後你如果有任何的程式提交 (commit) 到 GitHub 上,Shippable 都會自動的進行建構的動作
讓開發者能夠達到持續地提交,建構與測試。當然這個過程是開發者需要提供一些設定檔才能達成的
而 Shippable 更提供了幾個主流開發語言的環境,包括 Node.js, Java, Ruby, Scala, Python 等等
而 Heroku 則是一個 PaaS,它提供了很多種語言的 deploy (部署)與運行環境
簡單來說就是它能夠讓你部屬你的專案到 Heroku 的 Cloud 上,並透過它給你的 domain 進行結果的瀏覽
在進行接下來的教學前你需要有 GitHub 的帳號,並且在 GitHub 上有一些專案可以運用
所以 GitHub 的操作就不多說了,直接從 Shippable 開始
建立 Shippable 與 GitHub 間的連結
先進入到 Shippable 的首頁 https://www.shippable.com/ 並按下中間 GitHub 的按鈕
接下來會進行一些 GitHub 的權限認證,做完之後就會看到 Shippable 的 dashboard
中間是你目前開啟 Shippable 與 GitHub 同步的專案,右邊會是你 GitHub 上的所有專案
建立 Heroku 帳號與應用(Application)
接下來建立 Heroku 的帳號就不多說了,很簡單,就直接從建立帳號後開始說起
帳號建立完成後你應該會看到類似下方的圖
接下來你可以透過按下右上方角落的+來建立一個App,建立過程很簡單,你只要輸入名稱就好
你甚至不輸入也沒關係,它會自動幫你建立一個名子。
設定 SSH key
回到剛剛的 Shippable dashboard,並按下左邊欄的 Organizations 之後,再選擇 Deployment Key,如下圖並且複製 ssh-rsa key,並回去 Heroku 的 dashboard,按下左邊欄的 Account,並選擇 Manage Account,之後往下拉找到 SSH Keys 那區塊,按下右邊的 Edit,並輸入剛剛複製的 ssh key 再儲存即可,如下圖:
建立 .shippable.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: node_js | |
node_js: | |
- "0.10.25" | |
env: | |
- NODE_ENV=travis | |
before_install: | |
- sudo npm install bower -g | |
- bower install | |
- sudo chown -R $(whoami) /home/shippable/.npm | |
after_success: | |
- git push git@heroku.com:youAppName.git |
shippable 提供很多不同階段的入口點,讓開發者可以在不同的階段做想做的事情
例如上述範例在 npm install(before_install) 之前,會先安裝 Bower,並 install 所有的 bower dependency
最後在成功之後 (after_success) 我們做了一個最重要的步驟,就是將結果透過 git 提交到 Heroku
至於你的 Heroku 的 git 路徑你可以回到 Heroku 的 dashboard,並在中間下方部分選擇你剛剛建立的 Application
再選擇之後會顯示你目前 Application 的一些資訊和狀態,接著在上方選擇 Settings 的 tab
你就會在 Info 的區塊中找到你這麼 Application 在 Heroku 的 git url 了,如下圖:
所以你只要把 git push 後面的 git url 換成自己的就可以了
建立 Procfile
建立 Procfile (在專案的 root 下建立),它能夠指定你的 Application 要如何在 Heroku 的平台中運行(我的範例是一個 web 的 Node.js 專案)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: npm start |
Building Project
最後回到 Shippable ,在右邊欄選擇你要同步的專案,按下 Enable就可以了如同剛剛前面說的,只要有任何 commit 到 github 上,都會觸發一個 Shippable 任務去執行 build 的動作
build 成功之後,你的 dashboard 會類似下圖
你可以點進去看這個專案 building 後的 log
當你 build 成功之後,你可以回到 Heroku,同樣進到你的 Application 頁面並選擇 Activity tab
你會看到一些 build 和 deploy 的記錄
最後就可以透過 http://<your application name>.herokuapp.com/ 這個網址查看 deploy 後的結果了
結語
基本上 GitHub 就負責對你的專案做版本的控管,這是做一個應用程式的基礎,在這基礎上我們透過了 Shippable 提供的功能來讓你做到應用程式的持續建構與測試,並且也能匯整出一份報告
在成功的完成這些基本的作業後,就可以將我們的應用程式自動且直接地透過 Heroku 上到 Production 了
沒有留言:
張貼留言