Changes for page Automating Application Deployment with Capistrano (Overview)
Last modified by Ralf Schuchardt on 2020/11/17 19:23
From version 18.1
edited by David Avendasora
on 2010/11/30 05:51
on 2010/11/30 05:51
Change comment:
Migrated to Confluence 5.3
To version 19.1
edited by Ralf Schuchardt
on 2020/11/17 19:23
on 2020/11/17 19:23
Change comment:
Changed links to the correct site, because the old one is about UK gambling now
Summary
-
Page properties (4 modified, 0 added, 0 removed)
Details
- Page properties
-
- Parent
-
... ... @@ -1,0 +1,1 @@ 1 +Deployment - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki.a vendasora1 +XWiki.ralf_schuchardt - Tags
-
... ... @@ -1,0 +1,1 @@ 1 +deployment - Content
-
... ... @@ -2,10 +2,9 @@ 2 2 3 3 = How to install Capistrano = 4 4 5 -Here is the official Capistrano installation instructon page: [[http:~~/~~/ www.capify.org/install>>url:http://www.capify.org/install||rel="nofollow"shape="rect"class="external-link"]]. On Leopard all you need to do is to run the following command with root privileges:5 +Here is the official Capistrano installation instruction page: [[https:~~/~~/capistranorb.com/documentation/getting-started/installation/>>url:https://capistranorb.com/documentation/getting-started/installation/||shape="rect"]]. On Leopard all you need to do is to run the following command with root privileges: 6 6 7 7 {{noformat}} 8 - 9 9 gem install -y capistrano 10 10 11 11 {{/noformat}} ... ... @@ -14,7 +14,7 @@ 14 14 15 15 = Must-read article about Capistrano = 16 16 17 -Basics of using Capistrano are well described on its official site: www.capify.org/getting-started/basics>>url:http://www.capify.org/getting-started/basics||rel="nofollow"shape="rect"class="external-link"]]16 +Basics of using Capistrano are well described on its official site: [[https:~~/~~/capistranorb.com>>url:https://capistranorb.com||shape="rect"]] 18 18 19 19 = Writing simple deployment recipe = 20 20 ... ... @@ -29,7 +29,6 @@ 29 29 So let's start our recipe file: 30 30 31 31 {{code}} 32 - 33 33 task :deploy, roles => :app do 34 34 end 35 35 ... ... @@ -38,7 +38,6 @@ 38 38 This is the empty definition of task "deploy" that will run on application servers (see, roles :app). We need to define the :app role in order to make the recipe usable: 39 39 40 40 {{code}} 41 - 42 42 role :app, "localhost" 43 43 task :deploy, roles => :app do 44 44 end ... ... @@ -48,7 +48,6 @@ 48 48 Ok - this is not much, but at least something. Capistrano recipes are executed using "cap" command. So now you should be able to execute the following: 49 49 50 50 {{noformat}} 51 - 52 52 cap -f BugTracker.cap deploy 53 53 54 54 {{/noformat}} ... ... @@ -56,7 +56,6 @@ 56 56 The output should be: 57 57 58 58 {{noformat}} 59 - 60 60 * executing `deploy' 61 61 62 62 {{/noformat}} ... ... @@ -76,7 +76,6 @@ 76 76 So the code will be: 77 77 78 78 {{code}} 79 - 80 80 system "tar -C build -czvf BugTracker.woa.tar.gz BugTracker.woa" 81 81 raise "failed to create an archive" unless $?.exitstatus == 0 82 82 ... ... @@ -92,7 +92,6 @@ 92 92 Here's how it can be done: 93 93 94 94 {{code}} 95 - 96 96 upload "BugTracker.woa.tar.gz", "/tmp/BugTracker.woa.tar.gz" 97 97 98 98 {{/code}} ... ... @@ -104,7 +104,6 @@ 104 104 This will look like this: 105 105 106 106 {{code}} 107 - 108 108 run "rm -rf /Library/WebObjects/Applications/BugTracker.woa" 109 109 110 110 {{/code}} ... ... @@ -116,7 +116,6 @@ 116 116 Nothing new in this code: 117 117 118 118 {{code}} 119 - 120 120 run "tar -C /Library/WebObjects/Applications -xzvf /tmp/BugTracker.woa.tar.gz" 121 121 122 122 {{/code}} ... ... @@ -124,7 +124,6 @@ 124 124 So, right now we have the following deployment script: 125 125 126 126 {{code}} 127 - 128 128 role :app, "localhost" 129 129 task :deploy, roles => :app do 130 130 # creating BugTracker.woa.tar.gz ... ... @@ -150,7 +150,6 @@ 150 150 Let's write a cleanup task in order not to leave tar.gz archives both on our local machine and on remote servers. The task can look like this: 151 151 152 152 {{code}} 153 - 154 154 task :cleanup, roles => :app do 155 155 FileUtils.rm_f "BugTracker.woa.tar.gz" 156 156 ... ... @@ -163,7 +163,6 @@ 163 163 Now we can check that :cleanup task actually works by executing the following command: 164 164 165 165 {{noformat}} 166 - 167 167 cap -f BugTracker.cap cleanup 168 168 169 169 {{/noformat}} ... ... @@ -171,7 +171,6 @@ 171 171 It's great to have a cleanup task, but it would be even better if it would run after the deployment. Capistrano has a "hooks" feature that will help us with that: 172 172 173 173 {{code}} 174 - 175 175 after :deploy, :cleanup 176 176 177 177 {{/code}} ... ... @@ -184,10 +184,10 @@ 184 184 185 185 {{noformat}} 186 186 set <variable name>, <variable value> - this commands says for itself. Some examples: 187 -{{/noformat}} 188 188 189 -{{ code}}175 +{{/noformat}} 190 190 177 +{{code}} 191 191 set "var1", "some data" 192 192 set :var2, 10 193 193 ... ... @@ -196,7 +196,6 @@ 196 196 Note also that you can use the identifiers starting with ":" as variable names. This is the ruby way of specifying unique identifiers (called symbols in ruby). Using symbols is a bit faster than using strings, besides you can easily see identifiers in your code, as they won't be quoted - and will not look like string literals. Anyway these calls are absolutely equal: 197 197 198 198 {{code}} 199 - 200 200 set :var1, "some data" 201 201 set "var1", "some data" 202 202 ... ... @@ -205,7 +205,6 @@ 205 205 After the variable is set, you can use it in string literals using in the traditional ruby way: 206 206 207 207 {{code}} 208 - 209 209 run "echo #{var1}" 210 210 run "echo #{var2}" 211 211 ... ... @@ -214,7 +214,6 @@ 214 214 So let's generalize our script with some variables usage: 215 215 216 216 {{code}} 217 - 218 218 role :app, "localhost" 219 219 220 220 set :app_name, "BugTracker.woa"