Why does rails ignore .bundle by default? - ruby-on-rails

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.

Related

Rails 4.2 capistrano 3 deployment

I am totally new to rails deployment. After googling, I still find it hard to understand how to deploy rails apps.
So, my questions are:
After setting up the VPS with all rails dependencies, where do I store my codebase? The root directory of the VPS or some specific locations e.g. www/ or public/?
Should I upload the whole rails app folder or just part of it? I have paperclip in my rails app, and paperclip creates a system/ directory in the public/ folder, so should I upload system/?
In Capistrano 3, there is a repo_url field, I know they support file://, https://, ssh://, or svn+ssh://, but most of the articles about capistrano put github repositories into that. However, I do not have such a github repo. What should I input then?
Thank you for your attention.
Answers to the specific questions raised:
After setting up the VPS with all rails dependencies, where do I store
my codebase? The root directory of the VPS or some specific locations
e.g. www/ or public/?
It will be deployed to the folder pointed by :deploy_to parameter. If not specified, :deploy_to defaults to /var/www/#{fetch(:application) See: https://github.com/capistrano/capistrano/blob/05f63f5f333bb261f2a4c4497174361c48143252/lib/capistrano/defaults.rb#L3
Should I upload the whole rails app folder or just part of it? I have
paperclip in my rails app, and paperclip creates a system/ directory
in the public/ folder, so should I upload system/?
Paperclip system folder is specific to the environment; each environment (development, production,...) will have its own system folder which will store the files uploaded on that specific environment. This folder should not be part of the code being deployed.
The recommended way of handing such folders is the keep them in a shared folder on the server, and create symlinks in the current version of the code so that the same folder is used for storing/retrieving attachments. See Section 3. Update custom links section in http://robmclarty.com/blog/how-to-deploy-a-rails-4-app-with-git-and-capistrano for more details about this.
As mentioned there, the same applies to config/database.yml file, and any other file containing environment specific configurations.
In Capistrano 3, there is a repo_url field, I know they support
file://, https://, ssh://, or svn+ssh://, but most of the articles
about capistrano put github repositories into that. However, I do not
have such a github repo. What should I input then?
Depends on where the code you are deploying is stored. If it is in a local folder, use the file::// format to specify where the files are located.
You can set up your own private git server, then in deploy.rb you can put something like
set :repo_url, 'ssh://user#server_ip/path/to/your_git_repo.git'
When you commit your changes to the git repo, you do not have to upload the app to the server. Capistrano will upload the app for you when you deploy.
where do i put my code base? This is determined by what you put in deploy.rb e.g
set :deploy_to, '/path/to/my_codebase'
Whether to upload the /system directory will depend on whether you want the paperclip images on your version control. If not you can add the directory to gitignore. Here is a tutorial on how to deploy on ubuntu 14.04 passenger and NGINX. if you are not using Passenger and Nginx you can skip to how to configure capistrano and make adjustments depending on your setup.
EDIT
You need to install git on your development machine and set up a git server on your VPS as explained on the link above, add your remote server to your local machine using
git remote add origin <server>
where 'server' is the url to your git repo in the VPS e.g.
ssh://VPS_user#VPS_ip/path/to/your_git_repo.git
Now when you commit and push your changes to the server, capistrano will deploy the latest version on your git server.
Here is a link with a guide on how to get started with git

Maintain database.yml on server

I have a Rails 4 app version controlled with git.
I would like to have a version of database.yml on my server that never changes. What's the best way to allow me to continue to edit this file locally, without changing the remote database.yml file?
You should include your local version of database.yml in .gitignore, so that it's not in the repository and won't change with subsequent deployments.
For instance, in your application root, create a ".gitignore" file and add the following in:
config/database.yml
You can also hide entire directories:
config/*
Basic shell wildcard syntax will work.
*.sql
Etc.
Take it out of version control, it shouldn't be there anyway.
We don't track our config/database.yml in version control (we do track a sample file so it's easier to get setup on new development machines). Our deployment script symlinks in a custom database.yml that's stored in the application user's home directory with permissions set to "600". This way the app user is the only user that can see the database password, and we don't have to do anything manual on deploy.
move database.yml to some secure folder, like /etc/config/database.yml and then create symlink
of that file with rails database.yml after deployment but before starting server.

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?

How to make cap deploy link my vendors folder?

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.

Ruby on Rails integration with Heroku/Engine Yard/similar services

I have a Ruby on Rails project that I've deployed to a PaaS service via GitHub. The Git repo is structured like so:
/ (root)
README
some random files here
src (directory)
a_folder
another_folder
my_rails_app
app (directory)
config (directory)
config.ru
db (directory)
...
Gemfile
...
Rakefile
README
...
As you can see, the Rails app is two directories underneath the root. I suppose I could move it to one file underneath root if necessary, but I definitely need to have other non-Rails files tracked under version control.
But since my Rails app isn't at the root, I'm having trouble using Engine Yard, Heroku, etc... they don't know where to find the Rakefile. I tried creating a Rakefile (https://gist.github.com/245400) and placing it at the root and src directories but it still doesn't work.
Do you know what's going on here or how to fix it?
(As requested ;-D)
If you want to deploy on Heroku/Engine Yard, etc. you might just want to put all those "other folders" within the app directory (e.g. in a folder called supporting_documents or something).
Then you can have those docs under source control AND deploy on Heroku. Also, with Heroku, you'll be able to add those additional documents to the slugignore file (http://devcenter.heroku.com/articles/slug-compiler) so they don't get compiled in the slug.

Resources