capistrano-git-copy 0.7.0 → 0.8.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/capistrano-git-copy.gemspec +2 -2
- data/lib/capistrano/git/copy.rb +1 -3
- data/lib/capistrano/git/copy/tasks/deploy.cap +1 -1
- data/lib/capistrano/git_copy.rb +3 -1
- data/lib/capistrano/git_copy/tasks/deploy.cap +61 -0
- data/lib/capistrano/git_copy/utility.rb +165 -0
- data/lib/capistrano/git_copy/version.rb +8 -0
- metadata +6 -4
- data/lib/capistrano/git/copy/utility.rb +0 -167
- data/lib/capistrano/git/copy/version.rb +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: da14278f5b4f4b247cf32afd34a66748b2443cc2
|
|
4
|
+
data.tar.gz: 757ddb4c2fa4135242423b66ce9746bfcc0b84f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b8eaeae3a93a485d221921ec82dcf8095efff3bf076f9746747668c76429ac8fe63178c62cea5a7b37cf0e00a5c72ebd0dc57c91acb7b5176a004bf34145bc8
|
|
7
|
+
data.tar.gz: e8bddba412086a66be0152e68fa2839ac62a6ad780335e56fa4df869b0d54e0ce3e19d8cb427ddbd2baf6166ceec611bea40d6e7a43f1192d8ff6c42e7c836bc
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
[](https://gemnasium.com/ydkn/capistrano-git-copy)
|
|
3
3
|
[](https://codeclimate.com/github/ydkn/capistrano-git-copy)
|
|
4
4
|
|
|
5
|
-
# Capistrano::
|
|
5
|
+
# Capistrano::GitCopy
|
|
6
6
|
|
|
7
7
|
Creates a tar archive locally from the git repository and uploads it to the remote server.
|
|
8
8
|
|
data/capistrano-git-copy.gemspec
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'capistrano/
|
|
4
|
+
require 'capistrano/git_copy/version'
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'capistrano-git-copy'
|
|
8
|
-
spec.version = Capistrano::
|
|
8
|
+
spec.version = Capistrano::GitCopy::VERSION
|
|
9
9
|
spec.authors = ['Florian Schwab']
|
|
10
10
|
spec.email = ['me@ydkn.de']
|
|
11
11
|
spec.description = 'Copy local git repository deploy strategy for capistrano'
|
data/lib/capistrano/git/copy.rb
CHANGED
data/lib/capistrano/git_copy.rb
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
namespace :git_copy do
|
|
2
|
+
def git_copy_utility
|
|
3
|
+
@git_copy_utility ||= Capistrano::GitCopy::Utility.new(self)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
task :wrapper do; end
|
|
7
|
+
|
|
8
|
+
desc 'Check that the repository is reachable'
|
|
9
|
+
task check: :'git_copy:wrapper' do
|
|
10
|
+
run_locally do
|
|
11
|
+
git_copy_utility.check
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Clone the repo to the cache'
|
|
16
|
+
task clone: :'git_copy:wrapper' do
|
|
17
|
+
run_locally do
|
|
18
|
+
if git_copy_utility.test
|
|
19
|
+
info t(:mirror_exists, at: git_copy_utility.repo_path)
|
|
20
|
+
else
|
|
21
|
+
git_copy_utility.clone
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc 'Update the repo mirror to reflect the origin state'
|
|
27
|
+
task update: :'git_copy:clone' do
|
|
28
|
+
run_locally do
|
|
29
|
+
within git_copy_utility.repo_path do
|
|
30
|
+
git_copy_utility.update
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
desc 'Copy repo to releases'
|
|
36
|
+
task create_release: :'git_copy:update' do
|
|
37
|
+
run_locally do
|
|
38
|
+
within git_copy_utility.repo_path do
|
|
39
|
+
git_copy_utility.prepare_release
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
on release_roles :all do
|
|
44
|
+
git_copy_utility.release
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
desc 'Determine the revision that will be deployed'
|
|
49
|
+
task :set_current_revision do
|
|
50
|
+
run_locally do
|
|
51
|
+
set :current_revision, git_copy_utility.fetch_revision
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
desc 'Clean repo cache'
|
|
56
|
+
task :cleanup do
|
|
57
|
+
run_locally do
|
|
58
|
+
git_copy_utility.cleanup
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
def initialize(context)
|
|
9
|
+
@context = context
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Check if repo cache exists
|
|
13
|
+
#
|
|
14
|
+
# @return [Boolean] indicates if repo cache exists
|
|
15
|
+
def test
|
|
16
|
+
test! " [ -d #{repo_path} ] "
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Check if repo is accessible
|
|
20
|
+
#
|
|
21
|
+
# @return void
|
|
22
|
+
def check
|
|
23
|
+
git :'ls-remote --heads', repo_url
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Clone repo to cache
|
|
27
|
+
#
|
|
28
|
+
# @return void
|
|
29
|
+
def clone
|
|
30
|
+
execute :mkdir, '-p', tmp_path
|
|
31
|
+
|
|
32
|
+
git :clone, fetch(:repo_url), repo_path
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Update repo and submodules to branch
|
|
36
|
+
#
|
|
37
|
+
# @return void
|
|
38
|
+
def update
|
|
39
|
+
git :remote, :update
|
|
40
|
+
git :reset, '--hard', commit_hash
|
|
41
|
+
|
|
42
|
+
# submodules
|
|
43
|
+
git :submodule, :init
|
|
44
|
+
git :submodule, :update
|
|
45
|
+
git :submodule, :foreach, '--recursive', :git, :submodule, :update, '--init'
|
|
46
|
+
|
|
47
|
+
# cleanup
|
|
48
|
+
git :clean, '-d', '-f'
|
|
49
|
+
git :submodule, :foreach, '--recursive', :git, :clean, '-d', '-f'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Create tar archive
|
|
53
|
+
#
|
|
54
|
+
# @return void
|
|
55
|
+
def prepare_release
|
|
56
|
+
execute git_archive_all_bin, "--prefix=''", archive_path
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Upload and extract release
|
|
60
|
+
#
|
|
61
|
+
# @return void
|
|
62
|
+
def release
|
|
63
|
+
remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path))
|
|
64
|
+
|
|
65
|
+
upload! archive_path, remote_archive_path
|
|
66
|
+
|
|
67
|
+
execute :mkdir, '-p', release_path
|
|
68
|
+
execute :tar, '-f', remote_archive_path, '-x', '-C', release_path
|
|
69
|
+
execute :rm, '-f', remote_archive_path
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Set deployed revision
|
|
73
|
+
#
|
|
74
|
+
# @return void
|
|
75
|
+
def fetch_revision
|
|
76
|
+
capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', fetch(:branch)).strip
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Cleanup repo cache
|
|
80
|
+
#
|
|
81
|
+
# @return void
|
|
82
|
+
def cleanup
|
|
83
|
+
execute :rm, '-rf', tmp_path
|
|
84
|
+
|
|
85
|
+
info 'Local repo cache was removed'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Temporary path for all git-copy operations
|
|
89
|
+
#
|
|
90
|
+
# @return [String]
|
|
91
|
+
def tmp_path
|
|
92
|
+
@_tmp_path ||= File.join(Dir.tmpdir, deploy_id)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Path to repo cache
|
|
96
|
+
#
|
|
97
|
+
# @return [String]
|
|
98
|
+
def repo_path
|
|
99
|
+
@_repo_path ||= File.join(tmp_path, 'repo')
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Path to archive
|
|
103
|
+
#
|
|
104
|
+
# @return [String]
|
|
105
|
+
def archive_path
|
|
106
|
+
@_archive_path ||= File.join(tmp_path, 'archive.tar.gz')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
def fetch(*args)
|
|
112
|
+
@context.fetch(*args)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test!(*args)
|
|
116
|
+
@context.test(*args)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def execute(*args)
|
|
120
|
+
@context.execute(*args)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def capture(*args)
|
|
124
|
+
@context.capture(*args)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def upload!(*args)
|
|
128
|
+
@context.upload!(*args)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def info(*args)
|
|
132
|
+
@context.info(*args)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def git(*args)
|
|
136
|
+
args.unshift(:git)
|
|
137
|
+
execute(*args)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def git_archive_all_bin
|
|
141
|
+
File.expand_path('../../../../vendor/git-archive-all/git-archive-all', __FILE__)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def deploy_id
|
|
145
|
+
[
|
|
146
|
+
fetch(:application),
|
|
147
|
+
fetch(:stage),
|
|
148
|
+
Digest::MD5.hexdigest(fetch(:repo_url))[0..7]
|
|
149
|
+
].compact.join('_')
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def commit_hash
|
|
153
|
+
return @_commit_hash if @_commit_hash
|
|
154
|
+
|
|
155
|
+
branch = fetch(:branch, 'master').strip
|
|
156
|
+
|
|
157
|
+
if test! :git, 'rev-parse', "origin/#{branch}", '>/dev/null 2>/dev/null'
|
|
158
|
+
@_commit_hash = capture(:git, 'rev-parse', "origin/#{branch}").strip
|
|
159
|
+
else
|
|
160
|
+
@_commit_hash = capture(:git, 'rev-parse', branch).strip
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano-git-copy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Schwab
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: capistrano
|
|
@@ -81,6 +81,7 @@ extra_rdoc_files: []
|
|
|
81
81
|
files:
|
|
82
82
|
- ".gitignore"
|
|
83
83
|
- ".gitmodules"
|
|
84
|
+
- CHANGELOG.md
|
|
84
85
|
- Gemfile
|
|
85
86
|
- LICENSE.txt
|
|
86
87
|
- README.md
|
|
@@ -88,9 +89,10 @@ files:
|
|
|
88
89
|
- capistrano-git-copy.gemspec
|
|
89
90
|
- lib/capistrano/git/copy.rb
|
|
90
91
|
- lib/capistrano/git/copy/tasks/deploy.cap
|
|
91
|
-
- lib/capistrano/git/copy/utility.rb
|
|
92
|
-
- lib/capistrano/git/copy/version.rb
|
|
93
92
|
- lib/capistrano/git_copy.rb
|
|
93
|
+
- lib/capistrano/git_copy/tasks/deploy.cap
|
|
94
|
+
- lib/capistrano/git_copy/utility.rb
|
|
95
|
+
- lib/capistrano/git_copy/version.rb
|
|
94
96
|
- vendor/git-archive-all/git-archive-all
|
|
95
97
|
homepage: https://github.com/ydkn/capistrano-git-copy
|
|
96
98
|
licenses:
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
require 'tmpdir'
|
|
2
|
-
require 'digest/md5'
|
|
3
|
-
|
|
4
|
-
module Capistrano
|
|
5
|
-
module Git
|
|
6
|
-
module Copy
|
|
7
|
-
# Utility stuff to avoid cluttering of deploy.cap
|
|
8
|
-
class Utility
|
|
9
|
-
def initialize(context)
|
|
10
|
-
@context = context
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Check if repo cache exists
|
|
14
|
-
#
|
|
15
|
-
# @return [Boolean] indicates if repo cache exists
|
|
16
|
-
def test
|
|
17
|
-
test! " [ -d #{repo_path} ] "
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Check if repo is accessible
|
|
21
|
-
#
|
|
22
|
-
# @return void
|
|
23
|
-
def check
|
|
24
|
-
git :'ls-remote --heads', repo_url
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Clone repo to cache
|
|
28
|
-
#
|
|
29
|
-
# @return void
|
|
30
|
-
def clone
|
|
31
|
-
execute :mkdir, '-p', tmp_path
|
|
32
|
-
|
|
33
|
-
git :clone, fetch(:repo_url), repo_path
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Update repo and submodules to branch
|
|
37
|
-
#
|
|
38
|
-
# @return void
|
|
39
|
-
def update
|
|
40
|
-
git :remote, :update
|
|
41
|
-
git :reset, '--hard', commit_hash
|
|
42
|
-
|
|
43
|
-
# submodules
|
|
44
|
-
git :submodule, :init
|
|
45
|
-
git :submodule, :update
|
|
46
|
-
git :submodule, :foreach, '--recursive', :git, :submodule, :update, '--init'
|
|
47
|
-
|
|
48
|
-
# cleanup
|
|
49
|
-
git :clean, '-d', '-f'
|
|
50
|
-
git :submodule, :foreach, '--recursive', :git, :clean, '-d', '-f'
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Create tar archive
|
|
54
|
-
#
|
|
55
|
-
# @return void
|
|
56
|
-
def prepare_release
|
|
57
|
-
execute git_archive_all_bin, "--prefix=''", archive_path
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Upload and extract release
|
|
61
|
-
#
|
|
62
|
-
# @return void
|
|
63
|
-
def release
|
|
64
|
-
remote_archive_path = File.join(fetch(:deploy_to), File.basename(archive_path))
|
|
65
|
-
|
|
66
|
-
upload! archive_path, remote_archive_path
|
|
67
|
-
|
|
68
|
-
execute :mkdir, '-p', release_path
|
|
69
|
-
execute :tar, '-f', remote_archive_path, '-x', '-C', release_path
|
|
70
|
-
execute :rm, '-f', remote_archive_path
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Set deployed revision
|
|
74
|
-
#
|
|
75
|
-
# @return void
|
|
76
|
-
def fetch_revision
|
|
77
|
-
capture(:git, 'rev-list', '--max-count=1', '--abbrev-commit', fetch(:branch)).strip
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Cleanup repo cache
|
|
81
|
-
#
|
|
82
|
-
# @return void
|
|
83
|
-
def cleanup
|
|
84
|
-
execute :rm, '-rf', tmp_path
|
|
85
|
-
|
|
86
|
-
info 'Local repo cache was removed'
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Temporary path for all git-copy operations
|
|
90
|
-
#
|
|
91
|
-
# @return [String]
|
|
92
|
-
def tmp_path
|
|
93
|
-
@_tmp_path ||= File.join(Dir.tmpdir, deploy_id)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# Path to repo cache
|
|
97
|
-
#
|
|
98
|
-
# @return [String]
|
|
99
|
-
def repo_path
|
|
100
|
-
@_repo_path ||= File.join(tmp_path, 'repo')
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Path to archive
|
|
104
|
-
#
|
|
105
|
-
# @return [String]
|
|
106
|
-
def archive_path
|
|
107
|
-
@_archive_path ||= File.join(tmp_path, 'archive.tar.gz')
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
private
|
|
111
|
-
|
|
112
|
-
def fetch(*args)
|
|
113
|
-
@context.fetch(*args)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def test!(*args)
|
|
117
|
-
@context.test(*args)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def execute(*args)
|
|
121
|
-
@context.execute(*args)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def capture(*args)
|
|
125
|
-
@context.capture(*args)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def upload!(*args)
|
|
129
|
-
@context.upload!(*args)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def info(*args)
|
|
133
|
-
@context.info(*args)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def git(*args)
|
|
137
|
-
args.unshift(:git)
|
|
138
|
-
execute(*args)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def git_archive_all_bin
|
|
142
|
-
File.expand_path('../../../../../vendor/git-archive-all/git-archive-all', __FILE__)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def deploy_id
|
|
146
|
-
[
|
|
147
|
-
fetch(:application),
|
|
148
|
-
fetch(:stage),
|
|
149
|
-
Digest::MD5.hexdigest(fetch(:repo_url))[0..7]
|
|
150
|
-
].compact.join('_')
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def commit_hash
|
|
154
|
-
return @_commit_hash if @_commit_hash
|
|
155
|
-
|
|
156
|
-
branch = fetch(:branch, 'master')
|
|
157
|
-
|
|
158
|
-
if test! :git, 'rev-parse', "origin/#{branch}", '>/dev/null 2>/dev/null'
|
|
159
|
-
@_commit_hash = capture(:git, 'rev-parse', "origin/#{branch}").strip
|
|
160
|
-
else
|
|
161
|
-
@_commit_hash = capture(:git, 'rev-parse', branch).strip
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|