capistrano-deploy-strategy-archive 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +1 -0
- data/capistrano-deploy-strategy-archive.gemspec +18 -0
- data/lib/capistrano/recipes/deploy/strategy/archive.rb +101 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Simo Kinnunen
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# capistrano-deploy-strategy-archive
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
**capistrano-deploy-strategy-archive** provides a simple archive strategy for [Capistrano](https://github.com/capistrano/capistrano). The strategy takes an existing, pre-built package, copies it as-is to each target host and uncompresses it to the release directory.
|
6
|
+
|
7
|
+
While normally discouraged, you'll usually want to use the :none SCM with this strategy (or for even less overhead, the :passthrough SCM from [capistrano-deploy-scm-passthrough](https://rubygems.org/gems/capistrano-deploy-scm-passthrough)).
|
8
|
+
|
9
|
+
You'll see the most benefit if you've got a build server cranking out builds for you, which you then later deploy. You'll often want to separate the build phase from the deploy phase in production. If necessary, you can of course use `capistrano/ext/multistage` to do `:archive` deploys for, say, production only.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Simply install the gem and you're done:
|
14
|
+
|
15
|
+
gem install capistrano-deploy-strategy-archive
|
16
|
+
|
17
|
+
No other setup is needed.
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Set your options as follows:
|
22
|
+
|
23
|
+
**deploy.rb**
|
24
|
+
|
25
|
+
set :scm, :none
|
26
|
+
set :deploy_via, :archive
|
27
|
+
set :repository, "target/#{application}.tar.gz"
|
28
|
+
|
29
|
+
Note that we've set the `:repository` option to match the target archive.
|
30
|
+
|
31
|
+
If you'd like to have as little overhead as possible, consider using the [:passthrough](https://rubygems.org/gems/capistrano-deploy-scm-passthrough) SCM:
|
32
|
+
|
33
|
+
**deploy.rb**
|
34
|
+
|
35
|
+
set :scm, :passthrough
|
36
|
+
set :deploy_via, :archive
|
37
|
+
set :repository, "target/#{application}.tar.gz"
|
38
|
+
|
39
|
+
This will transfer the archive directly, without any local copies being made. The `:none` strategy actually creates a local copy, which is usually not what you want if you've already got a package made.
|
40
|
+
|
41
|
+
Note: if your archive is not a gzipped tar archive, you must set the `:copy_compression` option. The currently available options are `:gzip` (default), `:bz2`, and `:zip`. Please use `cap deploy:check` to check if your servers have the necessary decompressors installed.
|
42
|
+
|
43
|
+
You can also set the `:copy_remote_dir` option to control where the package is initially transferred to on each host.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
Copyright (c) 2013 Simo Kinnunen
|
48
|
+
|
49
|
+
MIT License
|
50
|
+
|
51
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
52
|
+
a copy of this software and associated documentation files (the
|
53
|
+
"Software"), to deal in the Software without restriction, including
|
54
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
55
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
56
|
+
permit persons to whom the Software is furnished to do so, subject to
|
57
|
+
the following conditions:
|
58
|
+
|
59
|
+
The above copyright notice and this permission notice shall be
|
60
|
+
included in all copies or substantial portions of the Software.
|
61
|
+
|
62
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
63
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
64
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
65
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
66
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
67
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
68
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "capistrano-deploy-strategy-archive"
|
5
|
+
gem.version = "0.1.1"
|
6
|
+
gem.authors = ["Simo Kinnunen"]
|
7
|
+
gem.email = ["simo@shoqolate.com"]
|
8
|
+
gem.homepage = "https://github.com/sorccu/capistrano-deploy-strategy-archive"
|
9
|
+
gem.summary = %q{Archive deploy strategy for Capistrano.}
|
10
|
+
gem.description = %q{Provides an :archive deploy strategy for Capistrano. It takes an existing, pre-built archive and deploys it as-is. Useful when you've got a server making builds for you, which you then later deploy.}
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($/)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_dependency('capistrano', '>=2.1.0')
|
18
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'capistrano/recipes/deploy/strategy/base'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Deploy
|
5
|
+
module Strategy
|
6
|
+
|
7
|
+
# This class implements a strategy for deployments with prebuilt
|
8
|
+
# packages. It copies the package to each target host and uncompresses
|
9
|
+
# it to the release directory. While normally discouraged, you
|
10
|
+
# usually want to use the :none SCM with this strategy (or for even less
|
11
|
+
# overhead, the :passthrough SCM from capistrano-deploy-scm-passthrough).
|
12
|
+
# You'll also need to set :repository to the target archive.
|
13
|
+
#
|
14
|
+
# set :scm, :none
|
15
|
+
# set :deploy_via, :archive
|
16
|
+
# set :repository, "target/#{application}.tar.gz"
|
17
|
+
#
|
18
|
+
# This strategy is meant to be a drop-in replacement for the :copy
|
19
|
+
# strategy, and supports all the same configuration variables EXCEPT
|
20
|
+
# those that deal with creating the package. For example,
|
21
|
+
# :build_script and :copy_exclude are not supported.
|
22
|
+
#
|
23
|
+
# This deployment strategy also supports a special variable,
|
24
|
+
# :copy_compression, which must be one of :gzip, :bz2, or
|
25
|
+
# :zip, and which specifies how the package should be decompressed on
|
26
|
+
# each host.
|
27
|
+
class Archive < Base
|
28
|
+
# Copies the package to all target servers, and uncompresses it on
|
29
|
+
# each of them into the deployment directory.
|
30
|
+
def deploy!
|
31
|
+
distribute!
|
32
|
+
end
|
33
|
+
|
34
|
+
# Check dependencies.
|
35
|
+
def check!
|
36
|
+
super.check do |d|
|
37
|
+
d.remote.command(decompress(nil).first)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# Returns the name of the file that the source code will be
|
44
|
+
# compressed to.
|
45
|
+
def filename
|
46
|
+
@filename ||= File.expand_path(configuration[:repository], Dir.pwd)
|
47
|
+
end
|
48
|
+
|
49
|
+
# The directory on the remote server to which the archive should be
|
50
|
+
# copied
|
51
|
+
def remote_dir
|
52
|
+
@remote_dir ||= configuration[:copy_remote_dir] || "/tmp"
|
53
|
+
end
|
54
|
+
|
55
|
+
# The location on the remote server where the file should be
|
56
|
+
# temporarily stored.
|
57
|
+
def remote_filename
|
58
|
+
@remote_filename ||= File.join(remote_dir, "#{File.basename(configuration[:release_name])}.#{compression.extension}")
|
59
|
+
end
|
60
|
+
|
61
|
+
# A struct for representing the specifics of a compression type.
|
62
|
+
# Commands are arrays, where the first element is the utility to be
|
63
|
+
# used to perform the compression or decompression.
|
64
|
+
Compression = Struct.new(:extension, :decompress_command)
|
65
|
+
|
66
|
+
# The compression method to use, defaults to :gzip.
|
67
|
+
def compression
|
68
|
+
remote_tar = configuration[:copy_remote_tar] || 'tar'
|
69
|
+
remote_unzip = configuration[:copy_remote_unzip] || 'unzip'
|
70
|
+
|
71
|
+
type = configuration[:copy_compression] || :gzip
|
72
|
+
case type
|
73
|
+
when :gzip, :gz then Compression.new("tar.gz", [remote_tar, 'xzf'])
|
74
|
+
when :bzip2, :bz2 then Compression.new("tar.bz2", [remote_tar, 'xjf'])
|
75
|
+
when :zip then Compression.new("zip", [remote_unzip, '-q'])
|
76
|
+
else raise ArgumentError, "invalid compression type #{type.inspect}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the command necessary to decompress the given file,
|
81
|
+
# relative to the current working directory. It must also
|
82
|
+
# preserve the directory structure in the file.
|
83
|
+
def decompress(file)
|
84
|
+
compression.decompress_command + [file]
|
85
|
+
end
|
86
|
+
|
87
|
+
# Decompress the package on the remote host.
|
88
|
+
def decompress_remote_file
|
89
|
+
run "mkdir #{configuration[:release_path]} && cd #{configuration[:release_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
|
90
|
+
end
|
91
|
+
|
92
|
+
# Distributes the file to the remote hosts.
|
93
|
+
def distribute!
|
94
|
+
upload(filename, remote_filename)
|
95
|
+
decompress_remote_file
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-deploy-strategy-archive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simo Kinnunen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-20 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: 2.1.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: 2.1.0
|
30
|
+
description: Provides an :archive deploy strategy for Capistrano. It takes an existing,
|
31
|
+
pre-built archive and deploys it as-is. Useful when you've got a server making builds
|
32
|
+
for you, which you then later deploy.
|
33
|
+
email:
|
34
|
+
- simo@shoqolate.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- capistrano-deploy-strategy-archive.gemspec
|
45
|
+
- lib/capistrano/recipes/deploy/strategy/archive.rb
|
46
|
+
homepage: https://github.com/sorccu/capistrano-deploy-strategy-archive
|
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.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Archive deploy strategy for Capistrano.
|
70
|
+
test_files: []
|