For a while I had the status: 1 with Capistrano and now got it working. I deployed and things were going well but then it got stuck at this below.
Here is my deploy.rb file:
# config valid only for Capistrano 3.1
lock '3.2.1'
set :application, 'Joggleio'
set :repo_url, 'git#github.com:xxxxxx/xxxxxx.io.git'
# set :repo_url, 'git://github.com:xxxxxxxx/xxxxxxx.io.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/tristan/xxxxxxx'
# Default value for :scm is :git
set :scm, :git
set :branch, "production"
# Default value for :format is :pretty
set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, true
# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
# User
set :user, "tristan"
set :use_sudo, false
# Rails env
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { :forward_agent => true}
set :default_stage, "production"
# server "xx.xxx.xxx.xx", :app, :web, :db, :primary => true
namespace :deploy do
# before "deploy", "deploy:stop_dj"
desc 'Restart application'
task :restart do
sudo "service nginx restart"
run "RAILS_ENV=production rake assets:precompile"
run "RAILS_ENV=production bin/delayed_job -n2 restart"
# on roles(:app), in: :sequence, wait: 5 do
# # Your restart mechanism here, for example:
# # execute :touch, release_path.join('tmp/restart.txt')
# end
end
after :publishing, :restart
after :restart, "deploy:cleanup"
end
Not sure what is going on that's wrong
Just before that I get this:
Command: cd /home/tristan/xxxx/repo && ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/xxxxx/git-ssh.sh /usr/bin/env git archive production | tar -x -C /home/tristan/xxxxx/releases/20140611234421 )
DEBUG[0dbe45c7] fatal: Not a valid object name
DEBUG[0dbe45c7] tar: This does not look like a tar archive
DEBUG[0dbe45c7] tar: Exiting with failure status due to previous errors
Any help is greatly appreciated!!
I just run into same problem. The root cause is the branch you specified is not on the remote git repo yet. I'm using git flow so I specify my branch as develop. after push this branch to remote and deploy again the problem is gone.
Related
I have a rails application that is not rendering assets. It was previously working fine. When I added linked files it not only uploaded the files I specified but also precompiled assets. Even after clobbering all assets and recompiling it fails to render them even though that exist on the box.
error
Caddyfile
mydomain.com {
gzip
log stdout
root /home/deploy/apps/rails-app/current/public
proxy / unix:///home/deploy/apps/rails-app/shared/tmp/sockets/rails-app-puma.sock {
except /assets # this is /public/assets directory
except /solr
transparent
websocket
policy round_robin
}
errors stdout
header / {
Strict-Transport-Security "max-age=31536000"
}
proxy /solr localhost:8983 {
transparent
}
}
deploy.rb
# frozen_string_literal: true
# config valid only for current version of Capistrano
# lock '3.13.0'
# Change these
server '...', port: 2221, roles: %i[web app db], primary: true
set :repo_url, '...'
set :application, '...'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 0
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w[~/.ssh/id_rsa], auth_methods: %w(publickey) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
set :bundle_flags, '--no-cache'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.6.6'
set :rails_env, 'production'
set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
## Defaults:
set :branch, 'master'
set :log_level, :debug
set :keep_releases, 5
## Linked Files & Directories (Default None):
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# set :linked_dirs, %w{data_files}
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
# before :start, :make_dirs
end
namespace :deploy do
desc 'Make sure local git is in sync with remote.'
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts 'WARNING: HEAD is not the same as origin/master'
puts 'Run `git push` to sync changes.'
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke! 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke! 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
I was able to get this working but using the fileserver directive.
https://example.com {
encode zstd gzip
root * /home/deploy/apps/rails-app/current/public
file_server
tls user#email.com
#notStatic {
not file
}
reverse_proxy #notStatic unix//home/deploy/apps/rails-app/shared/tmp/sockets/rails-app-puma.sock
header / {
Strict-Transport-Security "max-age=31536000"
}
}
I am using capistrano for deployment, and for some reason my shared/bin folder is empty, and, well it should contain -rails, rake, bundle, setup, spring. now obviously I did something wrong, but as I am new to capistrano, I have no Idea what it is, because it is in my git repository, and as far as I know it copies the entire thing from the repository. since I am not sure wether it is relavent or not, I will just put everything I changed reguarding the capistrano deployment.
here's my deploy.rb
lock '3.4.0'
# application settings
set :application, 'SomeApplication'
set :user, 'someuser'
#set :repo_url, 'git#bitbucket.org:someapp/someappserver.git'
set :rails_env, 'production'
set :use_sudo, false
set :keep_releases, 5
#git settings
set :scm, :git
set :branch, "master"
set :repo_url, "git#bitbucket.org:someapplication/someapplicationserver.git"
set :deploy_via, :remote_cache
set :rvm_ruby_version, '2.2.1'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"
# dirs we want symlinked to the shared folder
# during deployment
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :pg_database, "someapp_production"
set :pg_user, "someapp_production"
set :pg_ask_for_password, true
namespace :deploy do
task :config_nginx do
pre = File.basename(previous_release)
cur = File.basename(release_path)
run "#{sudo} sed 's/#{pre}/#{cur}/g' /etc/nginx/sites-available/default"
end
task :restart_thin_server do
run "cd #{previous_release}; source $HOME/.bash_profile && thin stop -C thin_config.yml"
run "cd #{release_path}; source $HOME/.bash_profile && thin start -C thin_config.yml"
end
task :restart_nginx do
run "#{sudo} service nginx restart"
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
#
# The capistrano-unicorn-nginx gem handles all this
# for this example
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
here is my deploy/production.rb
# production deployment
set :stage, :production
# use the master branch of the repository
set :branch, "master"
# the user login on the remote server
# used to connect and deploy
set :deploy_user, "someuser"
# the 'full name' of the application
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
# the server(s) to deploy to
server 'someserver.cloudapp.net', user: 'someuser', roles: %w{web app db}, primary: true
# the path to deploy to
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
# set to production for Rails
set :rails_env, :production
and here is my cap file
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# require 'capistrano/passenger'
require 'capistrano/thin'
require 'capistrano/postgresql'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
like #emj365 said
just remove bin form your linked_dirs in config/deploy.rb
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
#gilmishal Kindly check with this link .. capistrano-deploy-configuration
And keep your eye on directory path where i did mistake many a times
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name' # This conf is by default
Hope it will solve your problem
I'm having this weird problem with Capistrano 3. The code it deploys is never updated, unless I delete the repo folder in my app folder on the server. If I delete the repo folder and deploy, it'll update the code.
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'APP_NAME'
set :repo_url, 'REPO'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/home/deployer/apps/APP_NAME'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
# Default value for :format is :pretty
set :format, :pretty
# Default value for :log_level is :debug
set :log_level, :info
# Default value for :pty is false
# set :pty, true
# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
set :use_sudo, false
set :linked_files, ["config/database.yml"]
namespace :deploy do
desc "Start Unicorn"
task :start do
on roles(:app) do
within current_path do
execute :bundle, "exec unicorn_rails -c config/unicorn.rb -D"
end
end
end
desc "Stop Unicorn"
task :stop do
on roles(:app) do
execute "kill -s QUIT `cat #{shared_path}/pids/unicorn.pid`"
end
end
desc "Restart application"
task :restart do
invoke 'deploy:stop'
invoke 'deploy:start'
end
end
Probably a little obvious but did you check the permissions on your server? I would try giving full permissions to any user on the folder I'm trying to deploy to just as a test to see if it goes through, if it does then you know where your problem is.
i am deploying with capistrano and I am strugg;ling to find out why it will not run migrations when I try to deploy the site.
here is the whole error:
WARN [SKIPPING] No Matching Host for /usr/bin/env if test ! -d /home/deploy/forge_staging/releases/20140319132005; then echo "Directory does not exist '/home/deploy/forge_staging/releases/20140319132005'" 1>&2; false; fi
WARN [SKIPPING] No Matching Host for bundle exec rake db:migrate
heres my setup:
deploy.rb
lock '3.1.0'
server "xxx.xxx.xxx.xxx"
set :application, "ForgeAndCo"
set :scm, "git"
set :repo_url, "my-repo"
# set :scm_passphrase, ""
set :user, "deploy"
set :use_sudo, false
set :ssh_options, {
forward_agent: true,
port: 14439
}
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml}
# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
SSHKit.config.command_map[:rake] = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
set :keep_releases, 20
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
unless execute :curl, '-s -k --location localhost | grep "Forge" > /dev/null'
exit 1
end
end
end
after :finishing, "deploy:cleanup"
end
# start new deploy.rb stuff for the beanstalk repo
staging.rb
role :app, %w{deploy#xxx.xxx.xxx.xxx}
role :web, %w{deploy#xxx.xxx.xxx.xxx}
role :db, %w{deploy#xxx.xxx.xxx.xxx}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
# server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
set :stage, :staging
server "xxx.xxx.xxx.xxx", user: "deploy", roles: %w{web app db}
set :deploy_to, "/home/deploy/forge_staging"
set :rails_env, 'staging' # If the environment differs from the stage name
set :migration_role, 'migrator' # Defaults to 'db'
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
Is this an issue with roles?
remove from deploy.rb: (add capistrano-bundler and require it in the Capfile)
server "xxx.xxx.xxx.xxx"
SSHKit.config.command_map[:rake] = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :user, "deploy" # you have it in staging.rb
set :use_sudo, false # not used in cap3
remove from staging.rb:
role :app, %w{deploy#xxx.xxx.xxx.xxx}
role :web, %w{deploy#xxx.xxx.xxx.xxx}
role :db, %w{deploy#xxx.xxx.xxx.xxx}
set :migration_role, 'migrator' # <= this is why you got the error
PS: edit your question and replace the ip with xxx.
Having setup capistrano on my rails app I was deploying okay I then went and changed some css values on my local site. This was fine but then when I went to deploy my site with cap staging deploy it started to do its normal routine tasks just fine but when it came to capistrano's precompile task for assets it failed. I have managed to source where it is going wrong on the capistrano area and thats here:
task :backup_manifest do
on roles(fetch(:assets_roles)) do
within release_path do
execute :cp,
release_path.join('public', fetch(:assets_prefix), 'manifest*'),
release_path.join('assets_manifest_backup')
end
end
end
task :restore_manifest do
on roles(fetch(:assets_roles)) do
within release_path do
source = release_path.join('assets_manifest_backup')
target = capture(:ls, release_path.join('public', fetch(:assets_prefix),
'manifest*')).strip
if test "[[ -f #{source} && -f #{target} ]]"
execute :cp, source, target
else
msg = 'Rails assets manifest file (or backup file) not found.'
warn msg
fail Capistrano::FileNotFound, msg
end
end
end
end
It fails here where you have within release_path do as thats in the stack trace but I do not know why it does that as i have not changed any tasks at all just ccs tweaks.
Here are my deployment settings for capistrano:
deploy.rb
lock '3.1.0'
server "188.226.182.102"
set :application, "ForgeAndCo"
set :scm, "git"
set :repo_url, "git#made-by-mark.beanstalkapp.com:/made-by-mark/forge.git"
# set :scm_passphrase, ""
set :user, "deploy"
set :use_sudo, false
set :ssh_options, {
forward_agent: true,
port: 14439
}
set :assets_prefix, 'prepackaged-assets'
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml}
# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
SSHKit.config.command_map[:rake] = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
set :keep_releases, 20
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
unless execute :curl, '-s -k --location localhost | grep "Forge" > /dev/null'
exit 1
end
end
end
end
after 'deploy:publishing', 'deploy:restart'
deploy/staging.rb
role :app, %w{deploy#188.226.182.102}
role :web, %w{deploy#188.226.182.102}
role :db, %w{deploy#188.226.182.102}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
# server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
set :stage, :staging
server "188.226.182.102", user: "deploy", roles: %w{web app db}
set :deploy_to, "/home/deploy/forge_staging"
set :rails_env, 'staging' # If the environment differs from the stage name
set :migration_role, 'migrator' # Defaults to 'db'
set :assets_roles, [:web, :app] # Defaults to [:web]
set :assets_prefix, 'prepackaged-assets' # Defaults to 'assets' this should match config.assets.prefix in your rails config/application.rb
set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
Does anyone know why it would fail at this task at all?