mattbrictson / capistrano-mb

[unmaintained] Capistrano tasks for deploying Rails from scratch to Ubuntu 16.04 and 18.04

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provisioning fails with Errno::ENOENT: No such file or directory @ rb_sysopen - .ruby-version

mazharoddin opened this issue · comments

Hi,

I am getting below error while trying to provision my ubuntu VM using capistrano-mb gem.
I tried provision using below command.

cap staging provision:14_04

Above command installed several packages, but finally failed with below error.

DEBUG [7c8ef0ef]    Reading extended state information...
DEBUG [7c8ef0ef]    Initializing package states...
DEBUG [7c8ef0ef]    Writing extended state information...
INFO [7c8ef0ef] Finished in 12.511 seconds with exit status 0 (successful).
(Backtrace restricted to imported tasks)
cap aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - .ruby-version

Tasks: TOP => mb:rbenv:compile_ruby
(See full trace by running task with --trace)

Later I tried to deploy sample app using deploy command.

 cap staging deploy

But it failed with below error.

INFO [cf753374] Running /usr/bin/env gem install bundler --conservative --no-document -v 1.10.6 as deployer@192.168.2.101
DEBUG [cf753374] Command: gem install bundler --conservative --no-document -v 1.10.6
DEBUG [cf753374]    ERROR:  While executing gem ... (OptionParser::InvalidOption)
DEBUG [cf753374]        invalid option: --no-document
DEBUG [cf753374]    
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@192.168.2.101: gem install bundler --conservative --no-document -v 1.10.6 exit status: 1
gem install bundler --conservative --no-document -v 1.10.6 stdout: Nothing written
gem install bundler --conservative --no-document -v 1.10.6 stderr: ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --no-document

Can you please let me know how to resolve these errors.

Thanks,
Mazhar

capistrano-mb expects .ruby-version file at the root of your Rails project that contains the version number of Ruby that your project requires. This file is created by tools like rbenv and rvm. For example. the file could contain:

2.2.3

That is how capistrano-mb knows what version of Ruby to install on the Ubuntu VM.

You'll need to create that file and then redo the provision command.

Thank you, it resolved the issue. I am able to provision my VM now.

Hi,
One more general question, while provisioning VM, capistrano-mb gem installed most of the required libraries and packages as part of provision, but during deploy few gems installation failed due to missing libraries, e.g rmagick failed because libmagickwand-dev was missing on my VM,
I installed missing libraries manually by logging into VM, but is it possible to add these packages to capistrano-mb config file so that next time provision will install required libraries automatically... can you please let me know where I can add this if its possible.

Thank you for sharing this gem, this gem is wonderful and with this gem deployments are really easy to do :)

Packages are determined using the :mb_aptitude_packages hash, which has this default value (see defaults.rake for this and other defaults that capistrano-mb uses):

set :mb_aptitude_packages,
    "curl"                                   => :all,
    "debian-goodies"                         => :all,
    "git-core"                               => :all,
    "libpq-dev@ppa:pitti/postgresql"         => :all,
    "nginx@ppa:nginx/stable"                 => :web,
    "nodejs@ppa:chris-lea/node.js"           => :all,
    "postgresql-client@ppa:pitti/postgresql" => :all,
    "postgresql@ppa:pitti/postgresql"        => :db,
    "ufw"                                    => :all

The format is package => role, which capistrano-mb uses to decide which packages are installed on which servers.

So if you wanted to install the libmagickwand-dev package on all servers, you would add something like this to your deploy.rb:

fetch(:mb_aptitude_packages).merge!("libmagickwand-dev" => :all)

This takes effect on your VM when you run provision, or if you want to just run the package installation step, you could do:

cap production mb:aptitude:install

Thank you, I will try this. btw I successfully deployed my site, everything went well except couple of issues.

  1. I am getting always secret_key_base missing error, I tried to provide the key value by running
rake secret RAILS_ENV=production

I tried putting this value in .env file , but it didn't worked, so I tried to use figaro gem and put the the key value in config/application.yml, even I tried to modify secret.yml file directly, but nothing worked so far, for time being I directly modified config/application.rb and provided secret key base as config.secret_key_base =' ' and checked in this file.

This resolved the issue for time being, but pls let me know if there is any better way if you came across this already, until then I will continue with workaround for now.

  1. Second problem I am facing is assets are not showing after deploy, no assets are loading in production environment, I observed that assets are getting created during deploy and public/assets directory exists with all compiled assets. but still some how all assets are blank if I access the site using browser.

Website source showing below asset files after deployment.

<link rel="stylesheet" media="all" href="/assets/application.css" data-turbolinks-track="true" />
<script src="/assets/application.js" data-turbolinks-track="true"></script>

But actually assets directory has these assets compiled.

application-5c0522c4c060a12a3d4c30ce1483529093f25e6617868a398f2e448697224744.js
application-ca5f438ed1ddd61c3b5bb692c7f81b514d747dd3872117dae933d113ebc7cb5b.css

I am not able to figure it out why rails server is trying to load /assets/application.css file instead of actual asset file which is compiled during deployment.

I am getting 404 error if I try to access /assets/application.css file manually , but able to access http:///assets/application-ca5f438ed1ddd61c3b5bb692c7f81b514d747dd3872117dae933d113ebc7cb5b.css without any issue.

Can you please let me know how I can resolve this issue. Thank you so much for your help and time.

Thanks
Mazhar

Setting the secret key base and referencing assets are more general Rails issues, not something to do with capistrano-mb. I suggest posting Stack Overflow questions for those.

If it helps, here's how I set the secret key base in my apps (it assumes RAILS_SECRET_KEY_BASE is set in the .env file): https://github.com/mattbrictson/rails-template/blob/master/config/initializers/secret_token.rb

I will close this issue for now. If you run into any new issues that are specific to capistrano-mb, feel free to open a new issue.

I agree secret key base and assets related issues are related to RAILS , but same code I was able to deploy to heroku and using capistrano 2 without any issue, everything worked as expected with heroku and capistrano 2, so I was thinking some capistrano-mb issue might be creating problem here.

Hi,
I tried with other app, before deploying I tried to run it locally in production mode by setting "config.serve_static_files = true" in production.rb file, and I see all assets are loaded properly without any issue.
But when I deploy same app using capistrano-mb gem assets are not loading in production.
I really this bug got resolved so that I can use capistrano-mb for my deployments ..

Hi, please let me know if I can open new issue for this, because this is recreatable on other apps aswell.

Please open a new issue and provide the erb/haml that is responsible for rendering the <link> and <script> tags that are not loading.