vlad 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,4 +1,16 @@
1
- == 1.3.1 / 2009-03-06
1
+ === 1.3.2 / 2009-03-16
2
+
3
+ * 3 minor enhancements:
4
+
5
+ * Added 'Deploying Merb with Vlad' by Graham Ashton.
6
+ * Added 'Deploying Sinatra with Vlad' by Graham Ashton.
7
+ * Core update task calls update with the actual revision once again
8
+
9
+ * 1 bug fix:
10
+
11
+ * Fix Git checkout/export methods. (Wilson)
12
+
13
+ === 1.3.1 / 2009-03-06
2
14
 
3
15
  * 4 minor enhancements:
4
16
 
@@ -3,6 +3,8 @@ Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
5
  considerations.txt
6
+ doco/deploying-merb-with-vlad.txt
7
+ doco/deploying-sinatra-with-vlad.txt
6
8
  doco/faq.txt
7
9
  doco/getting_started.txt
8
10
  doco/migration.txt
@@ -0,0 +1,155 @@
1
+ # Deploying Merb with Vlad
2
+
3
+ This tutorial has been adapted from [Deploying Merb with Vlad](http://effectif.com/articles/deploying-merb-with-vlad) by [Graham Ashton](http://effectif.com "Effectif Development").
4
+
5
+ You've built your Merb app, and you want to get it running on your web server. You could use Capistrano, but if you prefer the simple things in life you might find that [Vlad](http://rubyhitsquad.com/Vlad_the_Deployer.html "Vlad the Deployer") is a better fit.
6
+
7
+ This is a Merb version of the [Deploying Sinatra with Vlad](deploying-sinatra-with-vlad "Deploying Sinatra with Vlad") article that I wrote yesterday. There are big similarities to that article, but in this one we also look at how to restart Merb automatically after the code has been deployed.
8
+
9
+ ## Creating a sample application
10
+
11
+ Let's start by making ourselves a test app:
12
+
13
+ $ merb-gen flat hi
14
+ $ cd hi
15
+
16
+ We can check that the app works locally by running it...
17
+
18
+ $ merb
19
+
20
+ ...and then opening [http://localhost:4000](http://localhost:4000) in a web browser.
21
+
22
+ We need to create a `public` directory too (because this is a flat app I don't already have one), as Vlad assumes that we have a `public` directory for our static assets. I'm also going to make an empty CSS file so that the directory doesn't get ignored by Git:
23
+
24
+ $ mkdir public
25
+ $ touch public/master.css
26
+
27
+ We'll deploy our application from version control. I'm using Git, but you can use any system that Vlad supports; just check your files into a repository that will be accessible from your web server.
28
+
29
+ ## Configuring Vlad
30
+
31
+ Okay, we're ready for Vlad. It's a Ruby gem, so it's very easy to install:
32
+
33
+ $ sudo gem install vlad
34
+ Successfully installed vlad-1.2.0
35
+ 1 gem installed
36
+ Installing ri documentation for vlad-1.2.0...
37
+ Installing RDoc documentation for vlad-1.2.0...
38
+
39
+ There's no need to install Vlad on your server, just your workstation.
40
+
41
+ You access Vlad's functionality through Rake tasks. Add the following code to a file called `lib/tasks/vlad.rake` (you may have to make the directory first, but Merb will automatically find it):
42
+
43
+ begin
44
+ $TESTING = true # workaround a conflict between DataMapper and Vlad
45
+ require "vlad"
46
+ Vlad.load(:app => nil, :scm => "git")
47
+ rescue LoadError
48
+ # do nothing
49
+ end
50
+
51
+ Note that we've told Vlad that we intend to use Git (subversion is the default). We've set `:app` to `nil` as Vlad assumes that we'll run our application with `mongrel_rails` (it seems to think everybody who uses Mongrel is using Rails). Merb has support for clusters built in, so we'll setup some simple replacements later.
52
+
53
+ If you run `rake -T` now you should see a bunch of vlad tasks that are available to you. You can't run them yet; you need to configure Vlad. Create a `config/deploy.rb` file in your editor and set the following variables in it:
54
+
55
+ set :application, "hi"
56
+ set :repository, "ssh://your.git.server/path/to/project/hi.git"
57
+ set :domain, "your.web.server"
58
+ set :deploy_to, "/var/apps/#{application}"
59
+
60
+ Make sure that `:repository` correctly references your source control system, and that `:domain` is set to the hostname of your server.
61
+
62
+ I won't be able to create any directories under the `/var/apps` directory (I'm going to run vlad using my own username in this example), so I need to login to my server and make sure that I can create files in the `hi` directory:
63
+
64
+ $ ssh your.web.server
65
+ $ sudo mkdir -p /var/apps/hi
66
+ $ sudo chown yourusername /var/apps/hi
67
+
68
+ Now you can try running Vlad, to create all the directories necessary to serve your project. Back on your workstation, type:
69
+
70
+ $ rake vlad:setup
71
+
72
+ You should find that some directories have been created within `/var/apps/hi` on your server.
73
+
74
+ Let's trying deploying some code:
75
+
76
+ $ rake vlad:update
77
+ (in /Users/graham/data/effectif/projects/hi)
78
+ Initialized empty Git repository in /var/apps/hi/scm/repo/.git/
79
+ Switched to a new branch "deployed-HEAD"
80
+
81
+ You should now find that if you ssh into your server that you can run the application:
82
+
83
+ $ ssh your.web.server
84
+ $ cd /var/apps/hi/current
85
+ $ merb
86
+
87
+ Try making a change to your source, committing it to your repository, then run `vlad:update` again. Your code will be updated. If you restart Merb in the new directory you'll see your changes in the browser.
88
+
89
+ If you're following along with these commands, be careful that you're running `merb` in the freshly deployed directory. `current` is a symlink to a specific release directory, so you'll need to leave the directory and return to it to see the new source code (i.e. symlinks don't get updated under your shell's feet). This should do it:
90
+
91
+ $ cd ~ && cd -
92
+ $ merb
93
+
94
+ Okay, we're nearly there. All we need to do now is to automatically restart Merb when we deploy a new copy of the code with the `vlad:update` task. Add the following code to the bottom of your `config/deploy.rb` file:
95
+
96
+ Rake.clear_tasks("vlad:stop", "vlad:start")
97
+
98
+ namespace :vlad do
99
+ def stop
100
+ run "merb -m #{deploy_to}/current -K all"
101
+ end
102
+
103
+ def start
104
+ run "merb -m #{deploy_to}/current -e production -c 2"
105
+ end
106
+
107
+ remote_task :start, :roles => :app do
108
+ stop
109
+ start
110
+ end
111
+
112
+ remote_task :stop, :roles => :app do
113
+ stop
114
+ end
115
+
116
+ remote_task :update do
117
+ Rake::Task["vlad:start"].invoke
118
+ end
119
+ end
120
+
121
+ Note that in this example we've started a two process cluster with the `-c` option in the `start` method.
122
+
123
+ You'll find (with the `vlad:start` command I've shown above) that Merb is running on port 4000. If you want to run Merb on port 80 then I would recommend running these Merb processes behind Nginx, but I'll leave configuring Nginx as an exercise for the reader (Google will help you out there).
124
+
125
+ Let's just make sure that it's working. Run `rake vlad:update` a couple of times and check that Merb is getting stopped and started properly (it fails to stop Merb on the first run below simply because this was the first time I'd started it):
126
+
127
+ $ rake vlad:update
128
+ (in /Users/graham/data/effectif/projects/hi)
129
+ Loading init file from /Users/graham/data/effectif/projects/hi/config/init.rb
130
+ Initialized empty Git repository in /var/apps/hi/scm/repo/.git/
131
+ Switched to a new branch "deployed-HEAD"
132
+ ~ Could not find a PID file at /var/apps/hi/current/log/merb.main.pid. Most likely the process is no longer running and the pid file was not cleaned up.
133
+ ~ In 7643
134
+ $ rake vlad:update
135
+ (in /Users/graham/data/effectif/projects/hi)
136
+ Loading init file from /Users/graham/data/effectif/projects/hi/config/init.rb
137
+ Initialized empty Git repository in /var/apps/hi/scm/repo/.git/
138
+ Switched to a new branch "deployed-HEAD"
139
+ ~ Killing pid 7643 with INT
140
+ ~ In 7840
141
+
142
+ Now point your browser at port 4000 of your server – your application should be running!
143
+
144
+ ## Deploying from a Git branch
145
+
146
+ If you want to deploy from a specific Git branch (`master` is the default) you can set the `:revision` variable in `deploy.rb`:
147
+
148
+ set :revision, "origin/mybranch"
149
+
150
+ ## Deploying as a different user
151
+
152
+ It's not a great idea to deploy and run applications as your own login name (it's better practice to run web applications as users that don't have many privileges). I've not really addressed users in this article in order to focus on the basics of Vlad, but if you're interested you can deploy as a different user with these settings in `deploy.rb`:
153
+
154
+ set :user, "deploy"
155
+ set :domain, "#{user}@domain.com"
@@ -0,0 +1,119 @@
1
+ # Deploying Sinatra with Vlad
2
+
3
+ This tutorial has been adapted from [Deploying Sinatra with Vlad](http://effectif.com/articles/deploying-sinatra-with-vlad) by [Graham Ashton](http://effectif.com "Effectif Development").
4
+
5
+ So you've just written a nice new [Sinatra application](http://www.sinatrarb.com/ "Sinatra"), and you want to get it running on your web server. How hard can it be? Well with [Vlad the Deployer](http://rubyhitsquad.com/Vlad_the_Deployer.html "Vlad the Deployer"), it's actually rather easy.
6
+
7
+ ## Creating a sample application
8
+
9
+ Let's start by making ourselves a test app:
10
+
11
+ $ mkdir hello
12
+ $ cd hello
13
+ $ touch app.rb
14
+
15
+ Open `app.rb` in your editor and put this code in it:
16
+
17
+ require "rubygems"
18
+ require "sinatra"
19
+
20
+ get "/" do
21
+ "Hello!"
22
+ end
23
+
24
+ We can check that the app works locally by running it...
25
+
26
+ $ ruby app.rb
27
+
28
+ ...and then opening [http://localhost:4567](http://localhost:4567) in a web browser.
29
+
30
+ We need to create a `public` directory too, as Vlad assumes that we have a `public` directory for our static assets. I'm also going to make an empty CSS file so that the directory doesn't get ignored by Git:
31
+
32
+ $ mkdir public
33
+ $ touch public/master.css
34
+
35
+ We'll deploy our application from version control. I'm using Git, but you can use any system that Vlad supports; just check your files into a repository that will be accessible from your web server.
36
+
37
+ ## Configuring Vlad
38
+
39
+ Okay, we're ready for Vlad. It's a Ruby gem, so it's very easy to install:
40
+
41
+ $ sudo gem install vlad
42
+ Successfully installed vlad-1.2.0
43
+ 1 gem installed
44
+ Installing ri documentation for vlad-1.2.0...
45
+ Installing RDoc documentation for vlad-1.2.0...
46
+
47
+ There's no need to install Vlad on your server, just your workstation.
48
+
49
+ You access Vlad's functionality through Rake tasks. This means that we need a `Rakefile` which loads the Vlad code. Create `Rakefile` in the same directory as `app.rb`, then add the following code to it:
50
+
51
+ begin
52
+ require "vlad"
53
+ Vlad.load(:app => nil, :scm => "git")
54
+ rescue LoadError
55
+ # do nothing
56
+ end
57
+
58
+ Note that we've told Vlad that we intend to use Git (subversion is the default). We've set `:app` to `nil` as Vlad assumes that we'll run our application with [Mongrel](http://mongrel.rubyforge.org/ "Mongrel - Trac"). I'm not going to use Mongrel here, so we don't want Vlad to load its Mongrel recipes.
59
+
60
+ If you run `rake -T` now you should see a bunch of vlad tasks that are available to you. You can't run them yet; you need to configure Vlad with a `config/deploy.rb` file:
61
+
62
+ $ mkdir config
63
+ $ touch config/deploy.rb
64
+
65
+ Open `deploy.rb` in your editor and set the following variables:
66
+
67
+ set :application, "hello"
68
+ set :repository, "ssh://your.git.server/path/to/project/hello.git"
69
+ set :domain, "your.web.server"
70
+ set :deploy_to, "/var/apps/#{application}"
71
+
72
+ Make sure that `:repository` correctly references your source control system, and that `:domain` is set to the hostname of your server.
73
+
74
+ I won't be able to create any directories under the `/var/apps` directory (I'm going to run vlad using my own username in this example), so I need to login to my server and make sure that I can create files in the `hello` directory:
75
+
76
+ $ ssh your.web.server
77
+ $ sudo mkdir -p /var/apps/hello
78
+ $ sudo chown yourusername /var/apps/hello
79
+
80
+ Now you can try running Vlad, to create all the directories necessary to serve your project. Back on your workstation, type:
81
+
82
+ $ rake vlad:setup
83
+
84
+ You should find that some directories have been created within `/var/apps/hello` on your server.
85
+
86
+ Let's trying deploying some code:
87
+
88
+ $ rake vlad:update
89
+ (in /Users/graham/data/effectif/projects/hello)
90
+ Initialized empty Git repository in /var/apps/hello/scm/repo/.git/
91
+ Switched to a new branch "deployed-HEAD"
92
+
93
+ You should now find that if you ssh into your server that you can run the application:
94
+
95
+ $ ssh your.web.server
96
+ $ cd /var/apps/hello/current
97
+ $ ruby app.rb
98
+
99
+ Try making a change to your source, committing it to your repository, then run `vlad:update` again. Your code will be updated. If you restart Sinatra in the new directory you'll see your changes in the browser.
100
+
101
+ If you're following along with these commands, be careful that you're running `app.rb` in the freshly deployed directory. `current` is a symlink to a specific release directory, so you'll need to leave the directory and return to it to see the new source code (i.e. symlinks don't get updated under your shell's feet). This should do it:
102
+
103
+ $ cd ~ && cd -
104
+ $ ruby app.rb
105
+
106
+ You may now be wondering how to get Thin running automatically, and how to re-start it when you run `vlad:update`. That should be the subject of my next blog post (you can [subscribe](/articles.xml) if you need it).
107
+
108
+ ## Deploying from a Git branch
109
+
110
+ If you want to deploy from a specific Git branch (`master` is the default) you can set the `:revision` variable in `deploy.rb`:
111
+
112
+ set :revision, "origin/mybranch"
113
+
114
+ ## Deploying as a different user
115
+
116
+ It's not a great idea to deploy and run applications as your own login name (it's better practice to run web applications as users that don't have many privileges). I've not really addressed users in this article in order to focus on the basics of Vlad, but if you're interested you can deploy as a different user with these settings in `deploy.rb`:
117
+
118
+ set :user, "deploy"
119
+ set :domain, "#{user}@domain.com"
@@ -20,7 +20,7 @@ module Vlad
20
20
 
21
21
  ##
22
22
  # This is the version of Vlad you are running.
23
- VERSION = '1.3.1'
23
+ VERSION = '1.3.2'
24
24
 
25
25
  ##
26
26
  # Base error class for all Vlad errors.
@@ -54,7 +54,7 @@ namespace :vlad do
54
54
  begin
55
55
  run [ "cd #{scm_path}",
56
56
  "#{source.checkout revision, scm_path}",
57
- "#{source.export scm_path, release_path}",
57
+ "#{source.export revision, release_path}",
58
58
  "chmod -R g+w #{latest_release}",
59
59
  "rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids",
60
60
  "mkdir -p #{latest_release}/db #{latest_release}/tmp"
@@ -12,9 +12,9 @@ class Vlad::Darcs
12
12
  ].join(" && ")
13
13
  end
14
14
 
15
- def export(dir, dest)
16
- [ %{mkdir -p #{dest}},
17
- %{ls | grep ^[^_] | xargs -I vlad cp -R vlad #{dest}}
15
+ def export(revision, destination)
16
+ [ %{mkdir -p #{destination}},
17
+ %{ls | grep ^[^_] | xargs -I vlad cp -R vlad #{destination}}
18
18
  ].join(" && ")
19
19
  end
20
20
 
@@ -9,25 +9,31 @@ class Vlad::Git
9
9
  # SHA1 or equivalent (e.g. branch, tag, etc...)
10
10
 
11
11
  def checkout(revision, destination)
12
- destination = 'repo' if destination == '.'
12
+ destination = File.join(destination, 'repo')
13
13
  revision = 'HEAD' if revision =~ /head/i
14
14
 
15
15
  [ "rm -rf #{destination}",
16
16
  "#{git_cmd} clone #{repository} #{destination}",
17
17
  "cd #{destination}",
18
- "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}"
18
+ "#{git_cmd} checkout -f -b deployed-#{revision} #{revision}",
19
+ "cd -"
19
20
  ].join(" && ")
20
21
  end
21
22
 
22
23
  ##
23
- # Returns the command that will export +revision+ from the repository into
24
- # the directory +destination+.
24
+ # Returns the command that will export +revision+ from the current directory
25
+ # into the directory +destination+.
26
+ # Expects to be run from +scm_path+ after Vlad::Git#checkout
25
27
 
26
28
  def export(revision, destination)
27
- revision = 'HEAD' if revision == "."
29
+ revision = 'HEAD' if revision =~ /head/i
30
+ revision = "deployed-#{revision}"
28
31
 
29
32
  [ "mkdir -p #{destination}",
30
- "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)"
33
+ "cd repo",
34
+ "#{git_cmd} archive --format=tar #{revision} | (cd #{destination} && tar xf -)",
35
+ "cd -",
36
+ "cd .."
31
37
  ].join(" && ")
32
38
  end
33
39
 
@@ -9,24 +9,26 @@ class TestVladGit < VladTestCase
9
9
  set :repository, "git@myhost:/home/john/project1"
10
10
  end
11
11
 
12
+ # Checkout the way the default :update task invokes the method
12
13
  def test_checkout
13
- # Checkout to the current directory (which is what the :update task passes)
14
- cmd = @scm.checkout 'master', '.'
15
- assert_equal 'rm -rf repo && git clone git@myhost:/home/john/project1 repo && cd repo && git checkout -f -b deployed-master master', cmd
14
+ cmd = @scm.checkout 'head', '/the/scm/path'
15
+ assert_equal 'rm -rf /the/scm/path/repo && git clone git@myhost:/home/john/project1 /the/scm/path/repo && cd /the/scm/path/repo && git checkout -f -b deployed-HEAD HEAD && cd -', cmd
16
+ end
16
17
 
17
- # Mimic :update task
18
- # 'head' should become HEAD
19
- cmd = @scm.checkout 'head', '.'
20
- assert_equal 'rm -rf repo && git clone git@myhost:/home/john/project1 repo && cd repo && git checkout -f -b deployed-HEAD HEAD', cmd
18
+ # This is not how the :update task invokes the method
19
+ def test_checkout_revision
20
+ # Checkout to the current directory
21
+ cmd = @scm.checkout 'master', '.'
22
+ assert_equal 'rm -rf ./repo && git clone git@myhost:/home/john/project1 ./repo && cd ./repo && git checkout -f -b deployed-master master && cd -', cmd
21
23
 
22
24
  # Checkout to a relative path
23
25
  cmd = @scm.checkout 'master', 'some/relative/path'
24
- assert_equal 'rm -rf some/relative/path && git clone git@myhost:/home/john/project1 some/relative/path && cd some/relative/path && git checkout -f -b deployed-master master', cmd
26
+ assert_equal 'rm -rf some/relative/path/repo && git clone git@myhost:/home/john/project1 some/relative/path/repo && cd some/relative/path/repo && git checkout -f -b deployed-master master && cd -', cmd
25
27
  end
26
28
 
27
29
  def test_export
28
30
  cmd = @scm.export 'master', 'the/release/path'
29
- assert_equal 'mkdir -p the/release/path && git archive --format=tar master | (cd the/release/path && tar xf -)', cmd
31
+ assert_equal 'mkdir -p the/release/path && cd repo && git archive --format=tar deployed-master | (cd the/release/path && tar xf -) && cd - && cd ..', cmd
30
32
  end
31
33
 
32
34
  def test_revision
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vlad
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -32,7 +32,7 @@ cert_chain:
32
32
  FBHgymkyj/AOSqKRIpXPhjC6
33
33
  -----END CERTIFICATE-----
34
34
 
35
- date: 2009-03-06 00:00:00 -08:00
35
+ date: 2009-03-16 00:00:00 -07:00
36
36
  default_executable:
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
@@ -63,7 +63,7 @@ dependencies:
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 1.9.0
66
+ version: 1.10.0
67
67
  version:
68
68
  description: Vlad the Deployer is pragmatic application deployment automation, without mercy. Much like Capistrano, but with 1/10th the complexity. Vlad integrates seamlessly with Rake, and uses familiar and standard tools like ssh and rsync. Impale your application on the heartless spike of the Deployer.
69
69
  email:
@@ -79,6 +79,8 @@ extra_rdoc_files:
79
79
  - Manifest.txt
80
80
  - README.txt
81
81
  - considerations.txt
82
+ - doco/deploying-merb-with-vlad.txt
83
+ - doco/deploying-sinatra-with-vlad.txt
82
84
  - doco/faq.txt
83
85
  - doco/getting_started.txt
84
86
  - doco/migration.txt
@@ -90,6 +92,8 @@ files:
90
92
  - README.txt
91
93
  - Rakefile
92
94
  - considerations.txt
95
+ - doco/deploying-merb-with-vlad.txt
96
+ - doco/deploying-sinatra-with-vlad.txt
93
97
  - doco/faq.txt
94
98
  - doco/getting_started.txt
95
99
  - doco/migration.txt
metadata.gz.sig CHANGED
Binary file