8

I have spent couple of hours but unable to solve this problem.

When I try to deploy my local rails app to production server using capistrano I get the below error:

The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.

Any idea on how to solve this?

My rails application folder is under version control using Git. I have pushed the local git repo to github and the Gemfile.lock is there on github. So it is under version control. However capistrano continues to give the same error.

Deploy.rb file: https://gist.github.com/brahmadpk/4748991

  • I was in same problem. got fix by [adding Gemfile.lock to repo](http://stackoverflow.com/a/4151540/1090699). – codian Mar 05 '17 at 23:09

7 Answers7

13

Remove BUNDLE_FROZEN: "true" from .bundle/config file and run bundle again.

Linus
  • 4,643
  • 8
  • 49
  • 74
  • This solved it for me, however I had to remove the line from `~/.bundle/config`, which took me a few minutes to find. – dafalcon Jan 11 '21 at 02:59
7

Make sure there is nothing in the releases folder that is not a release. See this comment on a bundler issue for more details.

This blogpost titled Capistrano Deployment Trouble explains the same issue.

EDIT TO INCLUDE CONCLUSION FROM DISCUSSION IN COMMENTS

The deploy_to param was not set to an absolute path; hence capistrano wasn't able to find the folder to deploy, causing this error message.

Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
  • Yes, checked those articles, there is nothing in the releases folder. –  Feb 10 '13 at 09:25
  • After you added the `deploy.rb file`: Set the `:deploy_to` param to a path. Right now, it is getting set to `fxtofx`. With that, where would capistrano deploy the files to? Set it to an absolute path like `/var/#{application}`. – Prakash Murthy Feb 10 '13 at 09:35
  • Prakash - my application directory is 'fxtofx' on the server. Hence I am using `#{application}`. So the directory structure is fxtofx/releases etc. is there any issue using it that way? –  Feb 10 '13 at 09:46
  • 1
    How is capistrano able to find `fxtofx/releases`? Or for that matter how do you go to `fxtofx/releases `? Shouldn't it be `/fxtofx/releases` or `/usr/fxtofx/releases` or something starting from the root? – Prakash Murthy Feb 10 '13 at 09:53
  • Ok .. I can see what you are pointing out. When I am using `/#{application}`, I am getting an error `mkdir: cannot create directory /fxtofx' `. my linux skills may not be the best. –  Feb 10 '13 at 10:00
  • Create the base directory (`/fxtofx` or `/var/fxtofx` to follow conventions) manually on the server; and then try deploying. – Prakash Murthy Feb 10 '13 at 10:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24263/discussion-between-brahmadpk-and-prakash-murthy) –  Feb 10 '13 at 10:13
  • On my server: `cd ~`, then `mkdir /fxtofx`, I am getting an error of permission denied. Even if I create the directory using sudo, then `deploy:setup` gives the error –  Feb 10 '13 at 10:20
4

I solve this with:

set :bundle_gemfile, "your_app_name/Gemfile"

in the deploy.rb

Alexandre Alves
  • 196
  • 4
  • 5
1

After adding bundle config unset deployment this line in the terminal, bundle install started working again for me.

hananamar
  • 1,166
  • 15
  • 25
0

Run bundle and add your Gemfile.lock to your version control.

Michaël Witrant
  • 7,525
  • 40
  • 44
  • I can see a Gemfile.lock in my rails directory. As I mentioned in the question my rails directory is under version control. How to add Gemfile.lock specifically? –  Feb 10 '13 at 08:56
  • It depends on your version control. If you use git run `git add Gemfile.lock` (remove it from your `.gitignore` first if needed). – Michaël Witrant Feb 10 '13 at 09:00
  • Capistrano pulls your app from the remote repository. Did you push your changes before the deploy? – Michaël Witrant Feb 10 '13 at 09:40
  • I am not using github. I have used set :deploy_via, :copy –  Feb 10 '13 at 09:44
  • You may try `set :copy_strategy, :export`, but I can't see why capistrano won't copy Gemfile.lock if it's tracked by git. The doc says "the SCM checkout command is used to obtain the local copy" (https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy/strategy/copy.rb) – Michaël Witrant Feb 10 '13 at 10:08
0

I had the same problem, even though I had no files or folders in the releases folder. Turned out it was a silly little thing: the gemfile.lock file in my repo was in lowercase for some reason, while capistrano needs Gemfile.lock with a capital G.

This is how I solved it:

  1. Delete gemfile.lock
  2. Delete gemfile.lock from you repo (git rm ...)
  3. run bundle install
  4. add the new Gemfile.lock file to your repo: git add Gemfile.lock
  5. remove the folders from the server (don't know if this is really needed, did it anyway)
  6. deploy
Henk
  • 59
  • 1
  • 3
-1

I am getting exactly the same problem.

There is nothing in my releases folder (at all - my deploy cold keeps rolling back).

My gemfile.lock is checked in to Subversion.

I get:

** [out :: localhost] The --deployment flag requires a Gemfile.lock. Please make sure you   have checked your Gemfile.lock into version control before deploying.

Is there any way to stop the rollback so that I can see what the releases folder looks like at the time it tries to run

cd /var/qlarity/releases/20130222003607 && bundle install --gemfile /var/qlarity/releases/20130222003607/Gemfile --path /var/qlarity/shared/bundle --deployment --quiet --without development test

Later....

I found that I could prevent the rollback by commenting out the code as shown from

gems\capistrano-2.14.1\lib\capistrano\recipes\deploy.rb

task :update_code, :except => { :no_release => true } do
  # on_rollback { run "rm -rf #{release_path}; true" }
  strategy.deploy!
  finalize_update
end

This enabled me to examine my releases folder and sure enough, there was no Gemfile.lock in it. Turns out I have ended up with an unnecessary folder in my Rails project file structure so that instead of

myapp/trunk/app
myapp/trunk/config
...
myapp/trunk/Gemfile

I had

myapp/trunk/myapp/app
myapp/trunk/myapp/config
...
myapp/trunk/myapp/Gemfile

This meant I ended up with a folder containing my Gemfile

releases/nnnn/myapp

and bundle was looking for Gemfile in

releases/nnnn

When I changed my Capistrano config from

deploy.rb 

set :repository, "file:///D:/_SVN//myapp/trunk"

to

deploy.rb 

set :repository, "file:///D:/_SVN//myapp/trunk/myapp"

now all is good. Really should look at fixing the folder structure next!

Craig Miles
  • 447
  • 4
  • 18