当我的RAILS_ENV设置为开发时,如何强制在OpenShift Online上捆绑安装? [英] How can I force a bundle install on OpenShift Online when my RAILS_ENV is set to development?
问题描述
我在OpenShift Online上有一个Rails应用,该应用正尝试使用 RAILS_ENV = 开发进行设置,而不是默认环境 production . >.稍后,我将添加测试,暂存和生产域的想法.
I have a Rails app on OpenShift Online that I'm trying to setup with RAILS_ENV=development as opposed to the default env of production. The idea being later on I'll add test, staging and production domains.
我的问题是,因为环境设置为 development (开发),当我执行 git push 时运行的OpenShift进程表示它跳过了捆绑安装":
My problem is that because the env is set to development the OpenShift process that runs when I do a git push says it's skipping "bundle install":
remote: NOTE: Skipping 'bundle install' because running in development mode.
我通过将 RAILS_ENV 设置为生产临时来进行捆绑安装.
I got it to do the bundle install by setting RAILS_ENV to production temporarily.
更新:
尝试通过 .openshift/action_hooks/pre_build 强制进行捆绑安装.在 pre_build 钩子期间出现 Gemfile语法错误.当使用RAILS_ENV = production时, Gemfile 在本地和OpenShift上均可工作.
UPDATE:
Tried forcing a bundle install via .openshift/action_hooks/pre_build. Getting Gemfile syntax error during pre_build hook. Gemfile works locally and on OpenShift when using RAILS_ENV = production.
source 'https://rubygems.org'
gem 'rails', '4.1.4'
### OpenShift Online changes:
# Fix the conflict with the system 'rake':
gem 'rake', '~> 0.9.6'
# Iron.io gems
gem 'iron_mq'
#gem 'iron_worker_ng'
# Support for databases and environment.
# Use 'sqlite3' for testing and development and mysql and postgresql
# for production.
#
# To speed up the 'git push' process you can exclude gems from bundle install:
# For example, if you use rails + mysql, you can:
#
# $ rhc env set BUNDLE_WITHOUT="development test postgresql"
#
group :test do
gem 'sqlite3'
gem 'minitest'
end
group :development, :test do
gem 'thor'
end
# Add support for the MySQL
group :development, :production, :mysql do
gem 'mysql2'
end
### / OpenShift changes
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
#!/bin/bash
# This is a simple script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the build step. This script gets executed directly, so it
# could be python, php, ruby, etc.
if [[ "$RUBY_VERSION" == "1.8" ]]; then
echo "ERROR: This quickstart is not compatible with Ruby 1.8"
echo "ERROR: Please use ruby-1.9 or ruby-2.0 application type."
exit 1
fi
if [[ "$RAILS_ENV" == "development" ]]
then
echo "Forcing bundle install for environment: $RAILS_ENV"
pushd $OPENSHIFT_HOMEDIR/app-root/repo > /dev/null
bundle install --path ./vendor/bundle
popd > /dev/null
fi
remote: Stopping MySQL 5.5 cartridge
remote: Ruby cartridge in development mode, skipping stop...
remote: Force clean build enabled - cleaning dependencies
remote: Building git ref 'master', commit 5c3182d
remote: Forcing bundle install for environment: development
remote: Gemfile syntax error:
remote: /var/lib/openshift/540306395973ca6dc30006bc/app-root/runtime/repo/Gemfile:56:
remote: syntax error, unexpected ':', expecting $end
remote: gem 'sdoc', '~> 0.4.0', group: :doc
remote: ^
remote: Building Ruby cartridge
remote: NOTE: Skipping 'bundle install' because running in development mode.
remote: Preparing build for deployment
remote: Deployment id is a65ea3ad
remote: Activating deployment
remote: Starting MySQL 5.5 cartridge
remote: NOTE: The 'rake assets:precompile' is disabled when Ruby is in development mode.
remote: bundle exec rake db:migrate RAILS_ENV=development
remote: /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-0.9.6 in any of the sources (Bundler::GemNotFound)
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/spec_set.rb:85:in `map!'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/spec_set.rb:85:in `materialize'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/definition.rb:114:in `specs'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/definition.rb:159:in `specs_for'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/definition.rb:148:in `requested_specs'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/environment.rb:18:in `requested_specs'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:13:in `setup'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
remote: from /opt/rh/ror40/root/usr/share/gems/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
remote: from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
remote: from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
remote: -------------------------
remote: Git Post-Receive Result: failure
remote: Activation status: failure
remote: Activation failed for the following gears:
remote: 540306395973ca6dc30006bc (Error activating gear: CLIENT_ERROR: Failed to execute action hook 'deploy' for 540306395973ca6dc30006bc application pvcentral)
remote: Deployment completed with status: failure
remote: postreceive failed
To ssh://540306395973ca6dc30006bc@pvcentral-pervasivdev.rhcloud.com/~/git/pvcentral.git/
8d74e27..5c3182d master -> master
推荐答案
我能够通过 RAILS_ENV = development 通过做两件事:
I was able to force a bundle install with RAILS_ENV=development by doing two things:
- 修改了 pre_build 动作挂钩,以使用正确版本的ruby和环境上下文执行捆绑安装"
- 添加了 force_clean_build 标记
- Modified the pre_build action hook to execute "bundle install" with the correct version of ruby and environment context
- Added the force_clean_build marker
注意:我的应用是使用Rails 4(4.1.4)和 Ruby 2.0 快速入门创建的.
NOTE: My app was created using the Rails 4 (4.1.4) and Ruby 2.0 quickstart.
在将捆绑安装"添加到动作挂钩(建议pre_build是正确的修改对象)之后,我在上面尝试了什么,除了执行如下:
What I tried above after the suggestion to add "bundle install" to an action hook (turns out pre_build is the correct one to modify) was okay except executing as:
捆绑安装--path ./vendor/bundle
bundle install --path ./vendor/bundle
导致'sdoc'出现奇怪的Gemfile语法错误.
results in a weird Gemfile syntax error on 'sdoc'.
我注意到 deploy action hook 包含用于提供几个文件的代码,这些文件用于设置ruby版本和执行上下文.并以"pundle"的形式执行:
I noticed that the deploy action hook included code to source a couple of files to set the ruby version and execution context. And also executed "bundle" as:
ruby_with_nodejs_context "bundle exec rake db:migrate"
添加正确的"执行上下文(见下文)后,Gemfile语法错误消失了.最后,我不得不添加force_clean_build标记,因为没有它,我会得到错误:
After adding the "right" execution context (see below), the Gemfile syntax error disappeared. Finally, I had to add the force_clean_build marker because without it I was getting errors:
remote: Building Ruby cartridge
remote: Restoring previously bundled RubyGems
remote: NOTE: You can commit .openshift/markers/force_clean_build to force a clean bundle
remote: ERROR: You need to remove the ".bundle" directory from your GIT repository.
remote: An error occurred executing 'gear postreceive' (exit code: 1)
remote: Error message: CLIENT_ERROR: Failed to execute: 'control build' for /var/lib/openshift/54077e9a5973ca2e6900096f/ruby
.openshift/action_hooks/pre_build
source $OPENSHIFT_CARTRIDGE_SDK_BASH
source ${OPENSHIFT_RUBY_DIR}/lib/ruby_context
pushd ${OPENSHIFT_REPO_DIR} >/dev/null
if [[ -f .openshift/markers/force_clean_build && "$RAILS_ENV" == "development" ]]
then
echo "bundle install --path ./vendor/bundle"
ruby_with_nodejs_context "bundle install --path ./vendor/bundle"
fi
popd > /dev/null
这篇关于当我的RAILS_ENV设置为开发时,如何强制在OpenShift Online上捆绑安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!