capistrano-virtualenv 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,5 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Capistrano::Virtualenv::VERSION
17
17
 
18
18
  gem.add_dependency("capistrano")
19
- gem.add_dependency("capistrano-file-transfer-ext", "~> 0.0.3")
19
+ gem.add_development_dependency("net-scp", "~> 1.0.4")
20
+ gem.add_development_dependency("net-ssh", "~> 2.2.2")
21
+ gem.add_development_dependency("vagrant", "~> 1.0.6")
20
22
  end
@@ -1,5 +1,4 @@
1
1
  require "capistrano-virtualenv/version"
2
- require "capistrano/configuration/actions/file_transfer_ext"
3
2
  require "uri"
4
3
 
5
4
  module Capistrano
@@ -8,161 +7,181 @@ module Capistrano
8
7
  configuration.load {
9
8
  namespace(:virtualenv) {
10
9
  _cset(:virtualenv_use_system, false) # controls whether virtualenv should be use system packages or not.
11
-
12
- _cset(:virtualenv_script_url, 'https://raw.github.com/pypa/virtualenv/master/virtualenv.py')
13
- _cset(:virtualenv_script_file) {
14
- File.join(shared_path, 'virtualenv', File.basename(URI.parse(virtualenv_script_url).path))
15
- }
16
- _cset(:virtualenv_bootstrap_python, 'python') # the python executable which will be used to craete virtualenv
17
- _cset(:virtualenv_cmd) {
18
- [
19
- virtualenv_bootstrap_python,
20
- virtualenv_script_file,
21
- virtualenv_options,
22
- ].flatten.join(' ')
23
- }
24
- _cset(:virtualenv_options) {
25
- os = %w(--quiet)
26
- os << "--system-site-packages" if virtualenv_use_system
27
- os
28
- }
29
- _cset(:virtualenv_easy_install_options, %w(--quiet))
30
- _cset(:virtualenv_pip_options, %w(--quiet))
10
+ _cset(:virtualenv_script_url, "https://raw.github.com/pypa/virtualenv/master/virtualenv.py")
11
+ _cset(:virtualenv_script_file) { File.join(shared_path, "virtualenv", File.basename(URI.parse(virtualenv_script_url).path)) }
12
+ _cset(:virtualenv_bootstrap_python, "python") # the python executable which will be used to craete virtualenv
13
+ _cset(:virtualenv_cmd) { command }
14
+ _cset(:virtualenv_default_options) {
15
+ options = %w(--distribute --quiet)
16
+ options << "--system-site-packages" if virtualenv_use_system
17
+ options
18
+ }
19
+ _cset(:virtualenv_options) { virtualenv_default_options + fetch(:virtualenv_extra_options, []) }
20
+ _cset(:virtualenv_easy_install_options) { # TODO: remove this
21
+ logger.info(":virtualenv_easy_install_options has been deprecated.")
22
+ %w(--quiet)
23
+ }
24
+ _cset(:virtualenv_pip_default_options, %w(--quiet))
25
+ _cset(:virtualenv_pip_options) { virtualenv_pip_default_options + fetch(:virtualenv_pip_extra_options, []) }
31
26
  _cset(:virtualenv_pip_install_options, [])
32
- _cset(:virtualenv_pip_package, 'pip')
33
27
  _cset(:virtualenv_requirements, []) # primary package list
34
- _cset(:virtualenv_requirements_file) { # secondary package list
35
- File.join(release_path, 'requirements.txt')
36
- }
28
+ _cset(:virtualenv_requirements_file) { File.join(release_path, "requirements.txt") } # secondary package list
37
29
  _cset(:virtualenv_build_requirements, {})
38
- _cset(:virtualenv_install_packages, []) # apt packages
39
30
 
40
31
  ## shared virtualenv:
41
32
  ## - created in shared_path
42
33
  ## - to be used to share libs between releases
43
- _cset(:virtualenv_shared_path) {
44
- File.join(shared_path, 'virtualenv', 'shared')
45
- }
46
- _cset(:virtualenv_shared_python) {
47
- File.join(virtualenv_shared_path, 'bin', 'python')
48
- }
49
- _cset(:virtualenv_shared_easy_install) {
50
- File.join(virtualenv_shared_path, 'bin', 'easy_install')
51
- }
52
- _cset(:virtualenv_shared_easy_install_cmd) {
34
+ _cset(:virtualenv_shared_path) { File.join(shared_path, "virtualenv", "shared") }
35
+ _cset(:virtualenv_shared_bin_path) { File.join(virtualenv_shared_path, "bin") }
36
+ _cset(:virtualenv_shared_python) { File.join(virtualenv_shared_bin_path, "python") }
37
+ _cset(:virtualenv_shared_easy_install) { # TODO: remove this
38
+ logger.info(":virtualenv_shared_easy_install has been deprecated.")
39
+ File.join(virtualenv_shared_bin_path, "easy_install")
40
+ }
41
+ _cset(:virtualenv_shared_easy_install_cmd) { # TODO: remove this
53
42
  # execute from :virtualenv_shared_python
54
43
  # since `virtualenv --relocatable` will not set shebang line with absolute path.
44
+ logger.info(":virtualenv_shared_easy_install_cmd has been deprecated.")
55
45
  [
56
- virtualenv_shared_python,
57
- virtualenv_shared_easy_install,
58
- virtualenv_easy_install_options,
59
- ].flatten.join(' ')
60
- }
61
- _cset(:virtualenv_shared_pip) {
62
- File.join(virtualenv_shared_path, 'bin', 'pip')
63
- }
64
- _cset(:virtualenv_shared_pip_cmd) {
46
+ virtualenv_shared_python.dump,
47
+ virtualenv_shared_easy_install.dump,
48
+ virtualenv_easy_install_options.map { |x| x.dump }.join(" "),
49
+ ].join(" ")
50
+ }
51
+ # execute from :virtualenv_shared_python
52
+ # since `virtualenv --relocatable` will not set shebang line with absolute path.
53
+ _cset(:virtualenv_shared_pip) { # TODO: remove this
54
+ logger.info(":virtualenv_shared_pip has been deprecated.")
55
+ File.join(virtualenv_shared_bin_path, "pip")
56
+ }
57
+ _cset(:virtualenv_shared_pip_cmd) { # TODO: remove this
58
+ logger.info(":virtualenv_shared_pip_cmd has been deprecated.")
65
59
  [
66
- virtualenv_shared_python,
67
- virtualenv_shared_pip,
68
- virtualenv_pip_options,
69
- ].flatten.join(' ')
60
+ virtualenv_shared_python.dump,
61
+ virtualenv_shared_pip.dump,
62
+ virtualenv_pip_options.map { |x| x.dump }.join(" "),
63
+ ].join(" ")
70
64
  }
71
65
 
72
66
  ## release virtualenv
73
67
  ## - created in release_path
74
68
  ## - common libs are copied from shared virtualenv
75
69
  ## - will be used for running application
76
- _cset(:virtualenv_release_path) { # the path where runtime virtualenv will be created
77
- File.join(release_path, 'vendor', 'virtualenv')
78
- }
79
- _cset(:virtualenv_release_python) { # the python executable within virtualenv
80
- File.join(virtualenv_release_path, 'bin', 'python')
81
- }
82
- _cset(:virtualenv_release_easy_install) {
83
- File.join(virtualenv_release_path, 'bin', 'easy_install')
84
- }
85
- _cset(:virtualenv_release_easy_install_cmd) {
70
+ _cset(:virtualenv_release_path) { File.join(release_path, "vendor", "virtualenv") } # the path where runtime virtualenv will be created
71
+ _cset(:virtualenv_release_bin_path) { File.join(virtualenv_release_path, "bin") }
72
+ _cset(:virtualenv_release_python) { File.join(virtualenv_release_bin_path, "python") } # the python executable within virtualenv
73
+ _cset(:virtualenv_release_easy_install) { # TODO: remove this
74
+ logger.info(":virtualenv_release_easy_install has been deprecated.")
75
+ File.join(virtualenv_release_bin_path, "easy_install")
76
+ }
77
+ _cset(:virtualenv_release_easy_install_cmd) { # TODO: remove this
78
+ # execute from :virtualenv_release_python
79
+ # since `virtualenv --relocatable` will not set shebang line with absolute path.
80
+ logger.info(":virtualenv_release_easy_install_cmd has been deprecated.")
86
81
  [
87
- virtualenv_release_python,
88
- virtualenv_release_easy_install,
89
- virtualenv_easy_install_options,
90
- ].flatten.join(' ')
82
+ virtualenv_release_python.dump,
83
+ virtualenv_release_easy_install.dump,
84
+ virtualenv_easy_install_options.map { |x| x.dump }.join(" "),
85
+ ].join(" ")
91
86
  }
92
- _cset(:virtualenv_release_pip) {
93
- File.join(virtualenv_release_path, 'bin', 'pip')
87
+ _cset(:virtualenv_release_pip) { # TODO: remove this
88
+ logger.info(":virtualenv_release_pip has been deprecated.")
89
+ File.join(virtualenv_release_bin_path, "pip")
94
90
  }
95
- _cset(:virtualenv_release_pip_cmd) {
91
+ _cset(:virtualenv_release_pip_cmd) { # TODO: remove this
92
+ logger.info(":virtualenv_release_pip_cmd has been deprecated.")
96
93
  [
97
- virtualenv_release_python,
98
- virtualenv_release_pip,
99
- virtualenv_pip_options,
100
- ].flatten.join(' ')
94
+ virtualenv_release_python.dump,
95
+ virtualenv_release_pip.dump,
96
+ virtualenv_pip_options.map { |x| x.dump }.join(" "),
97
+ ].flatten.join(" ")
101
98
  }
102
99
 
103
100
  ## current virtualenv
104
101
  ## - placed in current_path
105
102
  ## - virtualenv of currently running application
106
- _cset(:virtualenv_current_path) {
107
- File.join(current_path, 'vendor', 'virtualenv')
108
- }
109
- _cset(:virtualenv_current_python) {
110
- File.join(virtualenv_current_path, 'bin', 'python')
111
- }
112
- _cset(:virtualenv_current_easy_install) {
113
- File.join(virtualenv_current_path, 'bin', 'easy_install')
114
- }
115
- _cset(:virtualenv_current_easy_install_cmd) {
103
+ _cset(:virtualenv_current_path) { File.join(current_path, "vendor", "virtualenv") }
104
+ _cset(:virtualenv_current_bin_path) { File.join(virtualenv_current_path, "bin") }
105
+ _cset(:virtualenv_current_python) { File.join(virtualenv_current_bin_path, "python") }
106
+ _cset(:virtualenv_current_easy_install) { # TODO: remove this
107
+ logger.info(":virtualenv_current_easy_install has been deprecated.")
108
+ File.join(virtualenv_current_bin_path, "easy_install")
109
+ }
110
+ _cset(:virtualenv_current_easy_install_cmd) { # TODO: remove this
111
+ # execute from :virtualenv_current_python
112
+ # since `virtualenv --relocatable` will not set shebang line with absolute path.
113
+ logger.info(":virtualenv_current_easy_install_cmd has been deprecated.")
116
114
  [
117
- virtualenv_current_python,
118
- virtualenv_current_easy_install,
119
- virtualenv_easy_install_options,
120
- ].flatten.join(' ')
115
+ virtualenv_current_python.dump,
116
+ virtualenv_current_easy_install.dump,
117
+ virtualenv_easy_install_options.map { |x| x.dump }.join(" "),
118
+ ].join(" ")
121
119
  }
122
120
  _cset(:virtualenv_current_pip) {
123
- File.join(virtualenv_current_path, 'bin', 'pip')
121
+ logger.info(":virtualenv_current_pip has been deprecated.")
122
+ File.join(virtualenv_current_path, "bin", "pip")
124
123
  }
125
124
  _cset(:virtualenv_current_pip_cmd) {
125
+ logger.info(":virtualenv_current_pip_cmd has been deprecated.")
126
126
  [
127
- virtualenv_current_python,
128
- virtualenv_current_pip,
129
- virtualenv_pip_options,
130
- ].flatten.join(' ')
127
+ virtualenv_current_python.dump,
128
+ virtualenv_current_pip.dump,
129
+ virtualenv_pip_options.map { |x| x.dump }.join(" "),
130
+ ].flatten.join(" ")
131
131
  }
132
132
 
133
+ _cset(:virtualenv_install_packages, []) # apt packages
134
+ _cset(:virtualenv_setup_dependencies) { not(virtualenv_install_packages.empty?) }
133
135
  desc("Setup virtualenv.")
134
136
  task(:setup, :except => { :no_release => true }) {
135
137
  transaction {
138
+ dependencies if virtualenv_setup_dependencies
136
139
  install
137
140
  create_shared
138
141
  }
139
142
  }
140
- after 'deploy:setup', 'virtualenv:setup'
143
+ after "deploy:setup", "virtualenv:setup"
141
144
 
142
145
  desc("Install virtualenv.")
143
146
  task(:install, :except => { :no_release => true }) {
144
- run("#{sudo} apt-get install #{virtualenv_install_packages.join(' ')}") unless virtualenv_install_packages.empty?
145
- dirs = [ File.dirname(virtualenv_script_file) ].uniq()
146
- run("mkdir -p #{dirs.join(' ')} && ( test -f #{virtualenv_script_file} || wget --no-verbose -O #{virtualenv_script_file} #{virtualenv_script_url} )")
147
+ run("mkdir -p #{File.dirname(virtualenv_script_file).dump}")
148
+ run("test -f #{virtualenv_script_file.dump} || wget --no-verbose -O #{virtualenv_script_file.dump} #{virtualenv_script_url.dump}")
149
+ }
150
+
151
+ task(:dependencies, :except => { :no_release => true }) {
152
+ run("#{sudo} apt-get install #{virtualenv_install_packages.map { |x| x.dump }.join(" ")}")
147
153
  }
148
154
 
149
155
  desc("Uninstall virtualenv.")
150
156
  task(:uninstall, :except => { :no_release => true }) {
151
- run("rm -f #{virtualenv_script_file}")
157
+ run("rm -f #{virtualenv_script_file.dump}")
152
158
  }
153
159
 
160
+ def command(options={})
161
+ [
162
+ virtualenv_bootstrap_python,
163
+ virtualenv_script_file.dump,
164
+ virtualenv_options.map { |x| x.dump }.join(" "),
165
+ ].join(" ")
166
+ end
167
+
168
+ def create(destination, options={})
169
+ execute = []
170
+ execute << "mkdir -p #{File.dirname(destination).dump}"
171
+ execute << "( test -d #{destination.dump} || #{command(options)} #{destination.dump} )"
172
+ invoke_command(execute.join(" && "), options)
173
+ end
174
+
175
+ def destroy(destination, options={})
176
+ invoke_command("rm -rf #{destination.dump}", options)
177
+ end
178
+
154
179
  task(:create_shared, :except => { :no_release => true }) {
155
- dirs = [ File.dirname(virtualenv_shared_path) ].uniq()
156
- cmds = [ ]
157
- cmds << "mkdir -p #{dirs.join(' ')}"
158
- cmds << "( test -d #{virtualenv_shared_path} || #{virtualenv_cmd} #{virtualenv_shared_path} )"
159
- cmds << "( test -x #{virtualenv_shared_pip} || #{virtualenv_shared_easy_install_cmd} #{virtualenv_pip_package} )"
160
- cmds << "#{virtualenv_shared_python} --version && #{virtualenv_shared_pip_cmd} --version"
161
- run(cmds.join(' && '))
180
+ virtualenv.create(virtualenv_shared_path)
162
181
  }
163
182
 
164
183
  task(:destroy_shared, :except => { :no_release => true }) {
165
- run("rm -rf #{virtualenv_shared_path}")
184
+ virtualenv.destroy(virtualenv_shared_path)
166
185
  }
167
186
 
168
187
  desc("Update virtualenv for project.")
@@ -172,40 +191,50 @@ module Capistrano
172
191
  create_release
173
192
  }
174
193
  }
175
- after 'deploy:finalize_update', 'virtualenv:update'
194
+ after "deploy:finalize_update", "virtualenv:update"
176
195
 
177
196
  task(:update_shared, :except => { :no_release => true }) {
178
- unless virtualenv_requirements.empty?
179
- top.safe_put(virtualenv_requirements.join("\n"), virtualenv_requirements_file, :place => :if_modified)
197
+ top.put(virtualenv_requirements.join("\n"), virtualenv_requirements_file) unless virtualenv_requirements.empty?
198
+ run("touch #{virtualenv_requirements_file.dump}")
199
+ pip_options = ( virtualenv_pip_options + virtualenv_pip_install_options ).map { |x| x.dump }.join(" ")
200
+ virtualenv.exec("pip install #{pip_options} -r #{virtualenv_requirements_file.dump}",
201
+ :virtualenv => virtualenv_shared_path)
202
+ virtualenv_build_requirements.each do |package, options|
203
+ options ||= []
204
+ virtualenv.exec("pip install #{pip_options} #{options.map { |x| x.dump }.join(" ")} #{package.dump}",
205
+ :virtualenv => virtualenv_shared_path)
180
206
  end
181
- run("touch #{virtualenv_requirements_file} && #{virtualenv_shared_pip_cmd} install #{virtualenv_pip_install_options.join(' ')} -r #{virtualenv_requirements_file}")
182
-
183
- execute = virtualenv_build_requirements.map { |package, options|
184
- build_options = ( options || [] )
185
- "#{virtualenv_shared_pip_cmd} install #{virtualenv_pip_install_options.join(' ')} #{build_options.join(' ')} #{package.dump}"
186
- }
187
- run(execute.join(' && ')) unless execute.empty?
188
207
  }
189
208
 
190
- task(:create_release, :except => { :no_release => true }) {
191
- dirs = [ File.dirname(virtualenv_release_path) ].uniq()
192
- cmds = [ ]
193
- cmds << "mkdir -p #{dirs.join(' ')}"
209
+ def relocate(source, destination, options={})
210
+ execute = []
211
+ execute << "mkdir -p #{File.dirname(destination).dump}"
194
212
  # TODO: turn :virtualenv_use_relocatable true if it will be an official features.
195
213
  # `virtualenv --relocatable` does not work expectedly as of virtualenv 1.7.2.
196
214
  if fetch(:virtualenv_use_relocatable, false)
197
- cmds << "#{virtualenv_cmd} --relocatable #{virtualenv_shared_path}"
198
- cmds << "cp -RPp #{virtualenv_shared_path} #{virtualenv_release_path}"
215
+ execute << %{#{command(options)} --relocatable #{source.dump}}
216
+ execute << %{cp -RPp #{source.dump} #{destination.dump}}
199
217
  else
200
- cmds << "( test -d #{virtualenv_release_path} || #{virtualenv_cmd} #{virtualenv_release_path} )"
201
- cmds << "( test -x #{virtualenv_release_pip} || #{virtualenv_release_easy_install_cmd} #{virtualenv_pip_package} )"
202
- cmds << "#{virtualenv_release_python} --version && #{virtualenv_release_pip_cmd} --version"
203
- cmds << "rsync -lrpt -u #{virtualenv_shared_path}/bin/ #{virtualenv_release_path}/bin/" # copy binaries and scripts from shared virtualenv
204
- cmds << "sed -i -e 's|^#!#{virtualenv_shared_path}/bin/python.*$|#!#{virtualenv_release_path}/bin/python|' #{virtualenv_release_path}/bin/*"
205
- cmds << "rsync -lrpt #{virtualenv_shared_path}/lib/ #{virtualenv_release_path}/lib/" # copy libraries from shared virtualenv
218
+ execute << %{( test -d #{destination.dump} || #{command(options)} #{destination.dump} )}
219
+ # copy binaries and scripts from shared virtualenv
220
+ execute << %{rsync -lrpt #{File.join(source, "bin/").dump} #{File.join(destination, "bin/").dump}}
221
+ execute << %{sed -i -e 's|^#!#{source}/bin/python.*$|#!#{destination}/bin/python|' #{destination}/bin/*}
222
+ # copy libraries from shared virtualenv
223
+ execute << %{rsync -lrpt #{File.join(source, "lib/").dump} #{File.join(destination, "lib/").dump}}
206
224
  end
207
- run(cmds.join(' && '))
225
+ invoke_command(execute.join(" && "), options)
226
+ end
227
+
228
+ task(:create_release, :except => { :no_release => true }) {
229
+ virtualenv.relocate(virtualenv_shared_path, virtualenv_release_path)
208
230
  }
231
+
232
+ def exec(cmdline, options={})
233
+ options = options.dup
234
+ virtualenv = ( options.delete(:virtualenv) || virtualenv_shared_path )
235
+ options[:env] = options.fetch(:env, {}).merge("PATH" => [ File.join(virtualenv, "bin"), "$PATH" ].join(":"))
236
+ invoke_command(cmdline, options)
237
+ end
209
238
  }
210
239
  }
211
240
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Virtualenv
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /.vagrant
3
+ /known_hosts
4
+ /tmp
5
+ /vendor
@@ -0,0 +1,2 @@
1
+ load "deploy"
2
+ load "../config/deploy"
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec(:path => "../..")
@@ -0,0 +1,99 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "centos6-64"
11
+
12
+ # The url from where the 'config.vm.box' box will be fetched if it
13
+ # doesn't already exist on the user's system.
14
+ config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.3-x86_64-v20130101.box"
15
+
16
+ # Boot with a GUI so you can see the screen. (Default is headless)
17
+ # config.vm.boot_mode = :gui
18
+
19
+ # Assign this VM to a host-only network IP, allowing you to access it
20
+ # via the IP. Host-only networks can talk to the host machine as well as
21
+ # any other machines on the same network, but cannot be accessed (through this
22
+ # network interface) by any external networks.
23
+ config.vm.network :hostonly, "192.168.33.10"
24
+
25
+ # Assign this VM to a bridged network, allowing you to connect directly to a
26
+ # network using the host's network device. This makes the VM appear as another
27
+ # physical device on your network.
28
+ # config.vm.network :bridged
29
+
30
+ # Forward a port from the guest to the host, which allows for outside
31
+ # computers to access the VM, whereas host only networking does not.
32
+ # config.vm.forward_port 80, 8080
33
+
34
+ # Share an additional folder to the guest VM. The first argument is
35
+ # an identifier, the second is the path on the guest to mount the
36
+ # folder, and the third is the path on the host to the actual folder.
37
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
38
+
39
+ # Enable provisioning with Puppet stand alone. Puppet manifests
40
+ # are contained in a directory path relative to this Vagrantfile.
41
+ # You will need to create the manifests directory and a manifest in
42
+ # the file precise-amd64.pp in the manifests_path directory.
43
+ #
44
+ # An example Puppet manifest to provision the message of the day:
45
+ #
46
+ # # group { "puppet":
47
+ # # ensure => "present",
48
+ # # }
49
+ # #
50
+ # # File { owner => 0, group => 0, mode => 0644 }
51
+ # #
52
+ # # file { '/etc/motd':
53
+ # # content => "Welcome to your Vagrant-built virtual machine!
54
+ # # Managed by Puppet.\n"
55
+ # # }
56
+ #
57
+ # config.vm.provision :puppet do |puppet|
58
+ # puppet.manifests_path = "manifests"
59
+ # puppet.manifest_file = "precise-amd64.pp"
60
+ # end
61
+
62
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
63
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
64
+ # some recipes and/or roles.
65
+ #
66
+ # config.vm.provision :chef_solo do |chef|
67
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
68
+ # chef.roles_path = "../my-recipes/roles"
69
+ # chef.data_bags_path = "../my-recipes/data_bags"
70
+ # chef.add_recipe "mysql"
71
+ # chef.add_role "web"
72
+ #
73
+ # # You may also specify custom JSON attributes:
74
+ # chef.json = { :mysql_password => "foo" }
75
+ # end
76
+
77
+ # Enable provisioning with chef server, specifying the chef server URL,
78
+ # and the path to the validation key (relative to this Vagrantfile).
79
+ #
80
+ # The Opscode Platform uses HTTPS. Substitute your organization for
81
+ # ORGNAME in the URL and validation key.
82
+ #
83
+ # If you have your own Chef Server, use the appropriate URL, which may be
84
+ # HTTP instead of HTTPS depending on your configuration. Also change the
85
+ # validation key to validation.pem.
86
+ #
87
+ # config.vm.provision :chef_client do |chef|
88
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
89
+ # chef.validation_key_path = "ORGNAME-validator.pem"
90
+ # end
91
+ #
92
+ # If you're using the Opscode platform, your validator client is
93
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
94
+ #
95
+ # IF you have your own Chef Server, the default validation client name is
96
+ # chef-validator, unless you changed the configuration.
97
+ #
98
+ # chef.validation_client_name = "ORGNAME-validator"
99
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh -e
2
+
3
+ bundle exec vagrant up
4
+ bundle exec cap test_all
5
+ bundle exec vagrant halt
6
+
7
+ # vim:set ft=sh :
@@ -0,0 +1,149 @@
1
+ set :application, "capistrano-virtualenv"
2
+ set :repository, "."
3
+ set :deploy_to do
4
+ File.join("/home", user, application)
5
+ end
6
+ set :deploy_via, :copy
7
+ set :scm, :none
8
+ set :use_sudo, false
9
+ set :user, "vagrant"
10
+ set :password, "vagrant"
11
+ set :ssh_options, {:user_known_hosts_file => "/dev/null"}
12
+
13
+ role :web, "192.168.33.10"
14
+ role :app, "192.168.33.10"
15
+ role :db, "192.168.33.10", :primary => true
16
+
17
+ $LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
18
+ require "capistrano-virtualenv"
19
+
20
+ def _invoke_command(cmdline, options={})
21
+ if options[:via] == :run_locally
22
+ run_locally(cmdline)
23
+ else
24
+ invoke_command(cmdline, options)
25
+ end
26
+ end
27
+
28
+ def assert_file_exists(file, options={})
29
+ begin
30
+ _invoke_command("test -f #{file.dump}", options)
31
+ rescue
32
+ logger.debug("assert_file_exists(#{file}) failed.")
33
+ _invoke_command("ls #{File.dirname(file).dump}", options)
34
+ raise
35
+ end
36
+ end
37
+
38
+ def assert_file_not_exists(file, options={})
39
+ begin
40
+ _invoke_command("test \! -f #{file.dump}", options)
41
+ rescue
42
+ logger.debug("assert_file_not_exists(#{file}) failed.")
43
+ _invoke_command("ls #{File.dirname(file).dump}", options)
44
+ raise
45
+ end
46
+ end
47
+
48
+ def assert_command(cmdline, options={})
49
+ begin
50
+ _invoke_command(cmdline, options)
51
+ rescue
52
+ logger.debug("assert_command(#{cmdline}) failed.")
53
+ raise
54
+ end
55
+ end
56
+
57
+ def assert_command_fails(cmdline, options={})
58
+ failed = false
59
+ begin
60
+ _invoke_command(cmdline, options)
61
+ rescue
62
+ logger.debug("assert_command_fails(#{cmdline}) failed.")
63
+ failed = true
64
+ ensure
65
+ abort unless failed
66
+ end
67
+ end
68
+
69
+ def reset_virtualenv!
70
+ variables.each_key do |key|
71
+ reset!(key) if /^virtualenv_/ =~ key
72
+ end
73
+ end
74
+
75
+ def uninstall_virtualenv!
76
+ run("rm -rf #{virtualenv_shared_path.dump}")
77
+ run("rm -rf #{virtualenv_release_path.dump}")
78
+ end
79
+
80
+ task(:test_all) {
81
+ find_and_execute_task("test_default")
82
+ }
83
+
84
+ on(:start) {
85
+ run("rm -rf #{deploy_to.dump}")
86
+ }
87
+
88
+ namespace(:test_default) {
89
+ task(:default) {
90
+ methods.grep(/^test_/).each do |m|
91
+ send(m)
92
+ end
93
+ }
94
+ before "test_default", "test_default:setup"
95
+ after "test_default", "test_default:teardown"
96
+
97
+ task(:setup) {
98
+ uninstall_virtualenv!
99
+ set(:virtualenv_requirements, %w(simplejson))
100
+ reset_virtualenv!
101
+ find_and_execute_task("deploy:setup")
102
+ }
103
+
104
+ task(:teardown) {
105
+ }
106
+
107
+ task(:test_deploy) {
108
+ assert_command("#{virtualenv_shared_python} --version")
109
+ assert_command_fails("echo null | #{virtualenv_shared_python} -m simplejson.tool")
110
+ find_and_execute_task("deploy")
111
+ assert_command("#{virtualenv_release_python} --version")
112
+ assert_command("echo null | #{virtualenv_release_python} -m simplejson.tool")
113
+ assert_command("#{virtualenv_current_python} --version")
114
+ assert_command("echo null | #{virtualenv_current_python} -m simplejson.tool")
115
+ }
116
+
117
+ task(:test_redeploy) {
118
+ assert_command("#{virtualenv_shared_python} --version")
119
+ assert_command("echo null | #{virtualenv_shared_python} -m simplejson.tool")
120
+ variables.each_key do |key|
121
+ reset!(key)
122
+ end
123
+ find_and_execute_task("deploy")
124
+ assert_command("#{virtualenv_release_python} --version")
125
+ assert_command("echo null | #{virtualenv_release_python} -m simplejson.tool")
126
+ assert_command("#{virtualenv_current_python} --version")
127
+ assert_command("echo null | #{virtualenv_current_python} -m simplejson.tool")
128
+ }
129
+
130
+ task(:test_rollback) {
131
+ assert_command("#{virtualenv_shared_python} --version")
132
+ assert_command("echo null | #{virtualenv_shared_python} -m simplejson.tool")
133
+ variables.each_key do |key|
134
+ reset!(key)
135
+ end
136
+ find_and_execute_task("deploy:rollback")
137
+ assert_command_fails("#{virtualenv_release_python} --version")
138
+ assert_command_fails("echo null | #{virtualenv_release_python} -m simplejson.tool")
139
+ assert_command("#{virtualenv_current_python} --version")
140
+ assert_command("echo null | #{virtualenv_current_python} -m simplejson.tool")
141
+ }
142
+
143
+ task(:test_virtualenv_exec) {
144
+ virtualenv.exec("python --version", :virtualenv => virtualenv_shared_path)
145
+ virtualenv.exec("python --version", :virtualenv => virtualenv_current_path)
146
+ }
147
+ }
148
+
149
+ # vim:set ft=ruby sw=2 ts=2 :
@@ -0,0 +1 @@
1
+ credentials += Credentials("My Repository", "repository.example.com", "username", "password")
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /.vagrant
3
+ /known_hosts
4
+ /tmp
5
+ /vendor
@@ -0,0 +1,2 @@
1
+ load "deploy"
2
+ load "../config/deploy"
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec(:path => "../..")
@@ -0,0 +1,99 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "precise64"
11
+
12
+ # The url from where the 'config.vm.box' box will be fetched if it
13
+ # doesn't already exist on the user's system.
14
+ config.vm.box_url = "http://files.vagrantup.com/precise64.box"
15
+
16
+ # Boot with a GUI so you can see the screen. (Default is headless)
17
+ # config.vm.boot_mode = :gui
18
+
19
+ # Assign this VM to a host-only network IP, allowing you to access it
20
+ # via the IP. Host-only networks can talk to the host machine as well as
21
+ # any other machines on the same network, but cannot be accessed (through this
22
+ # network interface) by any external networks.
23
+ config.vm.network :hostonly, "192.168.33.10"
24
+
25
+ # Assign this VM to a bridged network, allowing you to connect directly to a
26
+ # network using the host's network device. This makes the VM appear as another
27
+ # physical device on your network.
28
+ # config.vm.network :bridged
29
+
30
+ # Forward a port from the guest to the host, which allows for outside
31
+ # computers to access the VM, whereas host only networking does not.
32
+ # config.vm.forward_port 80, 8080
33
+
34
+ # Share an additional folder to the guest VM. The first argument is
35
+ # an identifier, the second is the path on the guest to mount the
36
+ # folder, and the third is the path on the host to the actual folder.
37
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
38
+
39
+ # Enable provisioning with Puppet stand alone. Puppet manifests
40
+ # are contained in a directory path relative to this Vagrantfile.
41
+ # You will need to create the manifests directory and a manifest in
42
+ # the file precise-amd64.pp in the manifests_path directory.
43
+ #
44
+ # An example Puppet manifest to provision the message of the day:
45
+ #
46
+ # # group { "puppet":
47
+ # # ensure => "present",
48
+ # # }
49
+ # #
50
+ # # File { owner => 0, group => 0, mode => 0644 }
51
+ # #
52
+ # # file { '/etc/motd':
53
+ # # content => "Welcome to your Vagrant-built virtual machine!
54
+ # # Managed by Puppet.\n"
55
+ # # }
56
+ #
57
+ # config.vm.provision :puppet do |puppet|
58
+ # puppet.manifests_path = "manifests"
59
+ # puppet.manifest_file = "precise-amd64.pp"
60
+ # end
61
+
62
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
63
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
64
+ # some recipes and/or roles.
65
+ #
66
+ # config.vm.provision :chef_solo do |chef|
67
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
68
+ # chef.roles_path = "../my-recipes/roles"
69
+ # chef.data_bags_path = "../my-recipes/data_bags"
70
+ # chef.add_recipe "mysql"
71
+ # chef.add_role "web"
72
+ #
73
+ # # You may also specify custom JSON attributes:
74
+ # chef.json = { :mysql_password => "foo" }
75
+ # end
76
+
77
+ # Enable provisioning with chef server, specifying the chef server URL,
78
+ # and the path to the validation key (relative to this Vagrantfile).
79
+ #
80
+ # The Opscode Platform uses HTTPS. Substitute your organization for
81
+ # ORGNAME in the URL and validation key.
82
+ #
83
+ # If you have your own Chef Server, use the appropriate URL, which may be
84
+ # HTTP instead of HTTPS depending on your configuration. Also change the
85
+ # validation key to validation.pem.
86
+ #
87
+ # config.vm.provision :chef_client do |chef|
88
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
89
+ # chef.validation_key_path = "ORGNAME-validator.pem"
90
+ # end
91
+ #
92
+ # If you're using the Opscode platform, your validator client is
93
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
94
+ #
95
+ # IF you have your own Chef Server, the default validation client name is
96
+ # chef-validator, unless you changed the configuration.
97
+ #
98
+ # chef.validation_client_name = "ORGNAME-validator"
99
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh -e
2
+
3
+ bundle exec vagrant up
4
+ bundle exec cap test_all
5
+ bundle exec vagrant halt
6
+
7
+ # vim:set ft=sh :
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-virtualenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -28,21 +28,53 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: capistrano-file-transfer-ext
31
+ name: net-scp
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.0.3
38
- type: :runtime
37
+ version: 1.0.4
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: net-ssh
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.2.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: vagrant
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.6
70
+ type: :development
39
71
  prerelease: false
40
72
  version_requirements: !ruby/object:Gem::Requirement
41
73
  none: false
42
74
  requirements:
43
75
  - - ~>
44
76
  - !ruby/object:Gem::Version
45
- version: 0.0.3
77
+ version: 1.0.6
46
78
  description: a capistrano recipe to deploy python apps with virtualenv.
47
79
  email:
48
80
  - yamashita@geishatokyo.com
@@ -58,6 +90,18 @@ files:
58
90
  - capistrano-virtualenv.gemspec
59
91
  - lib/capistrano-virtualenv.rb
60
92
  - lib/capistrano-virtualenv/version.rb
93
+ - test/centos6-64/.gitignore
94
+ - test/centos6-64/Capfile
95
+ - test/centos6-64/Gemfile
96
+ - test/centos6-64/Vagrantfile
97
+ - test/centos6-64/run.sh
98
+ - test/config/deploy.rb
99
+ - test/config/templates/global.sbt.erb
100
+ - test/precise64/.gitignore
101
+ - test/precise64/Capfile
102
+ - test/precise64/Gemfile
103
+ - test/precise64/Vagrantfile
104
+ - test/precise64/run.sh
61
105
  homepage: https://github.com/yyuu/capistrano-virtualenv
62
106
  licenses: []
63
107
  post_install_message:
@@ -82,4 +126,16 @@ rubygems_version: 1.8.23
82
126
  signing_key:
83
127
  specification_version: 3
84
128
  summary: a capistrano recipe to deploy python apps with virtualenv.
85
- test_files: []
129
+ test_files:
130
+ - test/centos6-64/.gitignore
131
+ - test/centos6-64/Capfile
132
+ - test/centos6-64/Gemfile
133
+ - test/centos6-64/Vagrantfile
134
+ - test/centos6-64/run.sh
135
+ - test/config/deploy.rb
136
+ - test/config/templates/global.sbt.erb
137
+ - test/precise64/.gitignore
138
+ - test/precise64/Capfile
139
+ - test/precise64/Gemfile
140
+ - test/precise64/Vagrantfile
141
+ - test/precise64/run.sh