In Capistrano, both stages load when I specify a non-default stage - capistrano

I have a short multistage capistrano script that specifies a default stage (set :default_stage, :staging), but I find that when I specify another stage on the command line (e.g. cap production deploy), both the staging and production tasks are run:
$ cap production deploy
triggering load callbacks
* 2013-06-19 06:38:34 executing `staging'
* 2013-06-19 06:38:34 executing `production'
As a consequence, the deployment process looks for the scm in the location specified by staging.rb, which is a local repository -- so it doesn't exist for the production server, and my deployment fails.
Can I provide a default stage in my deploy script but not have it loaded when I specify another stage on the command line?
You can see my deploy files here:
deploy.rb
set :stages, [:staging, :production]
set :default_stage, :staging
require 'capistrano/ext/multistage'
set :repository, "myrepo"
set :scm, :git
set :scm_user, "deploy"
set :user, "deploy"
set (:deploy_to) {"/var/www/clu2/#{application}/"}
set :use_sudo, false
default_run_options[:pty] = true
production.rb
set :application, "production"
set :rails_env, 'production'
set :deploy_to, "/var/www/myapp/"
set :branch, 'develop'
role :app, 'trustedquote.com'
role :web, 'trustedquote.com'
role :db, 'trustedquote.com', :primary => true
staging.rb
set :application, "staging"
set :rails_env, 'production'
set :repository, "file:///git/myrepo.git"
set :local_repository, "file://."
set :branch, 'develop'
role :app, 'mylocation'
role :web, 'mylocation'
role :db, 'mylocation', :primary => true

Thanks to #CDub for his input.
I changed the stage names in deploy.rb from symbols to strings, and that made the difference:
set :stages, %w[staging production]
set :default_stage, 'staging'

Related

Rundeck SSH Execution

We've setup Rundeck community but have some questions regarding SSH execution.
From what I can see it looks like the user who executes the job is configured at the project level and there is no way to change that at a per job per level.
We want to be able to login to Rundeck using our AD credentials (currently working) and run jobs as our individual user id's, is this possible or not?
Thanks
It's possible to use a job level authentication in Rundeck, and it's possible to use the user name as an SSH user (of course the SSH server must be configured with that user to access it).
I made a XML entry node example:
<node name="node00"
description="Node 00"
tags="mytag"
hostname="192.168.33.20"
osArch="amd64"
osFamily="unix"
osName="Linux"
osVersion="3.10.0-1062.4.1.el7.x86_64"
username="${job.username}"
ssh-authentication="password"
ssh-password-option="option.sshPassword1"/>
If you check carefully, you can see the username attribute is set with ${job.username}, this is a context variable that gets the current username (from, LDAP, AD or realm.properties file), you can see all Rundeck context variables here.
This example uses a secure option to pass the password and achieve the SSH authentication, this option is called sshPassword1 (see the ssh-password-option attribute).
Now the job definition example in YAML format:
- defaultTab: nodes
description: ''
executionEnabled: true
id: b188c66c-c057-4bb7-98bf-7c84632bc144
loglevel: INFO
name: Whoami
nodeFilterEditable: false
nodefilters:
dispatch:
excludePrecedence: true
keepgoing: false
rankOrder: ascending
successOnEmptyNodeFilter: false
threadcount: '1'
filter: 'name: node00'
nodesSelectedByDefault: true
options:
- name: sshPassword1
secure: true
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: whoami
keepgoing: false
strategy: node-first
uuid: b188c66c-c057-4bb7-98bf-7c84632bc144

How to upgrade HAProxy on OpsWorks

We are using an AWS OpsWorks stack with Chef Version 11.10. with the default HAProxy Layer. We would like to upgrade the HAProxy to the latest version 1.6-stable (from the default 1.4-stable).
There seems to be a dedicated PPA for our Ubuntu version.
But where can we make OpsWorks use this PPA to install HAProxy?
In the default cookbook there is a default attributes file that has the following lines:
default[:haproxy][:version] = '1.4.22'
default[:haproxy][:patchlevel] = '1'
default[:haproxy][:rpm] = "haproxy-#{node[:haproxy][:version]}-#{node[:haproxy][:patchlevel]}.#{rhel_arch}.rpm"
default[:haproxy][:rpm_url] = "#{node[:opsworks_commons][:assets_url]}/packages/#{node[:platform]}/#{node[:platform_version]}/#{node[:haproxy][:rpm]}"
Overwriting the file in our cookbooks and naïvely changing the version number here does not have the desired effect.
We ended up overwriting the recipe haproxy/recipes/default.rb like so:
#Install software-properties-common if not installed
package 'software-properties-common' do
action :install
end
#Add PPA for haproxy 1.6 and update repo
execute "add-ppa-update" do
command "add-apt-repository ppa:vbernat/haproxy-1.6 && apt-get update -y"
action :run
end
package "haproxy" do
retries 3
retry_delay 5
version '1.6.4-3ppa1~trusty'
action :install
end
if platform?('debian','ubuntu')
template '/etc/default/haproxy' do
source 'haproxy-default.erb'
owner 'root'
group 'root'
mode 0644
end
end
include_recipe 'haproxy::service'
template '/etc/haproxy/haproxy.cfg' do
source 'haproxy.cfg.erb'
owner 'root'
group 'root'
mode 0644
notifies :restart, "service[haproxy]"
end
template "/etc/haproxy/server.pem" do
source "server.pem.erb"
owner 'root'
group 'root'
mode 0600
notifies :restart, "service[haproxy]"
end
service 'haproxy' do
action [:enable, :start]
end
Additionally we needed to update the haproxy.conf to work with the new version.
Everything runs beautifully now.

capistrano and ec2 and github - unable to deploy

I am trying to deploy my first webapp to EC2 using capistrano and the repo is on github. But I am facing issues with "cap deploy:cold". The deploy.rb is pasted below. Following are the steps I followed.
1) Logged into ec2 instance using ssh from my local machine. Generated keys using ssh-keygen without any passphrase.
2) Took the contents of id_rsa.pub and copied to the github repo settings deploy keys.
3) Then from my local machine, ran "cap deploy:cold". I get the following error
user1#laptop:~/MyExample$ cap deploy:cold
* 2013-03-01 19:08:06 executing deploy:cold'
* 2013-03-01 19:08:06 executingdeploy:update'
** transaction: start
* 2013-03-01 19:08:06 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.com:user1/MyExample.git HEAD"
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
* [deploy:update_code] rolling back
* executing "rm -rf /var/www/MyExample.com/releases/20130301133835; true"
servers: ["181.73.124.219"]
[181.73.124.219] executing command
command finished in 1186ms
set :application, "MyExample.com"
set :scm, "git"
set :repository, "git#github.com:thisuser/example.git"
default_run_options[:pty] = true
set :user, 'ubuntu'
set :use_sudo, true
set :deploy_to, "/var/www/#{application}"
set :deploy_via, :remote_cache
role :web, "181.73.124.219"
role :app, "181.73.124.219"
role :db, "181.73.124.219", :primary => true
after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
namespace :deploy do
task :bundle_gems do
run "cd #{deploy_to}/current && bundle install vandor/gems"
end
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
What am I missing here? Also any pointers to a URL/blog that can provide detailed steps would help.
Thanks.
I managed to get it working. As seen in the log,
executing locally: "git ls-remote git#github.com:user1/MyExample.git HEAD"
the capistrano is trying to run the above command local machine and not on the server. Running the above command on the terminal also returned the same error - Permission denied (Public Key).
So I had to copy the generated id_rsa and id_rsa.pub from the deploy server to the local machine. And after copying, add it to the ssk keys being used by running "ssh-add /path/to/keys".
After adding those keys, I was able to move ahead.

How to deploy symfony2 - my dev env works but not prod

I have read the cookbook regarding deploying my symfony2 app to production environment. I find that it works great in dev mode, but the prod mode first wouldn't allow signing in (said bad credentials though I signed in with those very credentials in dev mode), and later after an extra run of clearing and warming up the prod cache, I just get http500 from my prod route.
I had a look in the config files and wonder if this has anything to do with it:
config_dev.php:
imports:
- { resource: config.yml }
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
assetic:
use_controller: true
config_prod:
imports:
- { resource: config.yml }
#doctrine:
# orm:
# metadata_cache_driver: apc
# result_cache_driver: apc
# query_cache_driver: apc
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
I also noticed that there is a routing_dev.php but no routing_prod, the prod encironment works great however on my localhost so... ?
In your production environment when you run the app/console cache:warmup command you need to make sure you run it like this: app/console cache:warmup --env=prod --no-debug Also, remember that the command will warmup the cache as the current user, so all files will be owned by the current user and not the web server user (eg: www-data). That is probably why you get a 500 server error. After you warmup the cache run this: chown -R www-data.www-data app/cache/prod (be sure to replace www-data with your web server user.
Make sure your parameters.ini file has any proper configs in place since its common for this file to not be checked in to whatever code repository you might be using. Or (and I've even done this) its possible to simply forget to put parameters from dev into the prod parmeters.ini file.
You'll also need to look in your app/logs/prod.log to see what happens when you attempt to login.

Symfony2 Capifony deployment - Conflicts on a same server

I want to deploy different branchs of a Git repository on a same server.
I've updated app/config/deploy.rb
set :stage_dir, "app/config/deploy"
require "capistrano/ext/multistage"
set :stages, %w(prod stag stag2 stag3)
set :application, "MyApp"
I've created new files in app/config/deploy/
In app/config/deploy/stag.rb :
set :symfony_env_prod, "stag"
set :domain, "stag.example.com"
set :deploy_to, "/var/www/#{domain}"
# Other config
role :web, domain
role :app, domain
role :db, domain, :primary => true
In app/config/deploy/stag2.rb
set :symfony_env_prod, "stag"
set :domain, "stag2.example.com"
set :deploy_to, "/var/www/#{domain}"
# Other config
role :web, domain
role :app, domain
role :db, domain, :primary => true
I also launched cap stag2 deploy:setup.
When I deploy using cap stag deploy, stag.example.com is fine
Then, when I deploy cap stag2 deploy,stag2.example.com is file but stag.example.com get some changes from stag2. The source files of stag.example.com are correct. I suppose that there is a cache conflict.
Is Capifony able to deploy the same app in a same server properly ?
Edit : sounds similar Capistrano Multistage deploying to wrong directory
I also tried with set :deploy_to, "/var/www/stag2/#{domain}"
You have to use the server parameters instead of :domain.
stag.rb:
server "stag.example.com", :app, :web, :primary => true
stag2.rb:
server "stag2.example.com", :app, :web, :primary => true
Don't use :domain for this stuff.
See the docs.
I tried your solution #Elnur , replacing server by domain, deployment works fine but the problem still occurs...
After more investigation and tests I came up with a solution that seems to work.
I noticed that in app/autoload.php we use APC
$loader = new ApcUniversalClassLoader('xx.');
xx. is the A prefix to create a namespace in APC
http://symfony.com/doc/2.0/components/class_loader.html
I replaced by
$loader = new ApcUniversalClassLoader('xx.stagX');
Then restart Apache and rm -Rf app/cache/*
That seems to solve the problem. I would be surprised if the same APC name space could be used by 2 different websites on the same server.
This is the exception stack-trace that we got before, look how we go
from /var/www/stag5.XXXX.com/
to /var/www/stag6.XXXX.com/
#10 /var/www/stag6.XXXX.com/shared/vendor/cg-library/src/CG/Proxy/MethodInvocation.php(58): JMS\SecurityExtraBundle\Security\Authorization\Interception\MethodSecurityInterceptor->intercept(Object(CG\Proxy\MethodInvocation))
#11 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/jms_aop/proxies/St-XxBundle-Manager-XxxManager.php(85): CG\Proxy\MethodInvocation->proceed()
#12 /var/www/stag6.XXXX.com/releases/20121210060841/src/Xx/XxxBundle/Controller/XxxController.php(85): EnhancedProxy_16c750f17d8113ffbee7fc3acdc4b1625ca7410b\__CG__\St\CoreBundle\Manager\TagsManager->findXxxxx(Object(Xx\XxBundle\Entity\Project))
#13 [internal function]: Xx\XxxxxBundle\Controller\XxxxController->getXxxAction(Object(Symfony\Component\HttpFoundation\Request))
#14 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/classes.php(4591): call_user_func_array(Array, Array)
#15 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/classes.php(4555): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#16 /var/www/stag5.XXXX.com/releases/20121210053804/app/cache/stag/classes.php(5537): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/stag5.XXXX.com/releases/20121210053804/app/bootstrap.php.cache(564): Symfony\Bundle\FrameworkBundle\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/stag5.XXXX.com/releases/20121210053804/web/app_stag.php(13): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#19 {main}