capistrano-git-copy 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49518f26b320e7bc5bf917264cd19c3b386c75ab
4
- data.tar.gz: 6aea180c205916da185cbc642021a2d72e0e7a6a
3
+ metadata.gz: b2af2b9b1eb48bc206244ecbda119ffa9769e978
4
+ data.tar.gz: 3dd5ff5a4a71cdb64fef39f0875bb5f92f1a9177
5
5
  SHA512:
6
- metadata.gz: 73f8e3e51de78e4029f76fe48f083aa7122a743d685e17025a4a9dcd124f7650a89f2cfff72c78a3635f00d69a222eca47294a9121f3a1c0437ba5a608dfc1be
7
- data.tar.gz: 5eceecae6940c915762e8bfb5bbc92a77397d5056b26e4cce02c01a10f001de5adeaabe758c227cbfb1f36ffa414e01e59eaa1a42169c8819f3f58faed2eea2f
6
+ metadata.gz: 5d4a0f91a0780fadb3c11d0fbd914a47011d24af088aec896d34fa440f18b721769b5d755b1733d7646aded5ad4ff39aca682f77cb915a9a814620394f1824ff
7
+ data.tar.gz: a2e88cc490728d6943257563975d87e08ee5cc8cd2f4fdfe18f9714ce543e069a40b81eaae208011346d4c5237713892dcc1639f22522c3c0aeaccb080ca4d45
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/git-archive-all"]
2
+ path = vendor/git-archive-all
3
+ url = https://github.com/Kentzo/git-archive-all.git
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/capistrano-git-copy.svg)](https://rubygems.org/gems/capistrano-git-copy)
2
+ [![Dependencies](https://img.shields.io/gemnasium/ydkn/capistrano-git-copy.svg)](https://gemnasium.com/ydkn/capistrano-git-copy)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/capistrano-git-copy.svg)](https://codeclimate.com/github/ydkn/capistrano-git-copy)
4
+
1
5
  # Capistrano::GIT::Copy
2
6
 
3
7
  Creates a tar archive locally from the git repository and uploads it to the remote server.
@@ -22,13 +26,6 @@ Now use `git_copy` as your SCM type in your `config/deploy.rb`:
22
26
 
23
27
  set :scm, :git_copy
24
28
 
25
- ## Configuration
26
-
27
- You can modify any of the following Capistrano variables in your `deploy.rb` config.
28
-
29
- - `git_archive_all_bin` - Set the path for the git-archive-all command. Defaults to git-archive-all found in $PATH or the included version as a fallback.
30
- - `git_copy_tmp_path` - Temporary path where the repository is cloned to and the archive is created.
31
-
32
29
  ## Notes
33
30
 
34
31
  * Uses [git-archive-all](https://github.com/Kentzo/git-archive-all) for bundling repositories.
@@ -40,10 +37,3 @@ You can modify any of the following Capistrano variables in your `deploy.rb` con
40
37
  3. Commit your changes (`git commit -am 'Add some feature'`)
41
38
  4. Push to the branch (`git push origin my-new-feature`)
42
39
  5. Create new Pull Request
43
-
44
-
45
-  
46
-
47
- [![Gem Version](https://img.shields.io/gem/v/capistrano-git-copy.svg)](https://rubygems.org/gems/capistrano-git-copy)
48
- [![Dependencies](https://img.shields.io/gemnasium/ydkn/capistrano-git-copy.svg)](https://gemnasium.com/ydkn/capistrano-git-copy)
49
- [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/capistrano-git-copy.svg)](https://codeclimate.com/github/ydkn/capistrano-git-copy)
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -4,19 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'capistrano/git/copy/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "capistrano-git-copy"
7
+ spec.name = 'capistrano-git-copy'
8
8
  spec.version = Capistrano::Git::Copy::VERSION
9
- spec.authors = ["Florian Schwab"]
10
- spec.email = ["me@ydkn.de"]
11
- spec.description = %q{Copy local git repository deploy strategy for capistrano}
12
- spec.summary = %q{Copy local git repository deploy strategy for capistrano}
13
- spec.homepage = "https://github.com/ydkn/capistrano-git-copy"
14
- spec.license = "MIT"
9
+ spec.authors = ['Florian Schwab']
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'
13
+ spec.homepage = 'https://github.com/ydkn/capistrano-git-copy'
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($/) + %w( vendor/git-archive-all/git-archive-all )
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'capistrano', '>= 3.1.0', '< 4.0.0'
22
22
 
@@ -1,18 +1,3 @@
1
- # Capistrano
2
- module Capistrano
3
- # GIT
4
- module Git
5
- # Copy
6
- module Copy
7
- # Quick-Access to this gems root directory
8
- #
9
- # @return [String] Root directory of this gem
10
- def self.root_path
11
- File.expand_path('../../../..', __FILE__)
12
- end
13
- end
14
- end
15
- end
1
+ require 'capistrano/git/copy/utility'
16
2
 
17
- require 'capistrano/git/copy/version'
18
- require 'capistrano/git/copy/deploy'
3
+ load File.expand_path('../copy/tasks/deploy.cap', __FILE__)
@@ -1,102 +1,61 @@
1
- namespace :load do
2
- task :defaults do
3
- set :git_archive_all_bin, -> {
4
- bin = `which git-archive-all`.strip
5
- bin.length > 0 ? bin : File.join(Capistrano::Git::Copy.root_path, 'vendor', 'bin', 'git-archive-all')
6
- }
7
-
8
- set :git_copy_tmp_path, -> { File.join(Dir.tmpdir, "#{fetch(:application)}_#{fetch(:stage)}") }
9
- end
10
- end
11
-
12
1
  namespace :git_copy do
13
- task :wrapper do
14
- fail "git-archive-all binary not found" if fetch(:git_archive_all_bin).strip.length == 0
15
-
16
- invoke 'git_copy:update_local_working_copy'
2
+ def git_copy_utility
3
+ @git_copy_utility ||= Capistrano::Git::Copy::Utility.new(self)
17
4
  end
18
5
 
19
- task :check do; end
20
- task :clone do; end
21
-
22
- desc 'Create tar and upload to server'
23
- task update: :'git_copy:wrapper' do
24
- # create tar with git-archive-all
25
- system("cd #{fetch(:local_repo_path)} && #{fetch(:git_archive_all_bin)} __tmp.tar")
26
-
27
- # create tar.gz for upload
28
- system("cd #{fetch(:local_repo_path)} && tar -xf __tmp.tar && cd __tmp && tar -czf #{fetch(:local_tar_file)} .")
6
+ task :wrapper do; end
29
7
 
30
- # upload to all servers
31
- on release_roles :all do
32
- upload!(fetch(:local_tar_file), "#{fetch(:tmp_dir)}/#{fetch(:application)}_#{fetch(:stage)}.tar.gz")
8
+ desc 'Check that the repository is reachable'
9
+ task check: :'git_copy:wrapper' do
10
+ run_locally do
11
+ git_copy_utility.check
33
12
  end
13
+ end
34
14
 
35
- # delete temporary tar.gz archive
36
- system("rm -rf #{fetch(:local_tar_file)}")
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
37
24
  end
38
25
 
39
- desc 'Extract tar to release path'
40
- task create_release: :'git_copy:update' do
41
- on release_roles :all do
42
- execute(:mkdir, '-p', release_path)
43
- execute(:tar, '-f', "#{fetch(:tmp_dir)}/#{fetch(:application)}_#{fetch(:stage)}.tar.gz", '-x -C', release_path)
44
- execute(:rm, '-f', "#{fetch(:tmp_dir)}/#{fetch(:application)}_#{fetch(:stage)}.tar.gz")
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
45
32
  end
46
33
  end
47
34
 
48
- desc 'Determine the revision that will be deployed'
49
- task set_current_revision: :'git_copy:wrapper' do
50
- revision = `cd #{fetch(:local_repo_path)} && git rev-parse --short HEAD 2>/dev/null`.strip
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
51
42
 
52
43
  on release_roles :all do
53
- set :current_revision, revision
44
+ git_copy_utility.release
54
45
  end
55
46
  end
56
47
 
57
- desc 'Clean up temp dir'
58
- task :cleanup do
59
- tmp_path = fetch(:git_copy_tmp_path)
60
-
61
- if File.exists?(tmp_path)
62
- system("rm -rf #{tmp_path}")
63
- print "Removed #{tmp_path}\n"
64
- else
65
- print "Nothing to cleanup (#{tmp_path} not found)\n"
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
66
52
  end
67
53
  end
68
54
 
69
- task update_local_working_copy: :'git_copy:wrapper' do
70
- tmp_path = fetch(:git_copy_tmp_path)
71
-
72
- set :local_repo_path, File.join(tmp_path, 'repo')
73
- set :local_tar_file, File.join(tmp_path, 'archive.tar.gz')
74
-
75
- # track if the repo url has changed
76
- local_repo_url = `cd #{fetch(:local_repo_path)} 2>/dev/null && git config --get remote.origin.url 2>/dev/null`.strip
77
- system("rm -rf #{tmp_path}") unless fetch(:repo_url) == local_repo_url
78
-
79
- # prepare temp directory
80
- system("mkdir -p #{tmp_path}")
81
-
82
- # clone repository if necessary
83
- unless File.exists?(fetch(:local_repo_path))
84
- system("git clone #{fetch(:repo_url)} #{fetch(:local_repo_path)}")
55
+ desc 'Clean repo cache'
56
+ task :cleanup do
57
+ run_locally do
58
+ git_copy_utility.cleanup
85
59
  end
86
-
87
- # update repository
88
- system("cd #{fetch(:local_repo_path)} && git fetch origin && git fetch origin --tags")
89
-
90
- # reset repository
91
- system("cd #{fetch(:local_repo_path)} && git reset --hard #{fetch(:branch, 'master')} 2>/dev/null")
92
- system("cd #{fetch(:local_repo_path)} && git reset --hard origin/#{fetch(:branch, 'master')} 2>/dev/null")
93
-
94
- # init and update submodules
95
- system("cd #{fetch(:local_repo_path)} && git submodule init && git submodule update")
96
- system("cd #{fetch(:local_repo_path)} && git submodule foreach --recursive git submodule update --init")
97
-
98
- # clean up working directory
99
- system("cd #{fetch(:local_repo_path)} && git clean -d -f")
100
- system("cd #{fetch(:local_repo_path)} && git submodule foreach --recursive git clean -d -f")
101
60
  end
102
61
  end
@@ -0,0 +1,167 @@
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
@@ -1,8 +1,11 @@
1
+ # Capistrano
1
2
  module Capistrano
3
+ # Git
2
4
  module Git
5
+ # Copy
3
6
  module Copy
4
7
  # gem version
5
- VERSION = '0.6.3'
8
+ VERSION = '0.7.0'
6
9
  end
7
10
  end
8
11
  end
@@ -4,7 +4,7 @@
4
4
  from __future__ import print_function
5
5
  from __future__ import unicode_literals
6
6
 
7
- __version__ = "1.8"
7
+ __version__ = "1.9"
8
8
 
9
9
  import logging
10
10
  from os import extsep, path, readlink
@@ -79,7 +79,7 @@ class GitArchiver(object):
79
79
  Create the archive at output_file_path.
80
80
 
81
81
  Type of the archive is determined either by extension of output_file_path or by output_format.
82
- Supported formats are: gz, zip, bz2, tar, tgz
82
+ Supported formats are: gz, zip, bz2, xz, tar, tgz, txz
83
83
 
84
84
  @param output_path: Output file path.
85
85
  @type output_path: string
@@ -108,11 +108,13 @@ class GitArchiver(object):
108
108
  i.create_system = 3
109
109
  i.external_attr = 0xA1ED0000
110
110
  archive.writestr(i, readlink(file_path))
111
- elif output_format in ['tar', 'bz2', 'gz', 'tgz']:
111
+ elif output_format in ['tar', 'bz2', 'gz', 'xz', 'tgz', 'txz']:
112
112
  if output_format == 'tar':
113
113
  t_mode = 'w'
114
114
  elif output_format == 'tgz':
115
115
  t_mode = 'w:gz'
116
+ elif output_format == 'txz':
117
+ t_mode = 'w:xz'
116
118
  else:
117
119
  t_mode = 'w:{0}'.format(output_format)
118
120
 
@@ -428,8 +430,8 @@ if __name__ == '__main__':
428
430
  parser.add_option('--prefix',
429
431
  type='string',
430
432
  dest='prefix',
431
- default='',
432
- help="prepend PREFIX to each filename in the archive. OUTPUT_FILE name is used by default to avoid tarbomb")
433
+ default=None,
434
+ help="prepend PREFIX to each filename in the archive. OUTPUT_FILE name is used by default to avoid tarbomb. You can set it to '' in order to explicitly request tarbomb")
433
435
 
434
436
  parser.add_option('-v', '--verbose',
435
437
  action='store_true',
@@ -469,13 +471,13 @@ if __name__ == '__main__':
469
471
  parser.error("You cannot use directory as output")
470
472
 
471
473
  # avoid tarbomb
472
- if options.prefix:
474
+ if options.prefix is not None:
473
475
  options.prefix = path.join(options.prefix, '')
474
476
  else:
475
477
  import re
476
478
 
477
479
  output_name = path.basename(output_file_path)
478
- output_name = re.sub('(\.zip|\.tar|\.tgz|\.gz|\.bz2|\.tar\.gz|\.tar\.bz2)$', '', output_name) or "Archive"
480
+ output_name = re.sub('(\.zip|\.tar|\.tgz|\.txz|\.gz|\.bz2|\.xz|\.tar\.gz|\.tar\.bz2|\.tar\.xz)$', '', output_name) or "Archive"
479
481
  options.prefix = path.join(output_name, '')
480
482
 
481
483
  try:
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.6.3
4
+ version: 0.7.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-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -80,18 +80,18 @@ extensions: []
80
80
  extra_rdoc_files: []
81
81
  files:
82
82
  - ".gitignore"
83
+ - ".gitmodules"
83
84
  - Gemfile
84
85
  - LICENSE.txt
85
86
  - README.md
86
87
  - Rakefile
87
88
  - capistrano-git-copy.gemspec
88
- - lib/capistrano-git-copy.rb
89
89
  - lib/capistrano/git/copy.rb
90
- - lib/capistrano/git/copy/deploy.rb
91
90
  - lib/capistrano/git/copy/tasks/deploy.cap
91
+ - lib/capistrano/git/copy/utility.rb
92
92
  - lib/capistrano/git/copy/version.rb
93
93
  - lib/capistrano/git_copy.rb
94
- - vendor/bin/git-archive-all
94
+ - vendor/git-archive-all/git-archive-all
95
95
  homepage: https://github.com/ydkn/capistrano-git-copy
96
96
  licenses:
97
97
  - MIT
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.4.5
115
+ rubygems_version: 2.4.6
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Copy local git repository deploy strategy for capistrano
File without changes
@@ -1,3 +0,0 @@
1
- require 'tmpdir'
2
-
3
- load File.expand_path('../tasks/deploy.cap', __FILE__)