capistrano-git-copy 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +7 -10
- data/capistrano-git-copy.gemspec +3 -3
- data/lib/capistrano/git_copy.rb +1 -2
- data/lib/capistrano/git_copy/scm.rb +203 -0
- data/lib/capistrano/git_copy/tasks/git_copy.rake +59 -0
- data/lib/capistrano/git_copy/version.rb +1 -1
- data/vendor/git-archive-all/git_archive_all.py +3 -5
- metadata +9 -11
- data/lib/capistrano/git/copy.rb +0 -1
- data/lib/capistrano/git_copy/task.rb +0 -1
- data/lib/capistrano/git_copy/tasks/deploy.cap +0 -70
- data/lib/capistrano/git_copy/utility.rb +0 -219
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5674b8d5f3ded4e8674afea47a7f1f60b5642b03
|
4
|
+
data.tar.gz: 9bdc1dcf572d1172e3bfbb7a1c1dc8b76fb4fb13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4dcfa2bf859b3b332a7b2500ffd11b912724ccb670fd81d20b34bacd8abe4d5ab005a4b90e4d79d07101de304dee2bb22b144da1745973a21a777063b00bde5
|
7
|
+
data.tar.gz: 8e2dd9adb6f3ea20954d99c1641d1534ffd9cb768e0eee46660bc19fed41544c218633fd09b32c38fbb38157dbf35581cb66fafbe683ed5a50d6c9d8482a366c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -23,23 +23,20 @@ And require it in your `Capfile`:
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
require 'capistrano/git_copy'
|
26
|
+
install_plugin Capistrano::GitCopy::SCM
|
26
27
|
```
|
27
28
|
|
28
|
-
Now use `git_copy` as your SCM type in your `config/deploy.rb`:
|
29
|
-
|
30
|
-
set :scm, :git_copy
|
31
|
-
|
32
29
|
By default, it includes all submodules into the deployment package. However,
|
33
30
|
if they are not needed in a particular deployment, you can disable them with
|
34
31
|
a configuration option:
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
```ruby
|
33
|
+
set :with_submodules, false
|
34
|
+
```
|
38
35
|
Besides using `export-ignore` in `.gitattributes` it's possible exclude files and directories by
|
39
36
|
adding them to `git_excludes`:
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
```ruby
|
38
|
+
append :git_excludes, 'config/database.yml.example', 'test', 'rspec'
|
39
|
+
```
|
43
40
|
## Notes
|
44
41
|
|
45
42
|
* Uses [git-archive-all](https://github.com/Kentzo/git-archive-all) for bundling repositories.
|
data/capistrano-git-copy.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Capistrano::GitCopy::VERSION
|
9
9
|
spec.authors = ['Florian Schwab']
|
10
10
|
spec.email = ['me@ydkn.de']
|
11
|
-
spec.description = 'Copy local git repository deploy strategy for capistrano'
|
12
|
-
spec.summary = 'Copy local git repository deploy strategy for capistrano'
|
11
|
+
spec.description = 'Copy local git repository deploy strategy for capistrano.'
|
12
|
+
spec.summary = 'Copy local git repository deploy strategy for capistrano.'
|
13
13
|
spec.homepage = 'https://github.com/ydkn/capistrano-git-copy'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'capistrano', '>= 3.
|
21
|
+
spec.add_dependency 'capistrano', '>= 3.7.0', '< 4.0.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
24
|
spec.add_development_dependency 'rake'
|
data/lib/capistrano/git_copy.rb
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require 'capistrano/git_copy/
|
2
|
-
require 'capistrano/git_copy/task'
|
1
|
+
require 'capistrano/git_copy/scm'
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'capistrano/scm/plugin'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module GitCopy
|
5
|
+
class SCM < ::Capistrano::SCM::Plugin
|
6
|
+
# set default values
|
7
|
+
def set_defaults
|
8
|
+
set_if_empty :with_submodules, true
|
9
|
+
set_if_empty :git_excludes, []
|
10
|
+
set_if_empty :repo_tree, false
|
11
|
+
end
|
12
|
+
|
13
|
+
# define plugin tasks
|
14
|
+
def define_tasks
|
15
|
+
eval_rakefile File.expand_path('../tasks/git_copy.rake', __FILE__)
|
16
|
+
end
|
17
|
+
|
18
|
+
# register capistrano hooks
|
19
|
+
def register_hooks
|
20
|
+
after 'deploy:new_release_path', 'git_copy:create_release'
|
21
|
+
before 'deploy:check', 'git_copy:check'
|
22
|
+
before 'deploy:set_current_revision', 'git_copy:set_current_revision'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Check if repository is accessible
|
26
|
+
#
|
27
|
+
# @return void
|
28
|
+
def check
|
29
|
+
git(:'ls-remote --heads', repo_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Check if repository cache exists and is valid
|
33
|
+
#
|
34
|
+
# @return [Boolean] indicates if repo cache exists
|
35
|
+
def test
|
36
|
+
if backend.test("[ -d #{repo_cache_path} ]")
|
37
|
+
backend.within(repo_cache_path) do
|
38
|
+
if backend.test(:git, :status, '>/dev/null 2>/dev/null')
|
39
|
+
true
|
40
|
+
else
|
41
|
+
backend.execute(:rm, '-rf', repo_cache_path)
|
42
|
+
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Clone repo to cache
|
52
|
+
#
|
53
|
+
# @return void
|
54
|
+
def clone
|
55
|
+
backend.execute(:mkdir, '-p', tmp_path)
|
56
|
+
|
57
|
+
git(:clone, fetch(:repo_url), repo_cache_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Update repo and submodules to branch
|
61
|
+
#
|
62
|
+
# @return void
|
63
|
+
def update
|
64
|
+
git(:remote, :update)
|
65
|
+
git(:reset, '--hard', commit_hash)
|
66
|
+
|
67
|
+
# submodules
|
68
|
+
if fetch(:with_submodules)
|
69
|
+
git(:submodule, :init)
|
70
|
+
git(:submodule, :update)
|
71
|
+
git(:submodule, :foreach, '--recursive', :git, :submodule, :update, '--init')
|
72
|
+
end
|
73
|
+
|
74
|
+
# cleanup
|
75
|
+
git(:clean, '-d', '-f')
|
76
|
+
|
77
|
+
if fetch(:with_submodules)
|
78
|
+
git(:submodule, :foreach, '--recursive', :git, :clean, '-d', '-f')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Create tar archive
|
83
|
+
#
|
84
|
+
# @return void
|
85
|
+
def prepare_release
|
86
|
+
target = fetch(:repo_tree) ? "HEAD:#{fetch(:repo_tree)}" : 'HEAD'
|
87
|
+
|
88
|
+
if fetch(:with_submodules)
|
89
|
+
backend.execute(git_archive_all_bin, "--prefix=''", archive_path)
|
90
|
+
else
|
91
|
+
git(:archive, '--format=tar', target, '|', 'gzip', "> #{archive_path}")
|
92
|
+
end
|
93
|
+
|
94
|
+
exclude_files_from_archive if fetch(:git_excludes, []).count > 0
|
95
|
+
end
|
96
|
+
|
97
|
+
# Upload and extract release
|
98
|
+
#
|
99
|
+
# @return void
|
100
|
+
def release
|
101
|
+
backend.execute :mkdir, '-p', release_path
|
102
|
+
|
103
|
+
remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path))
|
104
|
+
|
105
|
+
backend.upload!(archive_path, remote_archive_path)
|
106
|
+
|
107
|
+
backend.execute(:mkdir, '-p', release_path)
|
108
|
+
backend.execute(:tar, '-f', remote_archive_path, '-x', '-C', release_path)
|
109
|
+
backend.execute(:rm, '-f', remote_archive_path)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Set deployed revision
|
113
|
+
#
|
114
|
+
# @return void
|
115
|
+
def fetch_revision
|
116
|
+
backend.capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', commit_hash).strip
|
117
|
+
end
|
118
|
+
|
119
|
+
# Cleanup repo cache
|
120
|
+
#
|
121
|
+
# @return void
|
122
|
+
def cleanup
|
123
|
+
backend.execute(:rm, '-rf', tmp_path)
|
124
|
+
|
125
|
+
backend.info('Local repo cache was removed')
|
126
|
+
end
|
127
|
+
|
128
|
+
# Temporary path for all git-copy operations
|
129
|
+
#
|
130
|
+
# @return [String]
|
131
|
+
def tmp_path
|
132
|
+
@_tmp_path ||= File.join(Dir.tmpdir, deploy_id)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Path to repository cache
|
136
|
+
#
|
137
|
+
# @return [String]
|
138
|
+
def repo_cache_path
|
139
|
+
@_repo_cache_path ||= File.join(tmp_path, 'repo')
|
140
|
+
end
|
141
|
+
|
142
|
+
# Path to archive
|
143
|
+
#
|
144
|
+
# @return [String]
|
145
|
+
def archive_path
|
146
|
+
@_archive_path ||= File.join(tmp_path, 'archive.tar.gz')
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def deploy_id
|
152
|
+
[
|
153
|
+
fetch(:application),
|
154
|
+
fetch(:stage),
|
155
|
+
Digest::MD5.hexdigest(fetch(:repo_url))[0..7],
|
156
|
+
Digest::MD5.hexdigest(Dir.getwd)[0..7]
|
157
|
+
].compact.join('_').gsub(/[^\w]/, '')
|
158
|
+
end
|
159
|
+
|
160
|
+
def commit_hash
|
161
|
+
return @_commit_hash if @_commit_hash
|
162
|
+
|
163
|
+
branch = fetch(:branch, 'master').to_s.strip
|
164
|
+
|
165
|
+
if backend.test(:git, 'rev-parse', "origin/#{branch}", '>/dev/null 2>/dev/null')
|
166
|
+
@_commit_hash = backend.capture(:git, 'rev-parse', "origin/#{branch}").strip
|
167
|
+
else
|
168
|
+
@_commit_hash = backend.capture(:git, 'rev-parse', branch).strip
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def git_archive_all_bin
|
173
|
+
File.expand_path('../../../../vendor/git-archive-all/git_archive_all.py', __FILE__)
|
174
|
+
end
|
175
|
+
|
176
|
+
def git(*args)
|
177
|
+
backend.execute(:git, *args)
|
178
|
+
end
|
179
|
+
|
180
|
+
def exclude_files_from_archive
|
181
|
+
archive_dir = File.join(tmp_path, 'archive')
|
182
|
+
|
183
|
+
backend.execute :rm, '-rf', archive_dir
|
184
|
+
backend.execute :mkdir, '-p', archive_dir
|
185
|
+
backend.execute :tar, '-xzf', archive_path, '-C', archive_dir
|
186
|
+
|
187
|
+
fetch(:git_excludes, []).each do |f|
|
188
|
+
file_path = File.join(archive_dir, f.gsub(/\A\//, ''))
|
189
|
+
|
190
|
+
unless File.exists?(file_path)
|
191
|
+
backend.warn("#{f} does not exists!")
|
192
|
+
|
193
|
+
next
|
194
|
+
end
|
195
|
+
|
196
|
+
FileUtils.rm_rf(file_path)
|
197
|
+
end
|
198
|
+
|
199
|
+
backend.execute :tar, '-czf', archive_path, '-C', archive_dir, '.'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
git_copy_plugin = self
|
2
|
+
|
3
|
+
namespace :git_copy do
|
4
|
+
desc 'Check that the repository is reachable'
|
5
|
+
task :check do
|
6
|
+
run_locally do
|
7
|
+
git_copy_plugin.check
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Clone the repo to the cache'
|
12
|
+
task :clone do
|
13
|
+
run_locally do
|
14
|
+
if git_copy_plugin.test
|
15
|
+
info t(:mirror_exists, at: git_copy_plugin.repo_cache_path)
|
16
|
+
else
|
17
|
+
git_copy_plugin.clone
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Update the repo mirror to reflect the origin state'
|
23
|
+
task update: :'git_copy:clone' do
|
24
|
+
run_locally do
|
25
|
+
within git_copy_plugin.repo_cache_path do
|
26
|
+
git_copy_plugin.update
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Copy repo to releases'
|
32
|
+
task create_release: :'git_copy:update' do
|
33
|
+
run_locally do
|
34
|
+
within git_copy_plugin.repo_cache_path do
|
35
|
+
git_copy_plugin.prepare_release
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
on release_roles :all do
|
40
|
+
git_copy_plugin.release
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Determine the revision that will be deployed'
|
45
|
+
task set_current_revision: :'git_copy:update' do
|
46
|
+
run_locally do
|
47
|
+
within git_copy_plugin.repo_cache_path do
|
48
|
+
set :current_revision, git_copy_plugin.fetch_revision
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Clean repo cache'
|
54
|
+
task :cleanup do
|
55
|
+
run_locally do
|
56
|
+
git_copy_plugin.cleanup
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -34,7 +34,7 @@ import tarfile
|
|
34
34
|
from zipfile import ZipFile, ZipInfo, ZIP_DEFLATED
|
35
35
|
import re
|
36
36
|
|
37
|
-
__version__ = "1.
|
37
|
+
__version__ = "1.15"
|
38
38
|
|
39
39
|
|
40
40
|
class GitArchiver(object):
|
@@ -306,10 +306,8 @@ class GitArchiver(object):
|
|
306
306
|
file_name = path.basename(repo_file_path)
|
307
307
|
main_repo_file_path = path.join(repo_path, repo_file_path) # file path relative to the main repo
|
308
308
|
|
309
|
-
# Only list symlinks and files
|
310
|
-
if
|
311
|
-
not path.islink(main_repo_file_path) and path.isdir(main_repo_file_path)
|
312
|
-
):
|
309
|
+
# Only list symlinks and files.
|
310
|
+
if not path.islink(main_repo_file_path) and path.isdir(main_repo_file_path):
|
313
311
|
continue
|
314
312
|
|
315
313
|
if self.is_file_excluded(repo_abspath, repo_file_path, exclude_patterns):
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-git-copy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Schwab
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.7.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 4.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.
|
29
|
+
version: 3.7.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 4.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
-
description: Copy local git repository deploy strategy for capistrano
|
75
|
+
description: Copy local git repository deploy strategy for capistrano.
|
76
76
|
email:
|
77
77
|
- me@ydkn.de
|
78
78
|
executables: []
|
@@ -87,11 +87,9 @@ files:
|
|
87
87
|
- README.md
|
88
88
|
- Rakefile
|
89
89
|
- capistrano-git-copy.gemspec
|
90
|
-
- lib/capistrano/git/copy.rb
|
91
90
|
- lib/capistrano/git_copy.rb
|
92
|
-
- lib/capistrano/git_copy/
|
93
|
-
- lib/capistrano/git_copy/tasks/
|
94
|
-
- lib/capistrano/git_copy/utility.rb
|
91
|
+
- lib/capistrano/git_copy/scm.rb
|
92
|
+
- lib/capistrano/git_copy/tasks/git_copy.rake
|
95
93
|
- lib/capistrano/git_copy/version.rb
|
96
94
|
- vendor/git-archive-all/git_archive_all.py
|
97
95
|
homepage: https://github.com/ydkn/capistrano-git-copy
|
@@ -117,5 +115,5 @@ rubyforge_project:
|
|
117
115
|
rubygems_version: 2.5.2
|
118
116
|
signing_key:
|
119
117
|
specification_version: 4
|
120
|
-
summary: Copy local git repository deploy strategy for capistrano
|
118
|
+
summary: Copy local git repository deploy strategy for capistrano.
|
121
119
|
test_files: []
|
data/lib/capistrano/git/copy.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
STDERR.puts("[DEPRECATION] Please change \"require 'capistrano/git/copy'\" to \"require 'capistrano/git_copy'\" in your Capfile, and make sure to disable the default require in your Gemfile with 'gem \"capistrano-git-copy\", require: false\"' to make this warning disappear.")
|
@@ -1 +0,0 @@
|
|
1
|
-
load File.expand_path('../tasks/deploy.cap', __FILE__)
|
@@ -1,70 +0,0 @@
|
|
1
|
-
namespace :load do
|
2
|
-
task :defaults do
|
3
|
-
set :with_submodules, fetch(:with_submodules, true)
|
4
|
-
set :git_excludes, fetch(:git_excludes, [])
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :git_copy do
|
9
|
-
def git_copy_utility
|
10
|
-
@git_copy_utility ||= Capistrano::GitCopy::Utility.new(self)
|
11
|
-
end
|
12
|
-
|
13
|
-
task :wrapper do; end
|
14
|
-
|
15
|
-
desc 'Check that the repository is reachable'
|
16
|
-
task check: :'git_copy:wrapper' do
|
17
|
-
run_locally do
|
18
|
-
git_copy_utility.check
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'Clone the repo to the cache'
|
23
|
-
task clone: :'git_copy:wrapper' do
|
24
|
-
run_locally do
|
25
|
-
if git_copy_utility.test
|
26
|
-
info t(:mirror_exists, at: git_copy_utility.repo_path)
|
27
|
-
else
|
28
|
-
git_copy_utility.clone
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'Update the repo mirror to reflect the origin state'
|
34
|
-
task update: :'git_copy:clone' do
|
35
|
-
run_locally do
|
36
|
-
within git_copy_utility.repo_path do
|
37
|
-
git_copy_utility.update
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
desc 'Copy repo to releases'
|
43
|
-
task create_release: :'git_copy:update' do
|
44
|
-
run_locally do
|
45
|
-
within git_copy_utility.repo_path do
|
46
|
-
git_copy_utility.prepare_release
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
on release_roles :all do
|
51
|
-
git_copy_utility.release
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
desc 'Determine the revision that will be deployed'
|
56
|
-
task set_current_revision: :'git_copy:update' do
|
57
|
-
run_locally do
|
58
|
-
within git_copy_utility.repo_path do
|
59
|
-
set :current_revision, git_copy_utility.fetch_revision
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
desc 'Clean repo cache'
|
65
|
-
task :cleanup do
|
66
|
-
run_locally do
|
67
|
-
git_copy_utility.cleanup
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,219 +0,0 @@
|
|
1
|
-
require 'tmpdir'
|
2
|
-
require 'digest/md5'
|
3
|
-
|
4
|
-
module Capistrano
|
5
|
-
module GitCopy
|
6
|
-
# Utility stuff to avoid cluttering of deploy.cap
|
7
|
-
class Utility
|
8
|
-
attr_reader :with_submodules
|
9
|
-
attr_reader :git_excludes
|
10
|
-
|
11
|
-
def initialize(context)
|
12
|
-
@context = context
|
13
|
-
@with_submodules = fetch(:with_submodules, true)
|
14
|
-
@repo_tree = fetch(:repo_tree, false)
|
15
|
-
@with_submodules = @repo_tree? false : @with_submodules # If repo_tree is specified, set with_submodules to false
|
16
|
-
@git_excludes = fetch(:git_excludes, [])
|
17
|
-
end
|
18
|
-
|
19
|
-
# Check if repo cache exists and is valid
|
20
|
-
#
|
21
|
-
# @return [Boolean] indicates if repo cache exists
|
22
|
-
def test
|
23
|
-
if test!("[ -d #{repo_path} ]")
|
24
|
-
@context.within(repo_path) do
|
25
|
-
if test!(:git, :status, '>/dev/null 2>/dev/null')
|
26
|
-
true
|
27
|
-
else
|
28
|
-
execute(:rm, '-rf', repo_path)
|
29
|
-
false
|
30
|
-
end
|
31
|
-
end
|
32
|
-
else
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Check if repo is accessible
|
38
|
-
#
|
39
|
-
# @return void
|
40
|
-
def check
|
41
|
-
git(:'ls-remote --heads', repo_url)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Clone repo to cache
|
45
|
-
#
|
46
|
-
# @return void
|
47
|
-
def clone
|
48
|
-
execute(:mkdir, '-p', tmp_path)
|
49
|
-
|
50
|
-
git(:clone, fetch(:repo_url), repo_path)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Update repo and submodules to branch
|
54
|
-
#
|
55
|
-
# @return void
|
56
|
-
def update
|
57
|
-
git(:remote, :update)
|
58
|
-
git(:reset, '--hard', commit_hash)
|
59
|
-
|
60
|
-
# submodules
|
61
|
-
if with_submodules
|
62
|
-
git(:submodule, :init)
|
63
|
-
git(:submodule, :update)
|
64
|
-
git(:submodule, :foreach, '--recursive', :git, :submodule, :update, '--init')
|
65
|
-
end
|
66
|
-
|
67
|
-
# cleanup
|
68
|
-
git(:clean, '-d', '-f')
|
69
|
-
if with_submodules
|
70
|
-
git(:submodule, :foreach, '--recursive', :git, :clean, '-d', '-f')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Create tar archive
|
75
|
-
#
|
76
|
-
# @return void
|
77
|
-
def prepare_release
|
78
|
-
target = @repo_tree? "HEAD:#{@repo_tree}" : 'HEAD'
|
79
|
-
if with_submodules
|
80
|
-
execute(git_archive_all_bin, "--prefix=''", archive_path)
|
81
|
-
else
|
82
|
-
git(:archive, '--format=tar', target, '|', 'gzip', "> #{archive_path}")
|
83
|
-
end
|
84
|
-
|
85
|
-
exclude_files_from_archive if git_excludes.count > 0
|
86
|
-
end
|
87
|
-
|
88
|
-
# Upload and extract release
|
89
|
-
#
|
90
|
-
# @return void
|
91
|
-
def release
|
92
|
-
remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path))
|
93
|
-
|
94
|
-
upload!(archive_path, remote_archive_path)
|
95
|
-
|
96
|
-
execute(:mkdir, '-p', release_path)
|
97
|
-
execute(:tar, '-f', remote_archive_path, '-x', '-C', release_path)
|
98
|
-
execute(:rm, '-f', remote_archive_path)
|
99
|
-
end
|
100
|
-
|
101
|
-
# Set deployed revision
|
102
|
-
#
|
103
|
-
# @return void
|
104
|
-
def fetch_revision
|
105
|
-
capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', commit_hash).strip
|
106
|
-
end
|
107
|
-
|
108
|
-
# Cleanup repo cache
|
109
|
-
#
|
110
|
-
# @return void
|
111
|
-
def cleanup
|
112
|
-
execute(:rm, '-rf', tmp_path)
|
113
|
-
|
114
|
-
info('Local repo cache was removed')
|
115
|
-
end
|
116
|
-
|
117
|
-
# Temporary path for all git-copy operations
|
118
|
-
#
|
119
|
-
# @return [String]
|
120
|
-
def tmp_path
|
121
|
-
@_tmp_path ||= File.join(Dir.tmpdir, deploy_id)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Path to repo cache
|
125
|
-
#
|
126
|
-
# @return [String]
|
127
|
-
def repo_path
|
128
|
-
@_repo_path ||= File.join(tmp_path, 'repo')
|
129
|
-
end
|
130
|
-
|
131
|
-
# Path to archive
|
132
|
-
#
|
133
|
-
# @return [String]
|
134
|
-
def archive_path
|
135
|
-
@_archive_path ||= File.join(tmp_path, 'archive.tar.gz')
|
136
|
-
end
|
137
|
-
|
138
|
-
private
|
139
|
-
|
140
|
-
def fetch(*args)
|
141
|
-
@context.fetch(*args)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test!(*args)
|
145
|
-
@context.test(*args)
|
146
|
-
end
|
147
|
-
|
148
|
-
def execute(*args)
|
149
|
-
@context.execute(*args)
|
150
|
-
end
|
151
|
-
|
152
|
-
def capture(*args)
|
153
|
-
@context.capture(*args)
|
154
|
-
end
|
155
|
-
|
156
|
-
def upload!(*args)
|
157
|
-
@context.upload!(*args)
|
158
|
-
end
|
159
|
-
|
160
|
-
def info(*args)
|
161
|
-
@context.info(*args)
|
162
|
-
end
|
163
|
-
|
164
|
-
def warn(*args)
|
165
|
-
@context.warn(*args)
|
166
|
-
end
|
167
|
-
|
168
|
-
def git(*args)
|
169
|
-
execute(:git, *args)
|
170
|
-
end
|
171
|
-
|
172
|
-
def git_archive_all_bin
|
173
|
-
File.expand_path('../../../../vendor/git-archive-all/git_archive_all.py', __FILE__)
|
174
|
-
end
|
175
|
-
|
176
|
-
def deploy_id
|
177
|
-
[
|
178
|
-
fetch(:application),
|
179
|
-
fetch(:stage),
|
180
|
-
Digest::MD5.hexdigest(fetch(:repo_url))[0..7],
|
181
|
-
Digest::MD5.hexdigest(Dir.getwd)[0..7]
|
182
|
-
].compact.join('_').gsub(/[^\w]/, '')
|
183
|
-
end
|
184
|
-
|
185
|
-
def commit_hash
|
186
|
-
return @_commit_hash if @_commit_hash
|
187
|
-
|
188
|
-
branch = fetch(:branch, 'master').to_s.strip
|
189
|
-
|
190
|
-
if test!(:git, 'rev-parse', "origin/#{branch}", '>/dev/null 2>/dev/null')
|
191
|
-
@_commit_hash = capture(:git, 'rev-parse', "origin/#{branch}").strip
|
192
|
-
else
|
193
|
-
@_commit_hash = capture(:git, 'rev-parse', branch).strip
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def exclude_files_from_archive
|
199
|
-
archive_dir = File.join(tmp_path, 'archive')
|
200
|
-
|
201
|
-
execute :rm, '-rf', archive_dir
|
202
|
-
execute :mkdir, '-p', archive_dir
|
203
|
-
execute :tar, '-xzf', archive_path, '-C', archive_dir
|
204
|
-
|
205
|
-
git_excludes.each do |f|
|
206
|
-
file_path = File.join(archive_dir, f.gsub(/\A\//, ''))
|
207
|
-
|
208
|
-
unless File.exists?(file_path)
|
209
|
-
warn("#{f} does not exists!")
|
210
|
-
next
|
211
|
-
end
|
212
|
-
|
213
|
-
FileUtils.rm_rf(file_path)
|
214
|
-
end
|
215
|
-
|
216
|
-
execute :tar, '-czf', archive_path, '-C', archive_dir, '.'
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|