每当gem'加载命令失败:耙'

寻找一些帮助。

我正在运行一个rails应用程序(v3.2.5)随时gem(v0.9.7)和rake (v11.2.2)。 我也在docker的容器图像做这个ruby:2.3cron被安装和bundle install被运行)

这是我的schedule.rb

 set :environment, ENV['RAILS_ENV'] every '*/2 9,10,11,12,13,14,15,16 * * 1-5' do rake "import_csv", output: {:error => 'log/import_csv_errors.log', :standard => 'log/import_csv.log'}' end 

注意 RAILS_ENV设置在容器启动到development

这是我的构build后的容器( crontab -l )上的cron作业:

 # Begin Whenever generated tasks for: /usr/src/app/config/schedule.rb */2 9,10,11,12,13,14,15,16 * * 1-5 /bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log' # End Whenever generated tasks for: /usr/src/app/config/schedule.rb 

当此cron作业运行时,日志将返回:

import_csv_errors.log

 Bundler::GemNotFound: Could not find rake-11.2.2 in any of the sources /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:95:in `block in materialize' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:185:in `specs_for' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:174:in `requested_specs' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/environment.rb:19:in `requested_specs' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:14:in `setup' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler.rb:95:in `setup' /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/setup.rb:19:in `<top (required)>' /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 

import_csv.log

 bundler: failed to load command: rake (/usr/local/bin/rake) 

现在这是奇怪的事情。 如果我复制cron作业命令:

 /bin/bash -l -c 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log' 

并在容器中运行它,它工作正常,但如果cron作业运行它,我得到日志中的错误! 我在这里迷路了

我试过添加

 env :PATH, ENV['PATH'] env :GEM_PATH, '/usr/local/bundle' 

schedule.rb的顶部,我试着做

 command 'cd /usr/src/app && RAILS_ENV=development bundle exec rake import_csv --silent >> log/import_csv.log 2>> log/import_csv_errors.log' 

而不是在任务中使用rake ,我得到相同的错误..

任何帮助appriciated

我更新了我的耙子版本,它为我工作。 以下是我遵循的步骤:

 sudo bundle update rake sudo bundle install 

打开一个Rakefile,把rake/rdoctaskreplace为require 'rdoc/task'

我通过修改Dockerfile修复了相同的错误:

 RUN gem update --system 2.6.12 RUN gem install bundler --version 1.14.6 

schedue.rb

 ENV.each { |k, v| env(k, v) } 

我解决了我的问题,通过使用不同的图像和build设,因为我需要它,而不是使用docker中心图像ruby:2.x

Dockerfile(编辑以适应线程):

 FROM ubuntu:14.04 # Installs needed to run rails on ubuntu 14.04 (must use mysql 5.6 or 5.5): RUN apt-get update && apt-get install -y apache2 curl git build-essential libmysqlclient-dev mysql-server-5.6 nodejs make RUN apt-get update && apt-get install -y ruby-dev zlib1g-dev RUN gem install rails --version 3.2.5 --no-ri --no-rdoc # Update ruby to v2.2 (optional) RUN apt-get install -y software-properties-common && apt-add-repository ppa:brightbox/ruby-ng RUN apt-get update && apt-get install -y ruby2.2 # Install cron RUN apt-get install -y cron # Finish the build RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # If you code is in the same directory you ran docker build then: COPY . /usr/src/app RUN bundle install RUN whenever --update-crontab CMD ["passenger start"]