How to add pre-requisites for a certain capistrano task - capistrano

I would like to add cap deploy:setup as a pre-requisite for cap deploy task. How should I do this.

Add the following line to your deploy.rb
before 'deploy:update', 'deploy:setup'

Related

I want to skip the deployment of same versions of azure functions during deploying

While deploying, I want the pipeline to skip the same versions of azure function app. How to go ahead for this POC. Any suggestions would help.
Should I try with run once deployment? or I need to make some changes in the build code?
You can achieve this by adding a bash script task.
Add bash script task to check if there is a difference using git diff. If there is, assign a variable to TRUE.
While deploying, add condition to your job. If TRUE, let it deploy. If not, it will pass.

How to validate Ansible playbook from azure yaml build file?

How can we validate the Ansible Playbook from yaml build file ? Yamllint ?
Yamlint is installed in Ubuntu and Linux Azure agents as stated here
So you can run yamlint inside a bash task so as to check your yml files. Choose whatever parameters that suit you.
You can run this pipeline as a build validation, so that no branch is merged into main without validation.

To do certain action after deployment

I am using capifony (it is capistrano for symfony) to deply.
I have to do some work after deployment such as changing access rights for some directories.
chmod 0777 test
For now I am doing this by manual operation.
Could I include this in my capifony deploy.rb?
Im not sure about capifony but if you put something like after 'deploy', 'sometask' in your capistrano deploy.rb file it is ran after deploy.
Here is the list of all the Capistrano deployment tasks. You can do a before or after for any of them.
Looks like this answer might help you.

Capistrano - clean up old releases

Usually when using capistrano, I will go and manually delete old releases from a deployed application. I understand that you can run cap deploy:cleanup but that still leaves 5 releases. Is this it's intended purpose? Is there another way to cleanup old releases to just 1 previous deploy?
You can use the :keep_releases variable to override the default of 5. Check this out.
You could do this automatically by setting this in your deploy.rb
set :keep_releases, 1
after "deploy:update", "deploy:cleanup"
In the past(I don't know exactly which version) this callback was the default, but later the developer decided to leave it to the user to decide. In capistrano 3 it was added back to the default deploy flow.
If you want to delete all releases except the last 3 for example you can run:
cap deploy:cleanup -s keep_releases=3
I had a similar problem. I wanted to keep the 5 releases for normal deployments but needed for certain situations to be able to remove all previous releases.
I was able to do this with a custom task. Create a file lib/capistrano/tasks/cleanup.rake and add the following code.
desc "Remove all but the last release"
task :cleanup_all do
set :keep_releases, 1
invoke "deploy:cleanup"
end
To run use bundle exec cap staging cleanup_all or cap staging cleanup_all

How do you roll back to the previously deployed version with capistrano?

I tried using "cap rollback" but I get the following error:
$ cap rollback
the task `rollback' does not exist
Is there some additional setup that I need to do to get rollbacks to work?
Just found the answer here http://github.com/leehambley/railsless-deploy:
cap deploy:rollback
If you're using different environments (e.g. staging, production) using the multistage gem (e.g. you have require 'capistrano/ext/multistage' in your deploy.rb file) then Capistrano defaults to staging. So, to roll back a production environment you would do:
cap production deploy:rollback
and, assuming you've got the defaults set, this would roll back staging:
cap deploy:rollback
Worth knowing if you're using different environments and wondering why it's not working for production.
simple roll back:
$ cap deploy:rollback
rollback to specific version:
$ cap deploy:rollback -s previous_release= [path to previous release under releases folder ]
Actually it is
cap deploy:rollback:code
deploy:rollback may rollback to a previous revision, not necessarily a previously deployed revision.