capistrano-scm-copy_strategy 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eafd8fc55f08df16dbd7526cf0dda903b9ba9e94
4
+ data.tar.gz: b4bb921c26e7e5448e8be48e6627878411094f52
5
+ SHA512:
6
+ metadata.gz: ef0bf6e4deb54cf2084adea99e9c1522e43419bfe2fe83c82e15a2f28f91a5204db050c56c2b1f95cf58b906e99a9356422c8cf66d9627566cac30983cd1a06e
7
+ data.tar.gz: f780ca9e6dc7cab19f582edadc6c50cd863127aa6d3bfe7ebba6f7c7f365e460aa3f92a070465c5783692d0db8112fd567e039ec8ae4e7f4216230ff7971ec0c
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ Gemfile.lock
3
+
4
+ .tmp
5
+ .idea
6
+ *.iml
7
+
8
+ # OS generated files #
9
+ ######################
10
+ .DS_Store
11
+ .DS_Store?
12
+ ._*
13
+ .Spotlight-V100
14
+ .Trashes
15
+ ehthumbs.db
16
+ Thumbs.db
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ capistrano-scm-copy_strategy
2
+ ============================
3
+
4
+ A copy strategy for Capistrano 3, which mimics the `:copy` scm of Capistrano 2.
5
+
6
+ This will make Capistrano tar the current directory, upload it to the server(s) and then extract it in the release directory.
7
+
8
+
9
+ Installation
10
+ ============
11
+
12
+ First make sure you install the capistrano-scm-copy_strategy by adding it to your `Gemfile`:
13
+
14
+ gem "capistrano-scm-copy_strategy"
15
+
16
+ Add to Capfile:
17
+
18
+ require 'capistrano/scm/copy_strategy'
19
+ install_plugin Capistrano::SCM::CopyStrategy
20
+
21
+ TODO
22
+ ====
23
+
24
+ I'm new to programming for Capistrano and even Ruby in general. So any feedback is appreciated.
25
+
26
+ License
27
+ =======
28
+
29
+ The MIT License (MIT)
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'capistrano-scm-copy_strategy'
3
+ s.version = '0.1.0'
4
+ s.date = '2017-04-10'
5
+ s.summary = "A copy strategy for Capistrano 3, which mimics the :copy scm of Capistrano 2."
6
+ s.description = "This will make Capistrano tar the current directory, upload it to the server(s) and then extract it in the release directory."
7
+
8
+ s.authors = ["Alberto Brino"]
9
+ s.email = 'alberto.brino@gmail.com'
10
+ s.homepage =
11
+ 'http://www.albertobrino.com'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ # s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ s.add_dependency "capistrano", "~> 3.0"
21
+ end
@@ -0,0 +1,69 @@
1
+ require "capistrano/scm/plugin"
2
+ require 'fileutils'
3
+ require 'tempfile' # Dir.tmpdir
4
+
5
+ # By convention, Capistrano plugins are placed in the
6
+ # Capistrano namespace. This is completely optional.
7
+ module Capistrano
8
+ class SCM::CopyStrategy < ::Capistrano::SCM::Plugin
9
+ def set_defaults
10
+ # Define any variables needed to configure the plugin.
11
+ set_if_empty :include_dir, "."
12
+ set_if_empty :archive_name, "#{env.release_timestamp}.tar.gz"
13
+ set_if_empty :temp_folder, "#{Dir.tmpdir}"
14
+
15
+ end
16
+
17
+ def register_hooks
18
+ after "deploy:new_release_path", "copy_strategy:create_release"
19
+ before "deploy:check", "copy_strategy:check"
20
+ end
21
+
22
+ def define_tasks
23
+ eval_rakefile File.expand_path("../tasks/copy-strategy.rake", __FILE__)
24
+ end
25
+
26
+ def check_server
27
+ backend.test :tar, "--version"
28
+ end
29
+
30
+ def check_repo_dir
31
+ if !backend.test " [ -d #{repo_path} ] "
32
+ backend.execute :mkdir, "-p", repo_path
33
+ else
34
+ backend.test :rm, "#{repo_path}/*"
35
+ end
36
+ end
37
+
38
+ def create_archive
39
+ archive_name = fetch(:archive_name)
40
+ include_dir = fetch(:include_dir)
41
+ exclude_dirs = Array(fetch(:exclude_dirs))
42
+ exclude_dirs.push(archive_name)
43
+ temp_folder = fetch(:temp_folder)
44
+
45
+ warn temp_folder
46
+
47
+ FileUtils.copy_entry include_dir, "#{temp_folder}/#{env.release_timestamp}"
48
+
49
+ # sh "ls -al #{temp_folder}/#{env.release_timestamp}"
50
+
51
+ exclude_dirs.map { |dir| FileUtils.rm_rf "#{temp_folder}/#{env.release_timestamp}/#{dir}" }
52
+
53
+ sh "ls -al #{temp_folder}/#{env.release_timestamp}"
54
+
55
+ tar_verbose = fetch(:tar_verbose, true) ? "v" : ""
56
+
57
+ cmd = ["tar", "-c#{tar_verbose}zf", archive_name, "-C #{temp_folder}/#{env.release_timestamp}", '.']
58
+ sh cmd.join(' ')
59
+ return archive_name
60
+ end
61
+
62
+
63
+ def archive_to_release_path
64
+ backend.execute :mkdir, "-p", release_path
65
+ backend.execute :tar, "-xf", "#{repo_path}/#{fetch(:archive_name)}", "-C", release_path
66
+ backend.execute :rm, "#{repo_path}/#{fetch(:archive_name)}"
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+
2
+ # This trick lets us access the Svn plugin within `on` blocks.
3
+ copy_strategy_plugin = self
4
+
5
+ namespace :copy_strategy do
6
+ desc "Check server compatibility"
7
+ task :check do
8
+ on release_roles :all do
9
+ copy_strategy_plugin.check_server
10
+ end
11
+ end
12
+ desc "Copy repo to releases"
13
+ task create_release: :'copy_strategy:update' do
14
+ on release_roles :all do
15
+ within repo_path do
16
+ warn "test, on: 3"
17
+ copy_strategy_plugin.archive_to_release_path
18
+ end
19
+ end
20
+ end
21
+
22
+ desc "Update code"
23
+ task update: :'copy_strategy:clean' do
24
+ on release_roles :all do
25
+ archive = copy_strategy_plugin.create_archive
26
+ upload!(archive, repo_path)
27
+ end
28
+ end
29
+
30
+ desc "Clean old revisions or initialize"
31
+ task :clean do
32
+ on release_roles :all do
33
+ within deploy_path do
34
+ copy_strategy_plugin.check_repo_dir
35
+ end
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-scm-copy_strategy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alberto Brino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-10 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: This will make Capistrano tar the current directory, upload it to the
28
+ server(s) and then extract it in the release directory.
29
+ email: alberto.brino@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - README.md
36
+ - capistrano-scm-copy_strategy.gemspec
37
+ - lib/capistrano/scm/copy-strategy.rb
38
+ - lib/capistrano/scm/tasks/copy-strategy.rake
39
+ homepage: http://www.albertobrino.com
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.6.11
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A copy strategy for Capistrano 3, which mimics the :copy scm of Capistrano
63
+ 2.
64
+ test_files: []