1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

fix syntax highlighting

This commit is contained in:
Thomas Kriechbaumer 2015-01-19 10:07:58 +00:00
parent c2e80bb804
commit 9d77662dd8
7 changed files with 25 additions and 24 deletions

View file

@ -3,6 +3,7 @@ title: Capistrano in ruby script
layout: default
---
Instead of building a config folder and deploy, you may want to programmatically set everything in a single ruby script. This could be done as follows:
{% highlight ruby %}
require 'capistrano/all'

View file

@ -11,13 +11,13 @@ Execute arbitrary remote commands, to use this simply add
`require 'capistrano/console'` which will add the necessary tasks to your
environment:
``` sh
{% highlight bash %}
$ bundle exec cap staging console
```
{% endhighlight %}
Then, after setting up the server connections, this is how that might look:
``` sh
{% highlight bash %}
$ bundle exec cap production console
capistrano console - enter command to execute on production
production> uptime
@ -30,4 +30,4 @@ production> who
DEBUG [9ce34809] Command: /usr/bin/env who
DEBUG [9ce34809] leehambley pts/0 2013-06-13 17:11 (port-11262.pppoe.wtnet.de)
INFO [9ce34809] Finished in 0.420 seconds command successful.
```
{% endhighlight %}

View file

@ -5,7 +5,7 @@ layout: default
Where calling on the same task name, executed in order of inclusion
``` ruby
{% highlight ruby %}
# call an existing task
before :starting, :ensure_user
@ -20,12 +20,12 @@ end
after :finishing, :notify do
#
end
```
{% endhighlight %}
If it makes sense for your use case (often, that means *generating a file*)
the Rake prerequisite mechanism can be used:
``` ruby
{% highlight ruby %}
desc "Create Important File"
file 'important.txt' do |t|
sh "touch #{t.name}"
@ -36,11 +36,11 @@ task :upload => 'important.txt' do |t|
upload!(t.prerequisites.first, '/tmp')
end
end
```
{% endhighlight %}
The final way to call out to other tasks is to simply `invoke()` them:
``` ruby
{% highlight ruby %}
namespace :example do
task :one do
on roles(:all) { info "One" }
@ -50,6 +50,6 @@ namespace :example do
on roles(:all) { info "Two" }
end
end
```
{% endhighlight %}
This method is widely used.

View file

@ -5,7 +5,7 @@ layout: default
Local tasks can be run by replacing `on` with `run_locally`:
```ruby
{% highlight ruby %}
desc 'Notify service of deployment'
task :notify do
run_locally do
@ -14,22 +14,22 @@ task :notify do
end
end
end
```
{% endhighlight %}
Of course, you can always just use standard ruby syntax to run things locally:
```ruby
{% highlight ruby %}
desc 'Notify service of deployment'
task :notify do
%x('RAILS_ENV=development bundle exec rake "service:notify"')
end
```
{% endhighlight %}
Alternatively you could use the rake syntax:
```ruby
{% highlight ruby %}
desc "Notify service of deployment"
task :notify do
sh 'RAILS_ENV=development bundle exec rake "service:notify"'
end
```
{% endhighlight %}

View file

@ -5,7 +5,7 @@ layout: default
Password authentication can be done via `set` and `ask` in your deploy environment file (e.g.: config/deploy/production.rb)
```ruby
{% highlight ruby %}
set :password, ask('Server password', nil)
server 'server.domain.com', user: 'ssh_user_name', port: 22, password: fetch(:password), roles: %w{web app db}
```
{% endhighlight %}

View file

@ -1,4 +1,4 @@
``` ruby
{% highlight ruby %}
server 'example.com', roles: [:web, :app]
server 'example.org', roles: [:db, :workers]
desc "Report Uptimes"
@ -8,7 +8,7 @@ task :uptime do
info "Host #{host} (#{host.roles.to_a.join(', ')}):\t#{capture(:uptime)}"
end
end
```
{% endhighlight %}
**Note**:

View file

@ -3,7 +3,7 @@ title: User Input
layout: default
---
``` ruby
{% highlight ruby %}
desc "Ask about breakfast"
task :breakfast do
ask(:breakfast, "pancakes")
@ -11,12 +11,12 @@ task :breakfast do
execute "echo \"$(whoami) wants #{fetch(:breakfast)} for breakfast!\""
end
end
```
{% endhighlight %}
Perfect, who needs telephones.
When using `ask` to get user input, you can pass `echo: false` to prevent the input from being displayed:
```ruby
{% highlight ruby %}
ask(:database_password, "default", echo: false)
```
{% endhighlight %}