How to make cap deploy link my vendors folder? - ruby-on-rails

I would like to link my vendor folder so I don't have 5 minutes down time every time I deploy and have to run bundle install --deployment.
Thanks!

May be you can use a rake task after the capistrano deploy, for example.

One option is to create a new task to symlink vendor to the shared path and set it to run before bundle:install, but this is a little unnecessary - it'd be nicer to just bundle to the shared path in the first place instead of vendor.
If you're requiring and using 'bundler/capistrino' in your deploy.rb file, all you need to do is set bundle_dir and bundler will pick it up:
set :bundle_dir, File.join(fetch(:shared_path), 'bundle')
If you've written your own bundle task, set the variable as above, then use --path #{fetch(:bundle_dir)} in the task.

Updating to the latest version of Capistrano helped.

Related

How to setup the development environment using cap

I would like to run cap development deploy:setup and cap development deploy to setup the dev environment for my rails app. In order to do this, I will have to remove the project folder from the remote machine, is there a way to automate this in some fashion using cap.
I basically want to remove the app folder in remote machine before I do a full deploy.
The Capistrano app folder is structured like this:
releases - Contains separate folders (named using commit IDs or timestamps) for each deployment made so far
current - Linked to the latest deployment folder under releases
shared - Shared logs, gem files, and tmp which are used between deployments
Now do you really want to clean the entire app folder? That could be dangerous since you'll lose logs.
current is just a symbolic link, it points to the latest release only.
If you want to clean up old releases, check this answer. You can set keep_releases to 1.
If you want to delete the shared folder as well, then you have to write your own Capistrano hook as #Strik3r mentioned.
before 'deploy:setup', 'removecode'
task :removecode do
run "rm -rf <path>", :shell => fetch(:rvm_shell)
end
add this code in to your deploy.rb file, this will call before deploy:setup
in this way you can create a task and do what ever you want to do

Grab Ruby on Rails files and install on local machine

general question that can be used in many different situations, so I thought it would be interesting to ask.
I'm semi new to Ruby and am learning from Treehouse. I am doing the social media site project, and am about half way through.
I was hoping to set up a separate installation from the source files they give you, of the completed site, to do a simple compare and contrast, and really I am just curious as to what the final product is gonna be like.
My question is, is there an easy way to just grab their files, install all the gems and dependencies and run the rails server. If I just try to run the server on the folder, I get a bunch of errors about Gems not being installed and such, which is expected.
If anyone has a process they use when doing things like migrated entire environments from one location to another, it would be appreciated!
Go to project directory.
Install all of the required Gems by executing
bundle install
Create database by executing
rake db:create
Then migrate the database by executing
rake db:migrate
And finally run the application using
rails s
If you have cloned their repository, or copied the files to a folder, try running
bundle install
from the command line

Use a .rvmrc file from a Ruby script

Backgound
A little background to this question first: Ruby on Rails has some security issues as of late. So we need to update the Rails version on our projects. If you have a few, that gets old fast if you do it by hand... So I figured I can create a Thor task for this.
Question
This now works great! BUT! I need to respect the .rvmrc file for each project while installing the new versions of rails. I want this script to be OpenSourced soon, but I want to tacle the problem of not respecting the .rvmrc file first.
So what I need is a way of using the right RVM ruby version/gemset when I change to a directory to update the Rails version.
How is the way for this to be done? Can it be done from the Ruby script in a way so that it works on Mac and Linux, regardless of Shell (found a answer with zsh support, but what about all the other shells out there?)
Quick Example code:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
Dir.chdir(project_folder) do
#TODO: Respect/load the rvmrc file in this directory
update_gem_file(project_folder) #example
run 'bundle update rails' #<--- needs to be done in the RVM gemset
end
}
Just to give you an idea of what I'm trying to do.
Link to the script on the githubs
The github repo for my script -- Work in Progress!
Check out this project https://github.com/versapay/bundler-auto-update it basically:
Attempt to update every single gem of your Gemfile to its latest patch, minor then major release. Runs a test command to ensure the update succeeded
As for RVM use this simple code:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
run "rvm in #{project_folder} do bundle-auto-update -c rake spec"
}
You can find more details on scripting with RVM on https://rvm.io
Blindly upgrading Rails is not a good idea. At least run your test suite to ensure nothing breaks. After that you still want to do some QA on the app to make sure you didn't break all the things.
Then, How do you know that the current branch you're updating is actually the main develop branch? Don't you want to create a 'hotfix' branch and apply it to your production and development branches?
But, let's say you did manage to upgrade all your apps, they are still not deployed to production.

Spree Commerce is working, but no assets.

I'm trying to customize and modify Spree Commerce, but none of the standard asset files/images/views are available under either app/views, lib/assets, or anywhere else I can think to look. I'm trying to go through their tutorials, but I can't find anything to edit. Is there another command I need to decompress everything or something? Thank you so much for any help!
The way I over came this is to download the main spree gem, via github.com, look where the images are located then creating the images I wanted to override in my local app/assets directory with the same path run:
rake assets:precompile:nondigest
restart webrick/pow or any other web server you are running and voila!
I'm guessing you're not really familiar with how gems work. As people here have said, these are not going to automatically show up in your core app directory, but the gemfile and running bundle install knows how to reference them.
So you need to find those gems to figure out the file names, as you said. If you want to view the gemfiles run this command in the terminal:
$ bundle open spree_frontend
If you get this error:
To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR
then you haven't set up the editor, so do this:
export BUNDLER_EDITOR=sublime
Then redo the bundle open command. This should open the spree_frontend directory which will let you investigate the file names/paths and the assets. If you want to change an entire template, you need to create that file matching its name and path exactly as it is in the spree gem (spree/layouts/spree_application.html.erb for example) then when you edit it your rails app will render the code in your core app directory thus overriding the spree gem.
That make sense?

Why does rails ignore .bundle by default?

Isn't the point of the project .bundle/config to specify config that is relevant to the project?
On the bundle-config manpage is says:
This command allows you to interact with bundler's configuration
system. Bundler retrieves its configuration from the local application
(app/.bundle/config), environment variables, and the user's home
directory (~/.bundle/config), in that order of priority.
So ensure that you don't have any configuration files that are taking priority over the one you want to use.
You can configure this file yourself or set options using bundle config (option), running bundle config without any options prints the current configuration.
For example you can set compile time options for they mysql gem like so:
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
So yes, app/.bundle/config is used to set bundle options for the current project.
Edit:
This change was added in commit efa85055 to the Rails github repo. You can view that version of the file here and the commit here.
The commit message is from José Valim and mentions the line you have a question about:
Make bin/rails call rails/commands/application, fix generators usage
and update .gitignores.
Edit Again:
This is a quote from bundler on why you should not check the .bundle directory into any VCS.
Do not check in the .bundle directory, or any of the files inside it.
Those files are specific to each particular machine, and are used to
persist installation options between runs of the bundle install
command.

Resources