capistrano-windows-server 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,239 @@
1
+ capistrano-windows-server
2
+ =========================
3
+
4
+ Deploy Ruby on Rails applications with capistrano to Windows servers
5
+
6
+ Capistrano is the preferred deploy method for Ruby on Rails apps, but Windows isn't really supported.
7
+ We didn't really like having a separate workflow for the projects on that require Windows though,
8
+ so this is what we came up with at SciMed.
9
+
10
+ Currently, only git is supported, but it could potentially support others.
11
+ There's plenty of room for improvement here, so feel free to fork and contribute.
12
+
13
+ ### How this is different from a normal capistrano setup
14
+
15
+ capistrano-windows-server provides a level of convenience for deploying to Windows servers,
16
+ but some things you might expect from a normal capistrano deploy are not possible.
17
+ Windows filesystems do not support symlinks, and files cannot be moved or deleted while they are in use (the server is running).
18
+
19
+ * Your app will deploy directly to #{deploy_to}/current and update in-place.
20
+ When you deploy, capistrano is essentially doing a git pull.
21
+ * There is no releases/ directory, and only one copy of your app will be on the server at any time.
22
+ This means that you cannot roll back.
23
+ * Git submodules are not yet supported by WindowsGit. Instructions for dealing with that are below.
24
+
25
+ ### Server stack
26
+
27
+ This gem assumes you are working with the following application stack, but you can modify it to meet your needs.
28
+
29
+ * Ruby on Rails application
30
+ * Mongrel instances proxied behind another web server (Apache + Passenger, nginx)
31
+ * Git code repository
32
+
33
+
34
+ Setting up the Windows server
35
+ -----------------------------
36
+
37
+ This section walks you through setting up SSH and Git on the windows server to prepare it for the deploy.
38
+ These instruction are for Windows Server 2003. For other versions, YMMV.
39
+ Administrative access is required.
40
+
41
+ * Disable User Access Control. We'll re-enable this later. Reboot if necessary.
42
+ <br><br>
43
+ *Control Panel > Users > Notify never*
44
+
45
+ * Purchase and install WindowsGit from www.windowsgit.com ($9).
46
+ <br><br>
47
+ Yes, you should buy this. I wasted hours trying to get msysgit and COPSSH to work together.
48
+ If your time is worth more than $3/hr, then this is well worth your money.
49
+
50
+ * WindowsGit creates a git user. Make the git user an administrator. This is required, or you will run into
51
+ [this problem](http://stackoverflow.com/questions/4516111/stack-trace-sshd-exe-fatal-error-could-not-load-u-win32-error-1114-copss/4518324).
52
+ <br><br>
53
+ *Administrative Tools > Computer Management > System Tools > Local Users and Groups > Users > git's properties > Member Of > Add "Administrators"*
54
+
55
+ * Open the COPSSH Control Panel
56
+ <br><br>
57
+ *Start Menu > Programs > Copssh > 01 COPSSH Control Panel*
58
+
59
+ * Active the git user for SSH
60
+ <br><br>
61
+ *Users > Add*
62
+
63
+ * *Recommended:* Disallow password authentication, and use SSH key-based authentication
64
+
65
+ * Import your developers/deployers' public SSH keys
66
+ <br><br>
67
+ *Keys > Import: Paste in public keys; import one at a time.*
68
+
69
+ * Re-enable User Access Control
70
+ <br><br>
71
+ *Control Panel > Users >* (restore previous value)
72
+
73
+ Now that COPSSH is up and running, ensure that you can SSH into the server as the git user. If you have problems, check the COPSSH event log under the Status tab. Make sure $HOME/.ssh/authorized_keys contains the keys you added.
74
+
75
+ If you haven't already, set up Ruby and install any gems needed for your application, plus mongrel.
76
+ The capistrano recipes in this gem create mongrel Windows services to run your app.
77
+ You can use Apache or your web server of choice to proxy for your mongrel instances.
78
+
79
+
80
+ Setting up capistrano for your Rails project
81
+ --------------------------------------------
82
+
83
+ **Rails 2.x**: Add the capistrano-windows-server gem to your Gemfile, and run `bundle`.
84
+
85
+ gem "capistrano-windows-server", :lib => "capistrano"
86
+
87
+ **Rails 3.x**: Add the capistrano-windows-server environment.rb, and run `rake gems:install`.
88
+
89
+ config.gem "capistrano-windows-server", :lib => "capistrano"
90
+
91
+ Set up capistrano as you normally would.
92
+ The [capistrano wiki](https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning) and
93
+ [capistrano handbook](https://github.com/leehambley/capistrano-handbook/blob/master/index.markdown) are helpful.
94
+
95
+ Set up your config/deploy.rb:
96
+
97
+ There are a few configuration values that need to be set in your deploy.rb, in addition to your base application configuration.
98
+
99
+ require 'capistrano/ext/windows_server'
100
+
101
+ set :rails_env, 'production'
102
+ set :user, 'git'
103
+ set :deploy_to, "/cygdrive/c/rails_apps/#{application}" # Deploy to C:\rails_apps\#{application}
104
+ set :mongrel_instances, (1..3) # Create 3 mongrel instances
105
+ set :mongrel_instance_prefix, 'mongrel_' # named mongrel_{1..3}
106
+ set :base_port, 8000 # on ports 8000, 8001, 8002
107
+
108
+ set :ruby_exe_path, '/cygdrive/c/ruby/bin/ruby' # This should be set to the location where Ruby is installed.
109
+
110
+ Your final config/deploy.rb might look something like this:
111
+
112
+ require 'capistrano/ext/windows_server'
113
+
114
+ set :application, "windowsy"
115
+ set :repository, "git@github.com:you/windowsy_rails_app.git"
116
+ set :repository_host_key, "github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" # This is optional and comes from .ssh/known_hosts. It prevents the initial deploy host key verification problems.
117
+
118
+ set :branch do
119
+ default_ref = 'master'
120
+ ref = Capistrano::CLI.ui.ask "Ref to deploy (make sure to push the ref first): [#{default_ref}] "
121
+ ref = default_ref if ref.empty?
122
+ ref
123
+ end
124
+
125
+ set :rails_env, 'production'
126
+ set :user, 'git'
127
+ set :deploy_to, "/cygdrive/c/rails_apps/#{application}" # Deploy to C:\rails_apps\#{application}
128
+ set :mongrel_instances, (1..3) # Create 3 mongrel instances
129
+ set :mongrel_instance_prefix, 'mongrel_' # named mongrel_{1..3}
130
+ set :base_port, 8000 # on ports 8000, 8001, 8002
131
+
132
+ set :domain, 'www.windowsy.com'
133
+ role :app, domain
134
+ role :web, domain
135
+ role :db, domain, :primary => true
136
+
137
+
138
+ Cleaning up the server before the initial deploy
139
+ ------------------------------------------------
140
+
141
+ If you don't already have mongrel Windows services installed for your app, skip this step.
142
+
143
+ `cap deploy:setup` will create new mongrel Windows services based on the new app location, so you'll need to remove the existing ones.
144
+
145
+ If you're using the same naming scheme as you have configured in deploy.rb (in our example, mongrel_1 to 3),
146
+ then use the deploy:mongrel:remove recipe to remove the services.
147
+
148
+ cap deploy:mongrel:remove
149
+
150
+ Otherwise, remove your old services manually (in a Windows command prompt on the server):
151
+
152
+ mongrel service::remove -N old_mongrel_service_name
153
+
154
+
155
+ The initial deploy
156
+ ------------------
157
+
158
+ The deploy:setup recipe is a little different for Windows.
159
+ In addition to creating the directory structure, it clones your project into #{deploy_to}/current and installs the mongrel Windows services.
160
+
161
+ cap deploy:setup
162
+
163
+ After `cap deploy:setup` runs successfully, it's time to set up the Rails application.
164
+ Create or copy in config/database.yml, set up the database server, install gems, and anything else you need to do to make the app run.
165
+ Testing to make sure the app will start with `rails script/server -e production` is a good idea.
166
+
167
+ Once it's ready, you can deploy your app for the first time:
168
+
169
+ cap deploy:cold
170
+
171
+ ### Submodules
172
+
173
+ Unfortunately, WindowsGit [does not currently support submodules](https://github.com/SciMed/capistrano-windows-server/issues/1).
174
+
175
+ If your project uses submodules, there are a few ways you can deal with this.
176
+
177
+ * Do it by hand - manually clone each submodule after your initial deploy
178
+ * Install another git distribution (msysgit, PortableGit), and run git submodule init/update in your project directory
179
+ * Pull the missing files out of another git distribution (msysgit, PortableGit) and copy them to C:\Program Files\ICW\bin .
180
+ If you go this route, please document the process on [this issue](https://github.com/SciMed/capistrano-windows-server/issues/1),
181
+ so we can update this documentation.
182
+
183
+
184
+ Which cap tasks are available?
185
+ ------------------------------
186
+
187
+ As usual, you can use `cap -T` for a full list of capistrano tasks.
188
+
189
+ The following default capistrano tasks are supported:
190
+
191
+ * `cap deploy` - Updates the code on the server (essentially just a git pull in the current/ directory)
192
+ * `cap deploy:cold` - Deploy and start the server
193
+ * `cap deploy:start` `cap deploy:stop` `cap deploy:restart` - Stop and start the mongrel services
194
+ * `cap deploy:migrate` - Run migrations
195
+ * `cap deploy:migrations` - Deploy and run migrations
196
+ * `cap deploy:update` - Updates the code without restarting the server
197
+ * `cap deploy:update_code` - Now an alias for deploy:update
198
+ * `cap deploy:upload` - Upload files to the server
199
+ * `cap invoke` - Run a command on the server specified by COMMAND
200
+ * `cap shell` - Open a Begin an interactive Capistrano session
201
+
202
+ The following new tasks were added:
203
+
204
+ * `cap deploy:mongrel:setup` - Create mongrel services
205
+ * `cap deploy:mongrel:remove` - Remove mongrel services
206
+ * `cap rake` - Run a rake task, specified by COMMAND. eg: cap rake COMMAND="gems:install"
207
+
208
+ The following tasks will later be fixed:
209
+
210
+ * `cap deploy:check`
211
+ * `cap deploy:pending`
212
+ * `cap deploy:pending:diff`
213
+ * `cap deploy:web:enable`
214
+ * `cap deploy:web:disable`
215
+
216
+ The following tasks were removed:
217
+
218
+ * `cap deploy:cleanup`
219
+ * `cap deploy:rollback`
220
+ * `cap deploy:symlink`
221
+
222
+
223
+ Contributing to capistrano-windows-server
224
+ -----------------------------------------
225
+
226
+ This gem was created to work on our systems and has not yet been tested on a wide range of systems.
227
+ We would love if you contribute back changes that you make to make it work for you.
228
+
229
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
230
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
231
+ * Fork the project
232
+ * Start a feature/bugfix branch
233
+ * Commit and push until you are happy with your contribution
234
+
235
+
236
+ Copyright
237
+ ---------
238
+
239
+ Copyright (c) 2011 SciMed Solutions, Inc. See LICENSE.txt for further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capistrano-windows-server}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Edward Anderson"]
12
+ s.date = %q{2011-07-22}
13
+ s.description = %q{This gem modifies capistrano recipes to allow deploys to windows machines.
14
+ Several nuances such as the lack of symlinks make the deploy a little different, but it's better than doing it by hand.
15
+ See the github page for instruction on how to set up Windows to get it ready for a deploy.}
16
+ s.email = %q{edward.anderson@scimedsolutions.com}
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "capistrano-windows-server.gemspec",
30
+ "lib/capistrano/ext/windows_server.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/nilbus/capistrano-windows-server}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.4.2}
36
+ s.summary = %q{Deploy Ruby on Rails applications with Capistrano to Windows servers}
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<capistrano>, [">= 0"])
43
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
44
+ else
45
+ s.add_dependency(%q<capistrano>, [">= 0"])
46
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<capistrano>, [">= 0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ end
52
+ end
53
+
@@ -5,22 +5,23 @@ configuration = Capistrano::Configuration.respond_to?(:instance) ?
5
5
  configuration.load do
6
6
  set :scm, :git
7
7
  set :deploy_via, :remote_cache
8
- set :git_enable_submodules, false # Git submodules not supported on windows
8
+ #set :git_enable_submodules, false # Git submodules not supported on windows
9
9
  set :shared_dir, "."
10
10
  set :repository_cache, "current"
11
11
  set :scm_verbose, true
12
12
  set :use_sudo, false
13
13
 
14
14
  namespace :deploy do
15
- desc "Custom for Windows - no releases; just update git in place"
15
+ desc "Update the code on the server by doing a git pull in the current/ directory"
16
16
  task :update do
17
- # update_repository_cache will attempt to clean out the repository; we must prevent that with this deploy method.
17
+ # update_repository_cache will attempt to clean out the repository; we must prevent that.
18
18
  # /bin/git below is where www.windowsgit.com's windows git/ssh installation puts the git executable.
19
+ # This creates a git proxy that goes in $PATH before /bin, which will filter out any `git clean` commands.
19
20
  run "mkdir -p '#{shared_path}/bin'"
20
21
  run <<-RUN
21
22
  echo 'if [ "$1" != "clean" ]; then /bin/git $*; fi' > "#{shared_path}/bin/git.exe"
22
23
  RUN
23
- alter_path_cmd = "export PATH=#{shared_path}/bin:$PATH"
24
+ alter_path_cmd = "export PATH=#{shared_path}/bin:$PATH # Required for capistrano-windows-server"
24
25
  run <<-RUN
25
26
  if ! grep '#{alter_path_cmd}' ~/.bashrc > /dev/null; then echo '#{alter_path_cmd}' >> ~/.bashrc; fi
26
27
  RUN
@@ -28,7 +29,7 @@ configuration.load do
28
29
  strategy.send 'update_repository_cache'
29
30
  end
30
31
 
31
- desc "On windows, this is an alias for update"
32
+ desc "An alias for deploy:update"
32
33
  task :update_code do
33
34
  update
34
35
  end
@@ -54,33 +55,37 @@ configuration.load do
54
55
  end
55
56
  end
56
57
 
57
- # Do nothing for Windows
58
- task :finalize_update do; end
59
-
60
- # Do nothing for Windows
61
- task :symlink do; end
58
+ # Remove tasks that are not appropriate on Windows
59
+ %w(finalize_update symlink cleanup).each do |removed_task|
60
+ task removed_task do; end
61
+ end
62
+ namespace :rollback do
63
+ %w(code default).each do |removed_task|
64
+ task removed_task do; end
65
+ end
66
+ end
62
67
 
63
- desc "Run migrations"
68
+ desc "Run pending migrations"
64
69
  task :migrate do
65
70
  set :rake_cmd, "#{ruby_exe_path} -e \"require 'rubygems'; gem 'rake', '>= 0'; load Gem.bin_path('rake', 'rake', '>= 0')\""
66
71
  run "cd #{current_path} && #{rake_cmd} db:migrate RAILS_ENV=#{rails_env}"
67
72
  end
68
73
 
69
- desc "start mongrel"
74
+ desc "Start mongrel"
70
75
  task :start do
71
76
  mongrel_instances.each do |n|
72
77
  run "net start #{mongrel_instance_prefix}#{n}"
73
78
  end
74
79
  end
75
80
 
76
- desc "stop mongrel"
81
+ desc "Stop mongrel"
77
82
  task :stop do
78
83
  mongrel_instances.each do |n|
79
84
  run "net stop #{mongrel_instance_prefix}#{n}"
80
85
  end
81
86
  end
82
87
 
83
- desc "restart mongrel"
88
+ desc "Restart mongrel"
84
89
  task :restart do
85
90
  mongrel_instances.each do |n|
86
91
  run "net stop #{mongrel_instance_prefix}#{n}"
@@ -89,7 +94,7 @@ configuration.load do
89
94
  end
90
95
 
91
96
  namespace :mongrel do
92
- desc "create mongrel services"
97
+ desc "Create mongrel services"
93
98
  task :setup do
94
99
  mongrel_instances.each do |n|
95
100
  run "cd #{current_path} && #{mongrel_cmd} service::install -e #{rails_env} -N #{mongrel_instance_prefix}#{n} -p #{base_port + n - mongrel_instances.first}"
@@ -97,7 +102,7 @@ configuration.load do
97
102
  end
98
103
  end
99
104
 
100
- desc "remove mongrel services"
105
+ desc "Remove mongrel services"
101
106
  task :remove do
102
107
  set :mongrel_cmd, "#{ruby_exe_path} -e \"require 'rubygems'; gem 'mongrel', '>= 0'; load Gem.bin_path('mongrel', 'mongrel_rails', '>= 0')\""
103
108
  mongrel_instances.each do |n|
@@ -109,11 +114,11 @@ configuration.load do
109
114
 
110
115
  end
111
116
 
112
- desc "Run a rake command in CMD"
117
+ desc "Run a rake command in COMMAND"
113
118
  task :rake do
114
- raise "Specify the command with CMD='some:task with_arguments'" unless ENV['CMD']
119
+ raise "Specify the command with COMMAND='some:task with_arguments'" unless ENV['COMMAND']
115
120
  set :rake_cmd, "#{ruby_exe_path} -e \"require 'rubygems'; gem 'rake', '>= 0'; load Gem.bin_path('rake', 'rake', '>= 0')\""
116
- run "cd #{current_path} && #{rake_cmd} #{ENV['CMD']} RAILS_ENV=#{rails_env}"
121
+ run "cd #{current_path} && #{rake_cmd} #{ENV['COMMAND']} RAILS_ENV=#{rails_env}"
117
122
  end
118
123
 
119
124
  after 'deploy:setup', 'deploy:update_code'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-windows-server
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Edward Anderson
@@ -59,16 +59,17 @@ extensions: []
59
59
 
60
60
  extra_rdoc_files:
61
61
  - LICENSE.txt
62
- - README.rdoc
62
+ - README.md
63
63
  files:
64
64
  - .document
65
65
  - Gemfile
66
66
  - Gemfile.lock
67
67
  - LICENSE.txt
68
- - README.rdoc
68
+ - README.md
69
69
  - Rakefile
70
70
  - VERSION
71
- - lib/capistrano/windows_server.rb
71
+ - capistrano-windows-server.gemspec
72
+ - lib/capistrano/ext/windows_server.rb
72
73
  has_rdoc: true
73
74
  homepage: http://github.com/nilbus/capistrano-windows-server
74
75
  licenses:
data/README.rdoc DELETED
@@ -1,20 +0,0 @@
1
- = capistrano-windows-server
2
-
3
- Deploy Ruby on Rails applications with Capistrano to Windows servers
4
-
5
- This gem modifies capistrano recipes to allow deploys to windows machines.
6
- Several nuances such as the lack of symlinks make the deploy a little different, but it's better than doing it by hand.
7
- See the github page for instruction on how to set up Windows to get it ready for a deploy.
8
-
9
- == Contributing to capistrano-windows-server
10
-
11
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
12
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
13
- * Fork the project
14
- * Start a feature/bugfix branch
15
- * Commit and push until you are happy with your contribution
16
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
17
-
18
- == Copyright
19
-
20
- Copyright (c) 2011 SciMed Solutions, Inc. See LICENSE.txt for further details.