capistrano-archive 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +118 -0
- data/capistrano-archive.gemspec +23 -0
- data/lib/capistrano/archive.rb +1 -0
- data/lib/capistrano/archive/scm.rb +104 -0
- data/lib/capistrano/archive/tasks/archive.rake +44 -0
- data/lib/capistrano/archive/version.rb +8 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96b7849b39d712939f1ae0f6ceddb6387b8fcc22632d1f25631acbc151baae17
|
4
|
+
data.tar.gz: 4f6b81d6b51c2f3d1b71194b53f96a513698d472abd602e3291ebbb1d2461af4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a1f0c749f8ec2f67d9789c926e2920a1d4b46254436d92acf7b5a9a20b6c9ee9ae0833250e9d61dff7bd94dbd401f8153b505d70387ee4008b0935f72e33ee1
|
7
|
+
data.tar.gz: 7219e2a539144cc24ad648fdf81153a72392d5ae4e4e7824cacdf79bce0db1357119e990885f5aa0a702327443515a71ea867c9aa115369832eec63dc3447c2c
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 PrestaConcept
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# capistrano-archive
|
2
|
+
|
3
|
+
This plugin adds a new scm to Capistrano 3 allowing deployment from an archive stored on the target server (s).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* Upload an archive (tar.bz2 as default) to target
|
8
|
+
* Create release from the archive
|
9
|
+
* Can use a file from the archive to know the deployed revision (./REVISION as default)
|
10
|
+
* Workflow between deploy stages copying the local archive on stage directory
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Put this in the Gemfile
|
15
|
+
```
|
16
|
+
gem 'capistrano-archive'
|
17
|
+
```
|
18
|
+
|
19
|
+
Then run
|
20
|
+
```
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
Add theses lines to your Capfile
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Include and use capistrano archive
|
28
|
+
require "capistrano/archive"
|
29
|
+
install_plugin Capistrano::Archive::SCM
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
First, you need to have a build system storing artefact release on the server used to deploy.
|
35
|
+
|
36
|
+
### Archive location and name
|
37
|
+
|
38
|
+
To specify the archive location, you can set the `:archive_release_path` variable. As default, the archive is supposed to be stored in the current directory.
|
39
|
+
|
40
|
+
The archive name is built as `:application_:branch` but you can change that with the `:archive_name` variable.
|
41
|
+
|
42
|
+
### Compression
|
43
|
+
|
44
|
+
The tar is compressed with bzip as default but you can change that with `:archive_extension` and `:archive_tar_options` variables.
|
45
|
+
|
46
|
+
### Upload
|
47
|
+
|
48
|
+
As default the archive is sent in the `:tmp_dir` but you can change the destination using the `:archive_remote_path` variable.
|
49
|
+
|
50
|
+
### Workflow
|
51
|
+
|
52
|
+
If you want have workflow between stage, like force deploy on staging before production, you can set the `:archive_workflow_previous` variable in your stages config file.
|
53
|
+
|
54
|
+
For example, in a *staging.rb* file, set the variable like that
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
set :archive_workflow_previous, "build"
|
58
|
+
```
|
59
|
+
|
60
|
+
And the archive location will be `:archive_releases_path`/build when you deploy the staging stage.
|
61
|
+
After the deploy, the archive file will be copied in the `:archive_workflow_next`, as default the current stage.
|
62
|
+
|
63
|
+
Do the same in a *production.rb* file
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
set :archive_workflow_previous, "staging"
|
67
|
+
```
|
68
|
+
|
69
|
+
And the archive location will be `:archive_releases_path`/staging when you deploy the production stage.
|
70
|
+
So you'll have to deploy on staging before production.
|
71
|
+
|
72
|
+
If you want turn off the workflow process, set the variable `:archive_workflow` to false.
|
73
|
+
|
74
|
+
### Revision
|
75
|
+
|
76
|
+
Capistrano log the revision info, the sha1 commit, in the revisions log file and in the file REVISION.
|
77
|
+
Since we are deploying from an archive, if we want to have the same info, it must already be present in the archive.
|
78
|
+
The most easy is to store the commit when build the archive in the REVISION file.
|
79
|
+
|
80
|
+
As default, the plugin can read the REVISION file from the archive.
|
81
|
+
|
82
|
+
If you want to store the info in another file, you can set the file with the `:archive_revision_file` variable.
|
83
|
+
If you have to manipulate the output (grep, awk, etc) you can change the `:archive_revision_command`
|
84
|
+
|
85
|
+
If you want turn off the revision process, set the variable `:archive_revision` to false.
|
86
|
+
|
87
|
+
### Variables available
|
88
|
+
|
89
|
+
If you need to change default values, you can set the following configuration variables in `config/deploy.rb` or wherever relevant:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
set :archive_releases_path, "./"
|
93
|
+
set :archive_name, "#{fetch(:application)}_#{fetch(:branch)}"
|
94
|
+
set :archive_extension, 'tar.bz2'
|
95
|
+
set :archive_tar_options, 'xjf'
|
96
|
+
set :archive_workflow, true
|
97
|
+
set :archive_workflow_previous, ""
|
98
|
+
set :archive_workflow_next,"#{fetch(:stage)}"
|
99
|
+
set :archive_remote_path, "#{fetch(:tmp_dir)}"
|
100
|
+
set :archive_revision, true
|
101
|
+
set :archive_revision_file, './REVISION'
|
102
|
+
set :archive_revision_command, 'cat'
|
103
|
+
```
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
Please feel free to open an [issue](https://github.com/prestaconcept/capistrano-archive/issues)
|
108
|
+
or a [pull request](https://github.com/prestaconcept/capistrano-archive),
|
109
|
+
if you want to help.
|
110
|
+
|
111
|
+
Thanks to
|
112
|
+
[everyone who has contributed](https://github.com/prestaconcept/capistrano-archive/graphs/contributors) already.
|
113
|
+
|
114
|
+
---
|
115
|
+
|
116
|
+
*This project is supported by [PrestaConcept](http://www.prestaconcept.net)*
|
117
|
+
|
118
|
+
Released under the [MIT License](LICENSE)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'capistrano/archive/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "capistrano-archive"
|
9
|
+
spec.version = Capistrano::Archive::VERSION
|
10
|
+
spec.authors = ['David Gaussinel']
|
11
|
+
spec.email = ['dgaussinel@prestaconcept.net']
|
12
|
+
spec.description = 'Transfer archive release strategy for capistrano.'
|
13
|
+
spec.summary = 'Transfer archive release strategy for capistrano.'
|
14
|
+
spec.homepage = 'https://github.com/prestaconcept/capistrano-archive'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'capistrano', '>= 3.7.0', '< 4.0.0'
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'capistrano/archive/scm'
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'capistrano/scm/plugin'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module Archive
|
5
|
+
class SCM < ::Capistrano::SCM::Plugin
|
6
|
+
def set_defaults
|
7
|
+
set_if_empty :archive_releases_path, ->{"./"}
|
8
|
+
set_if_empty :archive_name, ->{"#{fetch(:application)}_#{fetch(:branch)}"}
|
9
|
+
set_if_empty :archive_extension, ->{'tar.bz2'}
|
10
|
+
set_if_empty :archive_tar_options, ->{'xjf'}
|
11
|
+
set_if_empty :archive_workflow, ->{true}
|
12
|
+
set_if_empty :archive_workflow_previous, ""
|
13
|
+
set_if_empty :archive_workflow_next,->{"#{fetch(:stage)}"}
|
14
|
+
set_if_empty :archive_remote_path, ->{"#{fetch(:tmp_dir)}"}
|
15
|
+
set_if_empty :archive_revision, ->{true}
|
16
|
+
set_if_empty :archive_revision_file, ->{'./REVISION'}
|
17
|
+
set_if_empty :archive_revision_command, ->{'cat'}
|
18
|
+
set_if_empty :archive_roles, ->{:all}
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_tasks
|
22
|
+
eval_rakefile File.expand_path('../tasks/archive.rake', __FILE__)
|
23
|
+
end
|
24
|
+
|
25
|
+
def register_hooks
|
26
|
+
before 'deploy:new_release_path', 'archive:upload_archive'
|
27
|
+
after "deploy:new_release_path", "archive:create_release"
|
28
|
+
before "deploy:set_current_revision", "archive:set_current_revision"
|
29
|
+
after 'deploy:finished', 'archive:copy_archive_file'
|
30
|
+
end
|
31
|
+
|
32
|
+
def release
|
33
|
+
backend.execute :mkdir, '-p', release_path
|
34
|
+
backend.execute(:tar, fetch(:archive_tar_options), uploaded_archive_filename, '-C', release_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String]
|
38
|
+
def revision
|
39
|
+
if fetch(:archive_revision)
|
40
|
+
if File.file?(release_path_filename)
|
41
|
+
`tar #{fetch(:archive_tar_options)} #{release_path_filename} --to-command=\'#{fetch(:archive_revision_command)}\' #{fetch(:archive_revision_file)}`.gsub(/\n/,"")
|
42
|
+
else
|
43
|
+
abort "Archive #{release_path_filename} doesn't exist!"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def check
|
49
|
+
if !File.file?(release_path_filename)
|
50
|
+
abort "Archive #{release_path_filename} doesn't exist!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Upload archive file to server
|
55
|
+
#
|
56
|
+
# @return void
|
57
|
+
def upload
|
58
|
+
if File.file?(release_path_filename)
|
59
|
+
backend.upload!(release_path_filename, fetch(:archive_remote_path))
|
60
|
+
else
|
61
|
+
abort "Archive #{release_path_filename} doesn't exist!"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Remove archive file
|
66
|
+
#
|
67
|
+
# @return void
|
68
|
+
def clean
|
69
|
+
backend.execute(:rm, '-f', uploaded_archive_filename)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Copy archive file from previous stage to next stage directory release
|
73
|
+
def copy
|
74
|
+
if fetch(:archive_workflow)
|
75
|
+
unless fetch(:archive_workflow_next).to_s.strip.empty?
|
76
|
+
backend.execute(:cp, release_path_filename, "#{fetch(:archive_releases_path)}/#{fetch(:archive_workflow_next)}/")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Path and filename to local archive
|
82
|
+
#
|
83
|
+
# @return [String]
|
84
|
+
def release_path_filename
|
85
|
+
@_release_path_filename ||= File.join(fetch(:archive_releases_path), fetch(:archive_workflow_previous) , release_filename)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Filename to local archive
|
89
|
+
#
|
90
|
+
# @return [String]
|
91
|
+
def release_filename
|
92
|
+
@_release_filename ||= "#{fetch(:archive_name)}.#{fetch(:archive_extension)}"
|
93
|
+
end
|
94
|
+
|
95
|
+
# Archive uploaded filename
|
96
|
+
#
|
97
|
+
# @return [String]
|
98
|
+
def uploaded_archive_filename
|
99
|
+
@_uploaded_archive_filename ||= File.join(fetch(:archive_remote_path), release_filename)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
set :archive_plugin, self
|
2
|
+
|
3
|
+
namespace :archive do
|
4
|
+
desc 'Check that the archive is readable'
|
5
|
+
task :check do
|
6
|
+
run_locally do
|
7
|
+
fetch(:archive_plugin).check
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Upload release to current stage'
|
12
|
+
task :upload_archive do
|
13
|
+
on release_roles(fetch(:archive_roles)) do
|
14
|
+
fetch(:archive_plugin).upload
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Copy repo to releases'
|
19
|
+
task :create_release do
|
20
|
+
on release_roles :all do
|
21
|
+
fetch(:archive_plugin).release
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Determine the revision that will be deployed'
|
26
|
+
task :set_current_revision do
|
27
|
+
set :current_revision, fetch(:archive_plugin).revision
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Clean : remove archive file after deploy'
|
31
|
+
task :clean do
|
32
|
+
on roles(:app) do
|
33
|
+
fetch(:archive_plugin).clean
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Copy local archive to make it available to next stage'
|
38
|
+
task :copy_archive_file do
|
39
|
+
run_locally do
|
40
|
+
fetch(:archive_plugin).copy
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-archive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Gaussinel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.7.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.7.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.0
|
33
|
+
description: Transfer archive release strategy for capistrano.
|
34
|
+
email:
|
35
|
+
- dgaussinel@prestaconcept.net
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- CHANGELOG.md
|
41
|
+
- Gemfile
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
- capistrano-archive.gemspec
|
45
|
+
- lib/capistrano/archive.rb
|
46
|
+
- lib/capistrano/archive/scm.rb
|
47
|
+
- lib/capistrano/archive/tasks/archive.rake
|
48
|
+
- lib/capistrano/archive/version.rb
|
49
|
+
homepage: https://github.com/prestaconcept/capistrano-archive
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.7.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Transfer archive release strategy for capistrano.
|
73
|
+
test_files: []
|