AppFog 部署 Rails

1 条评论 , 9 次修正,6988 次阅读,最后更新于 2013年08月20日

appfog 部署 rails

首先 clone 这个项目https://github.com/appfog/af-ruby-rails/

自己改个名字,如果 clone 的时候没有指定的话

这样做的原因是 af 目前只支持 rails3.2.5,为了偷懒直接 clone 最好

登陆

Alfred-iMac:alfred$ af logn

##上传

**Alfred-iMac:alfred$ af push**
Would you like to deploy from the current directory? [Yn]: 默认
Application Name: alfred
Detected a Rails Application, is this correct? [Yn]:  选择3,速度更快一些
1: AWS US East - Virginia
2: AWS EU West - Ireland
3: AWS Asia SE - Singapore
4: Rackspace AZ 1 - Dallas
5: HP AZ 2 - Las Vegas
Select Infrastructure: 3
Application Deployed URL [alfred.ap01.aws.af.cm]: 
Memory reservation (128M, 256M, 512M, 1G, 2G) [256M]: 1G  只要不是128就成
How many instances? [1]: 
Bind existing services to 'alfred'? [yN]: 默认
Create services to bind to 'alfred'? [yN]: 默认
Would you like to save this configuration? [yN]: 
Creating Application: OK
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (38K): OK   
Push Status: OK
Staging Application 'alfred': OK                                           
Starting Application 'alfred': OK                                          

相关资源地址

rails 数据库

AppFog automatically creates and binds a new MySQL service with the Ruby on Rails jumpstart, and the app is automatically reconfigured to connect to the service. For more information on services and how to connect to them manually, check out our docs on Services.

文档说会自动绑定对应的 services:

如果要使用数据库

  • rails g scaffold something
  • rake db:migrate
  • rake assets:precompile

在 push 的时候需配置 services

上传代码
Alfred-iMac:alfred dudan$ af push --runtime ruby193
Would you like to deploy from the current directory? [Yn]: 
Application Name: alfred
Detected a Rails Application, is this correct? [Yn]: 
1: AWS US East - Virginia
2: AWS EU West - Ireland
3: AWS Asia SE - Singapore
4: Rackspace AZ 1 - Dallas
5: HP AZ 2 - Las Vegas
Select Infrastructure: 3
Application Deployed URL [alfred.ap01.aws.af.cm]: 
Memory reservation (128M, 256M, 512M, 1G, 2G) [256M]: 
How many instances? [1]: 

Bind existing services to 'alfred'? [yN]:         此处注意
Create services to bind to 'alfred'? [yN]: y    此处注意
1: mongodb
2: mysql
3: postgresql
4: rabbitmq
5: redis
What kind of service?: 2
Specify the name of the service [mysql-acaf3]: 
Create another? [yN]: 
Would you like to save this configuration? [yN]: 
Creating Application: OK
Creating Service [mysql-acaf3]: OK
Binding Service [mysql-acaf3]: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (322K): OK   
Push Status: OK
Staging Application 'alfred': OK                                       
Starting Application 'alfred': OK                                      

远程访问数据库

事先要安装 gem install caldecott,如果没有装,首次 af tunnel 的时候会有提示的

Alfred-iMac:alfred dudan$ af tunnel
1: mysql-acaf3
2: mysql-d71c9
Which service to tunnel to?: 1
Stopping Application 'caldecott-ap-aws': OK
Redeploying tunnel application 'caldecott-ap-aws'.
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (1K): OK   
Push Status: OK
Binding Service [mysql-acaf3]: OK
Staging Application 'caldecott-ap-aws': OK                                      
Starting Application 'caldecott-ap-aws': OK                                     
Getting tunnel connection info: OK

Service connection info: 
  username : us8MWQnFsAmwx
  password : pdrw6bwBnhpxX
  name     : d51004e4aa95f4a7c821c77fc1dcde125
  infra    : ap-aws

Starting tunnel to mysql-acaf3 on port 10000.
1: none
2: mysql
3: mysqldump
Which client would you like to start?: 2
Launching 'mysql --protocol=TCP --host=localhost --port=10000 --user=us8MWQnFsAmwx --password=pdrw6bwBnhpxX d51004e4aa95f4a7c821c77fc1dcde125'

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 273720936
Server version: 5.5.8-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show tables
    -> ;
+---------------------------------------------+
| Tables_in_d51004e4aa95f4a7c821c77fc1dcde125 |
+---------------------------------------------+
| blogs                                       |
| schema_migrations                           |
+---------------------------------------------+
2 rows in set (0.35 sec)

mysql> select * from blogs
    -> ;
+----+-----------+---------+---------------------+---------------------+
| id | title     | content | created_at          | updated_at          |
+----+-----------+---------+---------------------+---------------------+
|  1 | 斯蒂芬    | 收到    | 2012-12-20 06:35:02 | 2012-12-20 06:35:02 |
+----+-----------+---------+---------------------+---------------------+
1 row in set (0.35 sec)

至此完成简单的调试。

问题

有的时候会报这个错误

Error (JSON 503): <?xml version="1.0" encoding="u...

执行,指定 ruby 是 1.9.3 的版本就可以解决了

af push --runtime ruby193

todo

  • mysqldump
  • 使用 phpmyadmin