Exclude the files to deploy by Capistrano - ruby

I deployed the project by capistrano from git.
There are some files which are stored in git but not want to be copied to deploy server.
in git, file structure.
myapp - mainapp
- somesetting.txt
- _NoWanttoDeploy.txt // I don't want to deploy this file
These are deploy.rb
# config valid for current version and patch releases of Capistrano
lock "~> 3.11.2"
set :application, "myapp"
set :repo_url, "ssh://app#git.example.com/~/myGit/myapp.git"
set :branch, 'master'
set :deploy_to, "/var/www/html/myapp"
set :linked_dirs, fetch(:linked_dirs, []).push('static')
set :keep_releases, 3
How can I set???

how about copy_exclude?
set :copy_exclude, "_NoWanttoDeploy.txt"

Related

Mina Deploy uses wrong user

I got some issue with the gem 'mina'. If I do set :user, 'username', he tries to connect to the server via Username#xxx.... wich is not working if the user is not existing. My PC is name Username. So mina setup and mina deploy are not working.
Does someone know a solution?.
Thanks
Best regards
Matze
EDIT:
Gemfile:
gem 'mina'
After that I run bundle install and mina init
deploy.rb:
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
require 'mina/rvm' # for rvm support. (https://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
# branch - Branch name to deploy. (needed by mina/git)
set :user, "user"
set :application_name, 'appname'
set :domain, 'xx.xxx.xxx.xxx'
set :deploy_to, '/var/www/user/appname'
set :repository, 'user#xx.xxx.xxx.xxx:/home/user/git/appname.git'
set :branch, 'master'
# Optional settings:
# set :user, 'user' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# set :forward_agent, true # SSH forward_agent.
# Shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step.
# Some plugins already add folders to shared_dirs like `mina/rails` add `public/assets`, `vendor/bundle` and many more
# run `mina -d` to see all folders and files already included in `shared_dirs` and `shared_files`
# set :shared_dirs, fetch(:shared_dirs, []).push('public/assets')
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')
# This task is the environment that is loaded for all remote run commands, such as
# `mina deploy` or `mina rake`.
task :remote_environment do
# If you're using rbenv, use this to load the rbenv environment.
# Be sure to commit your .ruby-version or .rbenv-version to your repository.
# invoke :'rbenv:load'
# For those using RVM, use this to load an RVM version#gemset.
# invoke :'rvm:use', 'ruby-1.9.3-p125#default'
end
# Put any custom commands you need to run at setup
# All paths in `shared_dirs` and `shared_paths` will be created on their own.
task :setup do
# command %{rbenv install 2.3.0 --skip-existing}
end
desc "Deploys the current version to the server."
task :deploy do
# uncomment this line to make sure you pushed your local branch to the remote origin
# invoke :'git:ensure_pushed'
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
on :launch do
in_path(fetch(:current_path)) do
command %{mkdir -p tmp/}
command %{touch tmp/restart.txt}
end
end
end
# you can use `run :local` to run tasks on local machine before of after the deploy scripts
# run(:local){ say 'done' }
end
# For help in making your deploy script, see the Mina documentation:
#
# - https://github.com/mina-deploy/mina/tree/master/docs
set :execution_mode, :exec if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
When I run now mina setup he print that:
$ mina setup
User#xx.xxx.xxx.xxx's password:
SSH Auth key working fine and git working fine he just puts User instead of user before the ip, what is not working because the user just exists with small letter. But my working machine is named User.

Symfony: generate assetics

I use Capistrano and Symfony plugin ( https://github.com/capistrano/symfony ) for my deployment (I have Symfony 2.7). But, my CSS is wrong. I think assetic is not generated.
I used default deploy.rb and added ACL commands for chmod.
# config valid only for current version of Capistrano
lock '3.5.0'
set :application, 'Dometech.fr'
set :repo_url, 'ssh://git#37.187.154.125:9325/var/www/depotsGit/dometech.git/'
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/var/www/dev/Dometech'
set :symfony_directory_structure, 2
namespace :deploy do
after "deploy:updated" , "composer:install"
# Clear ACL only before switching version
before "deploy:publishing" , "symfony:fixes_acl"
end
namespace :symfony do
desc "Add ACL on cache directory"
task :fixes_acl do
on roles :web do
execute :setfacl, "-R -m u:www-data:rwX #{fetch(:release_path)}/app/cache #{fetch(:release_path)}/app/logs"
end
end
end
Can you help me for assetic?
Apparently, the Symfony Capistrano plugin removed Assetic support, so you should add a task to your deploy.rb to take care of it. You can probably just take what was removed:
set :assetic_dump_flags, ''
namespace :assetic do
desc "Dump assets with Assetic"
task :dump do
on release_roles(:all) do
symfony_console "assetic:dump", fetch(:assetic_dump_flags)
end
end
end
and make sure it’s invoked with something like:
after 'deploy:updated', 'symfony:assetic:dump'

Capistrano: No such file or directory

I'm really new to Capistrano and am having a tough time getting it setup. I'm using a Windows local machine, Linux server and BitBucket for my git repo. When I run cap deploy I get the following error:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railsless-deploy-1.1.2/lib/railsless-deploy.rb:98:in ``': No such file or directory - git ls-remote git#bitbucket.org:je3415/captest.git HEAD
(Errno::ENOENT)
When I SSH into the server I'm able to run git ls-remote git#bitbucket.org:je3415/captest.git HEAD without any problem. I also tried creating a public key with and without a passphrase. That made no difference as well.
Any suggestions would be really appreciated. Thanks.
Edit:
Here is the contents of my capfile:
require 'railsless-deploy'
load 'config/deploy'
And the beginning of my deploy.rb file looks like this:
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
set :application, "captest" # TODO
set :repository, "git#bitbucket.org:je3415/captest.git" # TODO
set :scm, :git
set :use_sudo, false
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :deploy_via, :remote_cache
set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules"]
set :git_enable_submodules, 1
set :wp_multisite, 0 # TODO Set to 1 if multisite
I was able to solve this by adding the location of my Git binaries to the Windows PATH environment variable. Thanks to #maksim for posting the solution at https://stackoverflow.com/a/8978686/868082.

Argument error while deploying rails app via capistrano to bluehost

I have build a sample app using rails and trying to deploy it using capistrano to bluehost.
But I am failing to do so. I followed the instructions mentioned in this http://vasil-y.com/2012/08/21/rails-capistrano-git-bluehost/
This is the contents of my config/deploy.rb:
require 'bundler/capistrano'
set :application, "rails_scaffold"
# BlueHost SSH user
set :user, "username"
# App Domain
set :domain, "example.com"
# We don't need sudo on BlueHost
set :use_sudo, false
# git is our SCM
set :scm, :git
# master is our default git branch
set :branch, "master"
# Use local git repository
set :repository, "#{domain}:/home/#{user}/rails_apps/#{application}"
set :local_repository, "."
# Checkout, compress and send a local copy
set deploy_via, :copy
set deploy_to, "/home/#{user}/rails_apps/#{application}"
# We have all components of the app on the same server
server domain, :app, :web, :db, :primary => true
namespace :deploy do
task :start do ; end
task :stop do ; end
# Touch tmp/restart.txt to tell Phusion Passenger about new version
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path, 'tmp', 'restart.txt')}"
end
end
# Clean-up old releases
after "deploy:restart", "deploy:cleanup"
But when I run the cap deploy:setup command, I get the following error:
/home/swaroop/.rvm/gems/ruby-1.9.3-p362/gems/capistrano-2.14.2/lib/capistrano/configuration/variables.rb:22:in `set': invalid variable `/u/apps/rails_scaffold' (variables must begin with an underscore, or a lower-case letter) (ArgumentError)
It says the application name must begin with an underscore or lowercase alphabets. And my application name looks like it is valid.
What am I doin wrong here?
Thank You
A couple of your set calls have arguments which are not symbols:
set deploy_via, :copy
set deploy_to, "/home/#{user}/rails_apps/#{application}"
Those should be:
set :deploy_via, :copy
set :deploy_to, "/home/#{user}/rails_apps/#{application}"
(Note the colons before deploy_via and deploy_to)
You can see why it might look related to your :application variable if we inspect what is happening in the line containing :deploy_to: it first calls the deploy_to method (since you're missing the colon, it looks like a method call), and deploy_to defaults to "/u/apps/#{application}" in the Capistrano source code:
_cset(:deploy_to) { "/u/apps/#{application}" }
So really, your code is effectively trying trying to run this:
set "/u/apps/#{application}", "/home/#{user}/rails_apps/#{application}"
but "/u/apps/#{application}" is not a valid variable name in Capistrano. Adding colons to those lines should fix it.

Ubuntu 10.04 Rails deploy - Why is capistrano failing to deploy to server?

I am trying to deploy with capistrano. RVM is installed on the server and the ruby version is 1.93p385.
Here is the log of cap production deploy:
http://pastie.org/private/vs336nrgejpwdkuelufnma#
Why is capistrano failing to deploy?
Here is the deploy file:
require "rvm/capistrano"
require "bundler/capistrano"
set :rvm_ruby_string, "1.9.3-p385"
set :rvm_type, :user #Should the user by the username?
require "capistrano/ext/multistage"
set :http_server, :apache2
set :rake, "#{rake} --trace"
set :application, "app"
set :user, "myuser" # The server's user for deploys
set :ruby_version, "1.9.3-p385"
set :scm, "git"
set :repository, "my git repo here"
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, true
default_run_options[:pty] = true # Must be set for the password prompt from git to work
ssh_options[:forward_agent] = true
set :nodejs, true
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
The server is an Ubuntu 10.04 LTS
** [out :: server] No such file or directory - /var/www/app/releases/20130216170229/config/database.yml
Does this path exist on the server? You might need to create the /var/www/app/releases portion by hand, which capistrano will then deploy into.
It is a common pattern to .gitignore database.yml for capistrano deployment. The database config then resides in <:deploy_to>/shared/config/. The you use this cap task to symlink the db config in your release directory:
namespace :deploy do
task :start do ; end
task :stop do ; end
desc "Symlink shared folders on each deployment"
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
before "deploy:assets:precompile", "deploy:symlink_shared"

Resources