I have the following Rake task:
namespace :foreman do
task :dev do
`foreman start -f Procfile.dev`
end
end
desc "Run Foreman using Procfile.dev"
task :foreman => 'foreman:dev'
The forman command works fine from the shell, however when I run rake foreman
I get the following error:
/Users/me/.gem/ruby/2.0.0/gems/bundler-1.5.2/lib/bundler/rubygems_integration.rb:240:in `block in replace_gem': foreman is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /Users/me/.gem/ruby/2.0.0/bin/foreman:22:in `<main>'
Forman specifically states:
Ruby users should take care not to install foreman in their project's Gemfile
So how can I get this task to run?
Rake allows you to define a list of other tasks that must run before the current task.
Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.
If you must make it work via rake, try changing the shell-out via backtick to use a hard-coded path to the system-wide foreman binary
`/global/path/to/foreman start -f Procfile.dev`
You just need to use 'which' or 'locate' or a similar tool to determine the path that works outside your bundler context. If you are using rbenv, then this might be sufficient :
$ rbenv which rake
/home/name/.rbenv/versions/1.9.3-p448/bin/rake
I hope that helps you move forward.
Not sure if this will work, but you could export the environment variables associated with your shell explicitly and then make a call to foreman
. FWIW, I don't think this is recommended, and would suggest using a bash script as @dax proposes.
Steps
Get the $PATH
and other environment variables from your shell
printenv >> shell.env
Get the environment variables from the rails environment
namespace :foreman_test do
task :dev do
`printenv >> rails.env`
end
end
Compare the two and find out the changed environment variables, and set them up in your rake task in the system
call
namespace :foreman do
task :dev do
`export PATH=/original/path:/value && GEM_DIR=/some/folder && foreman start -f Procfile.dev`
end
end
if it has to be a rake task, try this (from this answer):
namespace :foreman do
task :dev do
sh "foreman start -f Procfile.dev"
end
end
if it doesn't have to be a rake task, I have a simple bash script to start for a specific project that works well:
#!/bin/bash
export PROJECT_DIR=`pwd`
export PORT=$1
source "$HOME/.rvm/scripts/rvm"
unset BUNDLE_GEMFILE
unset BUNDLE_BIN_PATH
unset RUBYOPT
unset GEM_HOME
unset GEM_PATH
(cd <project full path> && exec foreman start -p $PORT)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With