熱門文章

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

2016年9月19日 星期一

[Ruby on Rails]上傳app到 Heroku

出處:http://railsgirls.tw/heroku


取得 Heroku

按照 Heroku 官方的快速上手指南的步驟 1 至步驟 3,來註冊、安裝工具包並登入。
教練: 講解將 App 部署到 Heroku,跟傳統自己架伺服器比起來,有什麼好處。

準備妳的 app

版本管理系統

需要把程式碼加到版本管理系統。在終端機裡輸入以下命令:
git init
echo "public/uploads" >> .gitignore
echo "tmp" >> .gitignore
echo "logs" >> .gitignore
git add .
git commit -m "initial commit"
教練:講解使用版本管理系統的好時機。順便解釋 .gitignore 檔案是什麼,並解釋為什麼要忽略某些檔案被傳上去。

更新資料庫

首先,需要讓資料庫在 Heroku 跑起來。Heroku 使用不同於 Rails 預設的資料庫。請修改 Gemfile 的內容:
請將
gem 'sqlite3'
改為
group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end
執行 bundle install --without production 命令來解決軟體相依問題。
教練: 可以講講 RDBMS 以及 pg 與 sqlite 的差別,請講點 Heroku 的 PostgreSQL 軟體相依細節。

安裝 rails_12factor Gem

接下來,需要在 Gemfile 加入 rails_12factor,讓我們的 app 可以出現在 Heroku。
這個 Gem 調整妳的 Rails App 成為適合在 Heroku 工作的模式,舉例來說,記錄檔存放的地方、靜態檔案的設定(圖片、樣式表以及 JavaScript 檔案)會設定成適合 Heroku 系統的設定。
請修改 Gemfile 的內容:
group :production do
  gem 'pg'
end
改為
group :production do
  gem 'pg'
  gem 'rails_12factor'
end
修改好之後到終端機執行 bundle 命令,接著將 Gemfile.lock 提交到妳的程式碼倉庫 (repository):
git commit -a -m "Added rails_12factor gem and updated Gemfile.lock"
教練: 可以說說 Heroku 的記錄檔怎麼用,或是其它相關的東西。

部署 App

建立 App

需要在終端裡輸入 heroku create,在 Heroku 上產生一個新的 Heroku app,妳會看到像是下面的訊息:
Creating evening-sky-7498... done, stack is cedar
http://evening-sky-7498.herokuapp.com/ | git@heroku.com:evening-sky-7498.git
Git remote heroku added
上面的 “evening-sky-7498” 就是妳 Heroku App 的名稱。

上傳程式碼

接著需要將程式碼上傳至 Heroku,輸入 git push heroku master。妳會看到像是下面的輸出:
Counting objects: 134, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (115/115), done.
Writing objects: 100% (134/134), 35.29 KiB, done.
Total 134 (delta 26), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       Fetching gem metadata from https://rubygems.org/.......
...
-----> Launching... done, v4
       http://evening-sky-7498.herokuapp.com deployed to Heroku
看到 “Launching…” 的訊息表示 App 已經上傳完畢了。

資料庫遷移

接著需要遷移資料庫,跟我們在工作坊時,在自己電腦上做的一樣: heroku run rake db:migrate
當這條命令執行完畢時,妳可以用產生出來的網址來訪問妳的 App,可以打開這個頁面 http://evening-sky-7498.herokuapp.com/ 看看。也可以在終端裡輸入 heroku open 來開啟網頁。


[Rails]錯誤解決-gem 'pg' 安裝PostgreSQL -way2

之前也有一篇解決方法 [Rails]錯誤解決-gem 'pg' 安裝PostgreSQL

後來也看到這個,Heroku 的 PostgreSQL 軟體相依。


更新資料庫

首先,需要讓資料庫在 Heroku 跑起來。Heroku 使用不同於 Rails 預設的資料庫。請修改 Gemfile 的內容:
請將

gem 'sqlite3'

改為

group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end

執行 bundle install --without production 命令來解決軟體相依問題。

2016年6月10日 星期五

Heroku 上傳之筆記

Heroku是一個支持多種程式語言的雲平台即服務。Heroku作為最開始的雲平台之一,從2007年6月起開發,當時它僅支持Ruby,但後來增加了對Java、Node.js、Scala、Clojure、Python以及PHP和Perl的支持。
Step 1: 上 Heroku 官網http://heroku.com 註冊帳號。(請在 Heroku、Git、GitHub、SSH 使用相同的 Email。)
Step 2: 請上 https://toolbelt.heroku.com/ ,下載heroku toolbelt,並安裝。

2016年2月29日 星期一

[Rails]deploy to Heroku




完成一個階段後,更新git,上傳到heroku

資料庫
https://mysterious-gorge-11470.herokuapp.com

deploy 新版程式的方法


步驟 1:把所有異動都 commit 進 git

Heroku 只受理我們有 commit 進本地 git repo 的程式,所以要確定修改過的檔案都有 commit 進去了。
在終端機打這些字:
git status
git status 顯示你還沒 commit 進 git 的異動。如果沒有輸出任何東西的話,那你可以 deploy 了!不然的話就要 commit 程式碼進去:
在終端機打這些字:
git add .
git commit -m "Some helpful message for your future self"
Commit message 應該要可以描述你這次修改了什麼東西,像是:「把投票數加到 topics 列表頁」

步驟 2:把異動 push(上傳)到 Heroku

在終端機打這些字:
git push heroku master
這樣子會把本地所有已經 commit 進去的異動都 push 到 Heroku。

步驟 3:在 Heroku 跑資料庫的 migration

在終端機打這些字:
heroku run rake db:migrate
這是叫 Heroku 在它的資料庫跑 migration,作用就像我們在本地跑 rake db:migrate。Heroku 的資料庫跟你電腦上的資料庫是分開的,也就是說每一次你更改了資料庫的結構,你都要在 Heroku 的資料庫更新一次。這也就是說在 Heroku 上面你不會看到你電腦上的 sqlite3 資料庫裡面的資料。

步驟 4:上網看你的程式

在終端機打這些字:
heroku open
會在瀏覽器打開你上傳到 Heroku 的程式。


以上轉至 http://railsbridge-docs-zh-tw.herokuapp.com/初探-rails/deploy_到_heroku?back=設定首頁#every-time