capistrano-virtualenv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-virtualenv.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yamashita Yuu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # capistrano-virtualenv
2
+
3
+ a capistrano recipe to deploy python apps with [virtualenv](http://pypi.python.org/pypi/virtualenv).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-virtualenv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-virtualenv
18
+
19
+ ## Usage
20
+
21
+ This recipe will create 2 kind of virtualenv during `deploy` task.
22
+
23
+ * shared virtualenv
24
+ * created in `shared_path` after `deploy:setup`
25
+ * common libraries are installed here.
26
+ * release virtualenv
27
+ * created in `release_path` after `deploy:finalize_update`
28
+ * per-release virtualenv that can be rolled back.
29
+
30
+ To deploy your application with `virtualenv`, add following in you `config/deploy.rb`.
31
+
32
+ # in "config/deploy.rb"
33
+ require 'capistrano-virtualenv'
34
+
35
+ Following options are available to manage your virtualenv.
36
+
37
+ * `:virtualenv_bootstrap_python` - the python executable which will be used to craete virtualenv. by default "python".
38
+ * `:virtualenv_current_path` - virtualenv path under `:current_path`.
39
+ * `:virtualenv_current_python` - python path under `:virtualenv_current_path`.
40
+ * `:virtualenv_easy_install_options` - options for `easy_install`. by defaul "--quiet".
41
+ * `:virtualenv_install_packages` - apt packages dependencies for python.
42
+ * `:virtualenv_pip_options` - options for `pip`. by default "--quiet".
43
+ * `:virtualenv_release_path` - virtualenv path under `:release_path`.
44
+ * `:virtualenv_release_python` - python path under `:virtualenv_release_path`.
45
+ * `:virtualenv_requirements` - the list of `pip` packages should be installed to `virtualenv`.
46
+ * `:virtualenv_requirements_file` - the path to the file that describes library dependencies. by default "requirements.txt".
47
+ * `:virtualenv_script_url` - the download URL of `virtualenv.py`.
48
+ * `:virtualenv_shared_path` - virtualenv path under `:shared_path`.
49
+ * `:virtualenv_shared_python` - python path under `:virtualenv_shared_path`
50
+ * `:virtualenv_use_system` - controls whether virtualenv should be use system packages or not. false by default.
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
59
+
60
+ ## Author
61
+
62
+ - YAMASHITA Yuu (https://github.com/yyuu)
63
+ - Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
64
+
65
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano-virtualenv/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yamashita Yuu"]
6
+ gem.email = ["yamashita@geishatokyo.com"]
7
+ gem.description = %q{a capistrano recipe to deploy python apps with virtualenv.}
8
+ gem.summary = %q{a capistrano recipe to deploy python apps with virtualenv.}
9
+ gem.homepage = "https://github.com/yyuu/capistrano-virtualenv"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-virtualenv"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::Virtualenv::VERSION
17
+
18
+ gem.add_dependency("capistrano")
19
+ end
@@ -0,0 +1,8 @@
1
+ require "capistrano-virtualenv/deploy"
2
+ require "capistrano-virtualenv/version"
3
+
4
+ module Capistrano
5
+ module Virtualenv
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,165 @@
1
+
2
+ require 'tempfile'
3
+ require 'uri'
4
+
5
+ module Capistrano
6
+ module Virtualenv
7
+ def self.extended(configuration)
8
+ configuration.load {
9
+ namespace(:virtualenv) {
10
+ _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))
31
+ _cset(:virtualenv_pip_package, 'pip')
32
+ _cset(:virtualenv_requirements, []) # primary package list
33
+ _cset(:virtualenv_requirements_file) { # secondary package list
34
+ File.join(release_path, 'requirements.txt')
35
+ }
36
+ _cset(:virtualenv_install_packages, []) # apt packages
37
+
38
+ ## shared virtualenv:
39
+ ## - created in shared_path
40
+ ## - to be used to share libs between releases
41
+ _cset(:virtualenv_shared_path) {
42
+ File.join(shared_path, 'virtualenv', 'shared')
43
+ }
44
+ _cset(:virtualenv_shared_python) {
45
+ File.join(virtualenv_shared_path, 'bin', 'python')
46
+ }
47
+ _cset(:virtualenv_shared_easy_install) {
48
+ File.join(virtualenv_shared_path, 'bin', 'easy_install')
49
+ }
50
+ _cset(:virtualenv_shared_pip) {
51
+ File.join(virtualenv_shared_path, 'bin', 'pip')
52
+ }
53
+
54
+ ## release virtualenv
55
+ ## - created in release_path
56
+ ## - common libs are copied from shared virtualenv
57
+ ## - will be used for running application
58
+ _cset(:virtualenv_release_path) { # the path where runtime virtualenv will be created
59
+ File.join(release_path, 'vendor', 'virtualenv')
60
+ }
61
+ _cset(:virtualenv_release_python) { # the python executable within virtualenv
62
+ File.join(virtualenv_release_path, 'bin', 'python')
63
+ }
64
+ _cset(:virtualenv_release_easy_install) {
65
+ File.join(virtualenv_release_path, 'bin', 'easy_install')
66
+ }
67
+ _cset(:virtualenv_release_pip) {
68
+ File.join(virtualenv_release_path, 'bin', 'pip')
69
+ }
70
+
71
+ ## current virtualenv
72
+ ## - placed in current_path
73
+ ## - virtualenv of currently running application
74
+ _cset(:virtualenv_current_path) {
75
+ File.join(current_path, 'vendor', 'virtualenv')
76
+ }
77
+ _cset(:virtualenv_current_python) {
78
+ File.join(virtualenv_current_path, 'bin', 'python')
79
+ }
80
+ _cset(:virtualenv_current_easy_install) {
81
+ File.join(virtualenv_current_path, 'bin', 'easy_install')
82
+ }
83
+ _cset(:virtualenv_current_pip) {
84
+ File.join(virtualenv_current_path, 'bin', 'pip')
85
+ }
86
+
87
+ desc("Setup virtualenv.")
88
+ task(:setup, :except => { :no_release => true }) {
89
+ transaction {
90
+ install
91
+ create_shared
92
+ }
93
+ }
94
+ after 'deploy:setup', 'virtualenv:setup'
95
+
96
+ desc("Install virtualenv.")
97
+ task(:install, :except => { :no_release => true }) {
98
+ run("#{sudo} apt-get install #{virtualenv_install_packages.join(' ')}") unless virtualenv_install_packages.empty?
99
+ dirs = [ File.dirname(virtualenv_script_file) ].uniq()
100
+ run("mkdir -p #{dirs.join(' ')} && ( test -f #{virtualenv_script_file} || wget --no-verbose -O #{virtualenv_script_file} #{virtualenv_script_url} )")
101
+ }
102
+
103
+ desc("Uninstall virtualenv.")
104
+ task(:uninstall, :except => { :no_release => true }) {
105
+ run("rm -f #{virtualenv_script_file}")
106
+ }
107
+
108
+ task(:create_shared, :except => { :no_release => true }) {
109
+ dirs = [ File.dirname(virtualenv_shared_path) ].uniq()
110
+ cmds = [ ]
111
+ cmds << "mkdir -p #{dirs.join(' ')}"
112
+ cmds << "( test -d #{virtualenv_shared_path} || #{virtualenv_cmd} #{virtualenv_shared_path} )"
113
+ cmds << "( test -x #{virtualenv_shared_pip} || #{virtualenv_shared_easy_install} #{virtualenv_easy_install_options.join(' ')} #{virtualenv_pip_package} )"
114
+ cmds << "#{virtualenv_shared_python} --version && #{virtualenv_shared_pip} --version"
115
+ run(cmds.join(' && '))
116
+ }
117
+
118
+ task(:destroy_shared, :except => { :no_release => true }) {
119
+ run("rm -rf #{virtualenv_shared_path}")
120
+ }
121
+
122
+ desc("Update virtualenv for project.")
123
+ task(:update, :except => { :no_release => true }) {
124
+ transaction {
125
+ update_shared
126
+ create_release
127
+ }
128
+ }
129
+ after 'deploy:finalize_update', 'virtualenv:update'
130
+
131
+ task(:update_shared, :except => { :no_release => true }) {
132
+ unless virtualenv_requirements.empty?
133
+ tempfile = Tempfile.new(File.basename($0))
134
+ top.put(virtualenv_requirements.join("\n"), tempfile.path)
135
+ run("diff -u #{virtualenv_requirements_file} #{tempfile.path} || mv -f #{tempfile.path} #{virtualenv_requirements_file}; rm -f #{tempfile.path}")
136
+ end
137
+ run("touch #{virtualenv_requirements_file} && #{virtualenv_shared_pip} #{virtualenv_pip_options.join(' ')} install -r #{virtualenv_requirements_file}")
138
+ }
139
+
140
+ task(:create_release, :except => { :no_release => true }) {
141
+ dirs = [ File.dirname(virtualenv_release_path) ].uniq()
142
+ cmds = [ ]
143
+ cmds << "mkdir -p #{dirs.join(' ')}"
144
+ if fetch(:virtualenv_use_relocatable, false) # "--relocatable" does not work expectedly on virtualenv 1.7.2
145
+ cmds << "#{virtualenv_cmd} --relocatable #{virtualenv_shared_path}"
146
+ cmds << "cp -RPp #{virtualenv_shared_path} #{virtualenv_release_path}"
147
+ else
148
+ cmds << "( test -d #{virtualenv_release_path} || #{virtualenv_cmd} #{virtualenv_release_path} )"
149
+ cmds << "( test -x #{virtualenv_release_pip} || #{virtualenv_release_easy_install} #{virtualenv_easy_install_options.join(' ')} #{virtualenv_pip_package} )"
150
+ cmds << "#{virtualenv_release_python} --version && #{virtualenv_release_pip} --version"
151
+ cmds << "rsync -lrpt #{virtualenv_shared_path}/lib/ #{virtualenv_release_path}/lib/" # copy libraries from shared virtualenv
152
+ end
153
+ run(cmds.join(' && '))
154
+ }
155
+ }
156
+ }
157
+ end
158
+ end
159
+ end
160
+
161
+ if Capistrano::Configuration.instance
162
+ Capistrano::Configuration.instance.extend(Capistrano::Virtualenv)
163
+ end
164
+
165
+ # vim:set ft=ruby :
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Virtualenv
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-virtualenv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yamashita Yuu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: a capistrano recipe to deploy python apps with virtualenv.
31
+ email:
32
+ - yamashita@geishatokyo.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - capistrano-virtualenv.gemspec
43
+ - lib/capistrano-virtualenv.rb
44
+ - lib/capistrano-virtualenv/deploy.rb
45
+ - lib/capistrano-virtualenv/version.rb
46
+ homepage: https://github.com/yyuu/capistrano-virtualenv
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: a capistrano recipe to deploy python apps with virtualenv.
70
+ test_files: []
71
+ has_rdoc: