capistrano-rsync-plugin 0.2.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/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +125 -0
- data/Rakefile +1 -0
- data/capistrano-rsync.gemspec +27 -0
- data/lib/capistrano-rsync.rb +0 -0
- data/lib/capistrano/rsync.rb +86 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 342fb3c066b99bd9f46b17b27c71e0bb2c9804992cb765380001a366bde9f7d8
|
4
|
+
data.tar.gz: 91f7a818d5eb5f762049e71cf22c789069d0b21356ffa9264ec62b5f0e92d308
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc8e521a52ce6f340208a8669be0f0605fab52718682fcbb0a72e38d6e05db89eed1f3a51db849b9d65f03b6e4c9cd595a6ebc522c46b693fba15f5279778eb0
|
7
|
+
data.tar.gz: 7a75810c5d2a8ac7a433433544c890c48e8d0ac3fd60df5fd30061830904e954305f95228ab46c751ee39ad7e86280797317f5f25c45277e8e122fd62521b133
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Tom Armitage, Stefan Daschek
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Capistrano 3.7.1+ rsync plugin
|
2
|
+
|
3
|
+
A plugin for Capistrano 3.7.1+ to enable deployment with RSync. Entirely adapted from [a gist by Stefan Daschek](https://gist.github.com/noniq/f73e7eb199a4c2ad519c6b5e2ba5b0df).
|
4
|
+
|
5
|
+
This emerged after [capistrano-rsync-bladrak](https://github.com/Bladrak/capistrano-rsync) appeared to [no longer support Capistrano 3.7.1](https://github.com/Bladrak/capistrano-rsync/issues/26)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'capistrano-rsync-plugin'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install capistrano-rsync-plugin
|
22
|
+
|
23
|
+
Then, add this to your `Capfile` after loading `capistrano/deploy`
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require "capistrano/rsync"
|
27
|
+
install_plugin Capistrano::SCM::Rsync
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Deploying via rsync works in three steps:
|
33
|
+
|
34
|
+
1. A git checkout of the specified branched is performed into a local cache directory (`:rsync_local_cache`). Per default, this directory is persisted so that the next deploy only needs to do a “git pull” instead of a fresh clone. But you can delete this directory anytime, if you need/want do. (It will be recreated during the next deploy.)
|
35
|
+
|
36
|
+
2. The local cache directory is synced to the remote cache directory (`:rsync_remote_cache`) using rsync. Think of the remote cache directory as equivalent to the `repo` directory when deploying via git. It is there to avoid having to transfer all the files on each deploy. This, too, can be deleted (and will be recreated during the next deploy).
|
37
|
+
|
38
|
+
Per default, `:rsync_options` is set to exclude any git related files, thus none of these files will be transferred to the server.
|
39
|
+
|
40
|
+
3. The current state of the remote cache directory is copied to the release directory (also using rsync, but as the release directory is freshly created for each deploy, this is in fact just a full recursive copy)
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
## Configuration
|
45
|
+
|
46
|
+
Configuration option `:rsync_options` lets you specify options for the RSync command. The default is equivalent to:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
set :rsync_options, %w[--archive --delete --exclude=.git*]
|
50
|
+
```
|
51
|
+
|
52
|
+
The local cache directory relative to current is set by `:rsync_local_cache`. The default is equivalent to
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
set :rsync_local_cache, 'tmp/.capistrano-rsync-deploy'
|
56
|
+
```
|
57
|
+
|
58
|
+
The remote cache directory, relative to the deploy root, is set via `:rsync_remote_cache`, and is equivalent to:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
set :rsync_remote_cache, 'rsync-deploy'
|
62
|
+
```
|
63
|
+
|
64
|
+
The option `:rsync_deploy_build_path` makes it possible to deploy a subdirectory of the local cache. For instance, to only deploy the `public` directory, containing a compiled static site:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
set :rsync_deploy_build_path, 'public/'
|
68
|
+
```
|
69
|
+
|
70
|
+
Note the trailing slash. By default this is blank.
|
71
|
+
|
72
|
+
### New Capistrano Tasks
|
73
|
+
|
74
|
+
The `rsync` plugin introduces the following new tasks, which can be hooked onto using capistrano's before/after hooks:
|
75
|
+
|
76
|
+
* `set_current_revision` - calculate the current repository revision to check out
|
77
|
+
* `update_local_cache` - check out that revision to the local cache directory
|
78
|
+
* `update_remote_cache` - rsync local cache to the remote cache directory
|
79
|
+
* `create_release` - copy cache directory to the latest release directory
|
80
|
+
|
81
|
+
After `create_release`, the traditional Capistrano flow is resumed, and the latest release is symlinekd to current.
|
82
|
+
|
83
|
+
## Hooking build tasks on to capistrano-rsync-plugin
|
84
|
+
|
85
|
+
A primary use case for `capistrano-rsync-plugin` is the deployment of sites made with static site generators. Rather than storing compiled static sites in the repo along with sourcecode, it is recommended to build the site as part of the deployment process, and then deploy only the compiled site. This requires no dependencies on the server as a result.
|
86
|
+
|
87
|
+
As an example, let's deploy a repository made with the static site generator [Hugo](https://gohugo.io). We'll first add a task in our `deploy.rb` to build the site by installing necessary Javascript plugins, and then running Hugo:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
namespace :mysite do
|
91
|
+
desc 'Locally build the hugo site'
|
92
|
+
task :build_hugo do
|
93
|
+
run_locally do
|
94
|
+
within fetch(:rsync_local_cache) do
|
95
|
+
execute :yarn
|
96
|
+
execute :hugo, '--gc'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
This will change directory to the local cache, run `yarn`, and then run `hugo`. Now, we should add a hook to the `deploy.rb` to ensure this runs at the appropriate point in the build - after we've checked out the local cache:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
after 'rsync:update_local_cache', "mysite:build_hugo"
|
107
|
+
```
|
108
|
+
|
109
|
+
This will run `hugo`, and output the compiled site to `{LOCAL_CACHE_PATH}/public`.
|
110
|
+
|
111
|
+
Finally, we don't want to deploy all our source data - only the `public` directory, so we make sure we've set a configuration variable to do that in our `config/deploy.rb` file:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
set :rsync_deploy_build_path, "public/"
|
115
|
+
```
|
116
|
+
|
117
|
+
Of course, you can always override these variables and tasks in per-environment configuration files.
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/infovore/capistrano-rsync-plugin .
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "capistrano-rsync-plugin"
|
7
|
+
spec.version = "0.2.0"
|
8
|
+
spec.authors = ["Tom Armitage", "Stefan Daschek"]
|
9
|
+
spec.email = ["tom@infovore.org"]
|
10
|
+
|
11
|
+
spec.summary = %q{Plugin for Capitsrano 3.7+ to deploy with rsync}
|
12
|
+
spec.description = %q{Plugin for Capistrano 3.7+ to deploy with rsync, based on a Gist by Stefan Daschek.
|
13
|
+
|
14
|
+
Ideally suited to deploying static sites made with static-site-generators.}
|
15
|
+
spec.homepage = "https://github.com/infovore/capistrano-rsync-plugin"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'capistrano', '>= 3.0.0.pre'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
File without changes
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'capistrano/scm/plugin'
|
2
|
+
|
3
|
+
class Capistrano::SCM
|
4
|
+
class Rsync < ::Capistrano::SCM::Plugin
|
5
|
+
def set_defaults
|
6
|
+
# command-line options for rsync
|
7
|
+
set_if_empty :rsync_options, %w[--archive --delete --exclude=.git*]
|
8
|
+
|
9
|
+
# Local cache (Git checkout will be happen here, resulting files then get rsynced to the remote server)
|
10
|
+
set_if_empty :rsync_local_cache, 'tmp/.capistrano-rsync-deploy'
|
11
|
+
|
12
|
+
# Remote cache on the server. Will be synced with the local cache before each release, and then used as
|
13
|
+
# source for the release. Saves needing to transfer all the source files for each release.
|
14
|
+
set_if_empty :rsync_remote_cache, 'rsync-deploy'
|
15
|
+
end
|
16
|
+
|
17
|
+
def define_tasks
|
18
|
+
namespace :rsync do
|
19
|
+
desc <<-DESC
|
20
|
+
Copy application source code from (remote) cache to release path.
|
21
|
+
|
22
|
+
If a :rsync_deploy_build_path is set, only that relative path will \
|
23
|
+
be copied to the release path.
|
24
|
+
DESC
|
25
|
+
task create_release: :update_remote_cache do
|
26
|
+
on release_roles :all do
|
27
|
+
execute :rsync, '--archive', "#{fetch(:deploy_to)}/#{fetch(:rsync_remote_cache)}/#{fetch(:rsync_deploy_build_path)}", "#{release_path}/"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc <<-DESC
|
32
|
+
Update remote cache of application source code.
|
33
|
+
|
34
|
+
This will be rsynced to :rsync_remote_cache, using rsync options set in \
|
35
|
+
:rsync_options
|
36
|
+
DESC
|
37
|
+
task update_remote_cache: :update_local_cache do
|
38
|
+
on release_roles :all do |role|
|
39
|
+
host_spec = role.hostname
|
40
|
+
host_spec = "#{role.user}@#{host_spec}" if role.user
|
41
|
+
run_locally do
|
42
|
+
execute :rsync, *fetch(:rsync_options), "#{fetch(:rsync_local_cache)}/", "#{host_spec}:#{fetch(:deploy_to)}/#{fetch(:rsync_remote_cache)}/"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc <<-DESC
|
48
|
+
Update local cache of application source code.
|
49
|
+
|
50
|
+
This will be checked out to :rsync_local_cache.
|
51
|
+
DESC
|
52
|
+
task :update_local_cache do
|
53
|
+
run_locally do
|
54
|
+
unless File.exist?("#{fetch(:rsync_local_cache)}/.git")
|
55
|
+
FileUtils.mkdir_p(fetch(:rsync_local_cache))
|
56
|
+
execute :git, :clone, '--quiet', repo_url, fetch(:rsync_local_cache)
|
57
|
+
end
|
58
|
+
within fetch(:rsync_local_cache) do
|
59
|
+
execute :git, :fetch, '--quiet', '--all', '--prune'
|
60
|
+
execute :git, :checkout, fetch(:branch)
|
61
|
+
execute :git, :reset, '--quiet', '--hard', "origin/#{fetch(:branch)}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
desc <<-DESC
|
67
|
+
Determine version of code that rsync will deploy.
|
68
|
+
|
69
|
+
By default, this is the latest version of the code on branch :branch.
|
70
|
+
DESC
|
71
|
+
task :set_current_revision do
|
72
|
+
run_locally do
|
73
|
+
within fetch(:rsync_local_cache) do
|
74
|
+
set :current_revision, capture(:git, "rev-list --max-count=1 #{fetch(:branch)}")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def register_hooks
|
82
|
+
after 'deploy:new_release_path', 'rsync:create_release'
|
83
|
+
before 'deploy:set_current_revision', 'rsync:set_current_revision'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-rsync-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Armitage
|
8
|
+
- Stefan Daschek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-07-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.0.0.pre
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.0.0.pre
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
description: |-
|
57
|
+
Plugin for Capistrano 3.7+ to deploy with rsync, based on a Gist by Stefan Daschek.
|
58
|
+
|
59
|
+
Ideally suited to deploying static sites made with static-site-generators.
|
60
|
+
email:
|
61
|
+
- tom@infovore.org
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".gitignore"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- capistrano-rsync.gemspec
|
72
|
+
- lib/capistrano-rsync.rb
|
73
|
+
- lib/capistrano/rsync.rb
|
74
|
+
homepage: https://github.com/infovore/capistrano-rsync-plugin
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.6.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Plugin for Capitsrano 3.7+ to deploy with rsync
|
98
|
+
test_files: []
|