在您的工作区中设置一个PostgreSQL数据库:
$ sudo service postgresql start
$ sudo sudo -u postgres psql
postgres=# CREATE USER username SUPERUSER PASSWORD 'password';
CREATE ROLE
postgres=# \q
选择一个在Heroku上可用的应用程序名称,因为它是您拥有或仍然在Heroku上可用的名称之一。您可以通过访问[potential domain name].herokuapp.com来检查可用性。
$ mkdir ["your app's directory/domain name"]
$ cd ["your app's directory/domain name"]
$ rvm install 2.2.3
$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ rvm use ruby-2.2.3@[your app name] --ruby-version --create
$ gem install rails --no-ri --no-rdoc
$ irb
2.2.3 :001 > require 'securerandom'
=> true
2.2.3 :002 > SecureRandom.hex(64)
=> "137d8b4bf436e670e2eea63372494b84aa25900edb1328eb5c1367f5100fe114fc95313f8772428dbda89ed84086e87a26428ef524951f94fd0375d4e399b613"
2.2.3 :003 > exit
我们(你和我)应该在生产中使用不同的内容。
$ echo "export SECRET_KEY_BASE=137d8b4bf436e670e2eea63372494b84aa25900edb1328eb5c1367f5100fe114fc95313f8772428dbda89ed84086e87a26428ef524951f94fd0375d4e399b613" >> ~/.profile
重新启动终端以设置环境变量。在Cloud9中,在终端中右键单击并选择“重新启动所有终端”即可。重新启动终端可能会将您返回到根目录。如果是这种情况,请使用以下命令更改为新应用程序目录:
$ cd [your app directory]
现在你已准备好加速Rails Composer了
$ rails new . -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
在Google上生成Google Analytics ID并输入。
为部署做准备:2 -- Heroku
禁用Rails Turbolinks吗?:n
禁止蜘蛛爬取:n
创建Github存储库吗?:n -- 我计划使用Bitbucket
添加环境变量的gem和文件吗?:1
在开发期间减少资产记录器噪音吗?:y
在开发期间使用'better_errors'来改进错误报告吗?:y
在开发和测试期间使用'pry'作为控制台替代品吗?:y
使用'rubocop'确保您的代码符合Ruby样式指南吗?:y
创建一个特定于项目的rvm gemset吗?:y
添加'therubyracer'吗?:n
[正在创建应用程序!]
PostgreSQL的用户名(留空以使用应用程序名称)用户名#根据我上面输入的内容创建本地pg数据库
database.yml中的PostgreSQL主机?(留空以使用默认套接字连接)留空
密码#也是根据我上面输入的内容创建本地pg数据库
可以删除名为[您的应用程序名称]的所有现有数据库吗?:y
提交最终更改到Git Rails Composer似乎会跳过一个最终的提交...请按照以下步骤进行:
$ git add .
$ git commit -am “Final rails_composer commit”
请按照Bitbucket上的指示创建新存储库,并从命令行将其推送到现有项目中。
按照‘Heroku入门’中的说明进行操作,其中包括以下步骤:
$ heroku login
在提示处输入您的Heroku凭据。
$ heroku create [your app name (without the herokuapp.com stored as a local variable above)]
请使用以下命令确认已添加 Heroku 远程仓库:
$ git config --list | grep heroku
$ git push heroku master
现在你已经在Heroku上创建了应用程序,还需要使用以下命令添加一些环境变量:
$ heroku config:set DOMAIN_NAME=[your app name].herokuapp.com
$ rake secret # uses rake to generate a new secret key
$ heroku config:set SECRET_KEY_BASE=5ed8c7d9a3bda9cec3887b61f22aa95bf430a3a550407642b96751c7ef0ce8946a161506d6739da0dcaaea8c8f4f8b3335b1fb549e3cc54f0a4cec554ede05f8
$ rake secret
来生成一个不同的SECRET_KEY_BASE,而不是我在上面的代码中包含的那个。$ heroku run rake db:migrate
$ touch Procfile
[Procfile]
web: bundle exec puma -C config/puma.rb
$ touch config/puma.rb
[config/puma.rb]
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
因为我不指望我的应用程序会有太多的流量,并且无法保证它是线程安全的:
$ heroku config:set MIN_THREADS=1 MAX_THREADS=1
使用以下命令提交Procfile和puma配置文件:
$ git add .
$ git commit -m "Add Procfile and config/puma.rb"
$ git push && git push heroku
我希望这些指示对您有所帮助。请随意添加和改进它们。