Vinova tuyển lập trình viên Mobile & Web ở Hà Nội, lương $300-1000

Article: Deploy project rails trên github lên trang heroku.com 1169

tinnguyentrong.myopenid.com 1
Updated over 2 years ago

Chào các bạn trên bliki cntt.tv, mình là dev rails, sẵn anh Ngọc đã viết về Git thì mình cũng hùa theo viết 1 bài hướng dẫn về cách deploy 1 project trên github lên heroku.com . Bài này chỉ dành cho OS Windows

 

 

Heroku là gì?

Heroku is an online Ruby on Rails development and hosting environment run by a San Francisco, California based company with the same name. It was one of the first cloud platform providers (having been in development since June 2007), and provides both in-browser development, collaboration and code repositories as well as hosting and scaling.

Nó hoạt động ra sao?

Tham khảo http://heroku.com/how/architecture

Chuẩn bị

  • Trước tiên chúng ta đăng ký 1 tài khoảng Heroku tại đây http://heroku.com/signup
  • Cài gem Heroku : gem install heroku
  • Đăng ký 1 tài khoản trên http://github.com
  • Download msysgit để cài git trên win (Khi cài đặt nhớ chọn Use Git Bash only )
  • Một rails app trên local của bạn (Nên dùng db Mysql hoặc postgreSQL và dung lượng app dưới 5MB nha, vì mình xài gói free Blossom )

Upload rails app lên github

  • Trước tiên cần tạo 1 ssh-keygen, vào git Bash, sau đó sinh ra ssh-keygen bằng lệnh

ssh-keygen -C "username@email.com" -t rsa

username@email.com dĩ nhiên là mail mà mình đăng ký trên github, nó sẽ hỏi mình thêm vài option mình có quyền để trống. Qua bước này nó sẽ sinh ra được file id_rsa.pub nằm trong thư mục C:\Documents and Settings\ten-ban\.ssh. Ta mở file này lên và copy toàn bộ nội dung paste vào phần SSH Public Keys trên GitHub

Global setup:

  Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email yourname@domain.com
       

Next steps:

  mkdir test
  cd test
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:YourName/your_respo.git
  git push origin master

     

Sau khi chạy 2 lệnh git config, ta sẽ vào thư mục rails app đã chuẩn bị trước, ta chạy lệnh

git init

git add .

 git commit -m 'first commit'
 git remote add origin git@github.com:YourName/your_respo.git
 git push origin master

(Nếu có báo lỗi permission, hoặc ko thể establish được thì các bạn xem lại về ssh keygen)

Sau khi hoàn thành bước này ta sẽ có 1 project tren github và bước tiếp theo là sẽ deploy project này lên trang heroku, sau khi deploy thành cong ta sẽ có 1 địa chỉ link đến app của ta dưới dạn gwww.subdomain.heroku.com. (Heroku )

Deploy projec từ github len heroku.com

  • Vào git Bash chạy lệnh sau

 cd rails_path

heroku create
>Enter your Heroku credentials.
>Email: joe@example.com
>Password:
>Uploading ssh public key /Users/joe/.ssh/id_rsa.pub

Nó sẽ tự động load id_rsa.pub vừa tạo ở bước generate ssh keygen

...

>created http://xx-xx-xx.heroku.com | git@heroku.com:xx-xx-xx.git

  • Bước cuối cùng ta add và deploy project tren git len heroku như sau (vẫn đứng ở rails root path nha)

 git remote add heroku git@heroku.com:xx-xx-xx.git
 git push heroku master

  • Migrate database

heroku rake db:migrate

  • Bạn truy cập vào http://xx-xx-xx.heroku.com để thấy heroku đã deploy app của bạn :-D
  • Khi bạn commit code len github muốn deploy lại thì chạy tiếp

git push heroku

Thank for watching.

Tài liệu tham khảo

 

Comments

ngocdaothanh.myopenid.com 172
Updated over 2 years ago

Hiện Heroku chỉ cho chạy Rails, nhưng có thể nói cấu trúc của nó cho phép chạy tùm lum thứ, thuộc dạng Heterogenous (hệ thống cẩu tạp chủng). Cùng với Cloud Computing (điện toán trên mây), đây là xu hướng mới của CNTT. Tham khảo thêm slide nói về Fuzed này.

You must login to be able to comment

Uploaded files
Name Size Uploader Time
heroku-proof.PNG 66 KB
tinnguyentrong.myopenid.com 1
over 2 years ago

You must login to be able to upload

Nhà tài trợ:

Mọi người đều tự do viết bài, sửa bài của người khác, và bình luận ở trang web này. Bạn muốn chủ động tạo bài mới để chia sẻ kinh nghiệm với mọi người? Xin click link ở dưới.

Create new content