capistrano-upload-configs 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 504fb99da9490dd7def34c25427c87a0d106e281
4
+ data.tar.gz: 53c1cde9aa39fa6174a5ccacd83953c52f77eccc
5
+ SHA512:
6
+ metadata.gz: 84c367649804dcda1e4aa0b7972a832cc19f9344ff4dea849c4a9db154df457dd2fba4e44cdc68d7dd930ca8b30edaf9013071d41532f8b8736425f5fa64ad5c
7
+ data.tar.gz: a926a3168949f68a0bce7a218b5645e5477aaaedf80b567a1c01cea7c8f6ffd555bb9311afdb6cab5059d55f57f02ed4d32a29600541cf0431506b933f6a0598
@@ -0,0 +1,3 @@
1
+ ## 0.0.1
2
+
3
+ - First release.
@@ -0,0 +1,31 @@
1
+ Capistrano plugin - Upload Configs
2
+ ----------------------------------
3
+
4
+ Capistrano plugin for Upload local config files to remote, and create soft link.
5
+
6
+ For example:
7
+
8
+ - config/app.yml
9
+ - config/database.yml
10
+ - etc/nginx/nginx.conf -> /etc/nginx/nginx.conf
11
+ - etc/nginx/ssl/foo.key -> /etc/nginx/ssl/foo.key
12
+
13
+
14
+ ```rb
15
+ append :linked_files, *%w(
16
+ config/app.yml
17
+ config/database.yml
18
+ )
19
+
20
+ # will link with absolute path
21
+ set :absolute_linked_files, %w(
22
+ etc/nginx/nginx.conf
23
+ etc/nginx/ssl/foo.key
24
+ )
25
+ ```
26
+
27
+ ## Tasks
28
+
29
+ - cap production config:check
30
+ - cap production config:push
31
+ - cap production config:pull
@@ -0,0 +1,76 @@
1
+ def get_local_config_name(config, stage)
2
+ path = File.dirname(config)
3
+ extension = File.extname(config)
4
+ filename = File.basename(config, extension)
5
+ extension.sub!(/^\./, '')
6
+ local_file = [filename, stage].join('.')
7
+ local_file = [local_file, extension].join('.') unless extension.empty?
8
+ local_path = File.join(path, local_file)
9
+ end
10
+
11
+ namespace :config do
12
+ desc 'Check local configuration files for each stage'
13
+ task :check do
14
+ run_locally do
15
+ fetch(:config_files).each do |config|
16
+ local_path = get_local_config_name(config, fetch(:stage).to_s)
17
+ if File.exists?(local_path)
18
+ info "Found: #{local_path}"
19
+ else
20
+ warn "Not found: #{local_path}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ desc 'Push configuration to the remote server'
27
+ task :push do
28
+ on release_roles :all do
29
+ within shared_path do
30
+ use_stage_remotely = fetch(:config_use_stage_remotely)
31
+ fetch(:config_files).each do |config|
32
+ local_path = get_local_config_name(config, fetch(:stage).to_s)
33
+ server_name = use_stage_remotely ? local_path.split('/').last : config
34
+ if File.exists?(local_path)
35
+ info "Uploading config #{local_path} as #{server_name}"
36
+ remote_path = File.join(shared_path, server_name)
37
+ execute :mkdir, "-p", File.dirname(remote_path)
38
+ upload! StringIO.new(IO.read(local_path)), remote_path
39
+ else
40
+ fail "#{local_path} doesn't exist"
41
+ end
42
+ end
43
+
44
+ fetch(:absolute_linked_files).each do |config|
45
+ local_path = get_local_config_name(config, fetch(:stage).to_s)
46
+ server_name = use_stage_remotely ? local_path.split('/').last : config
47
+ sudo :ln, "-sf #{shared_path}/#{server_name} /#{server_name}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ desc 'Pull configuration from the remote server'
54
+ task :pull do
55
+ on release_roles :all do
56
+ within shared_path do
57
+ use_stage_remotely = fetch(:config_use_stage_remotely)
58
+ fetch(:config_files).each do |config|
59
+ local_path = get_local_config_name(config, fetch(:stage).to_s)
60
+ server_name = use_stage_remotely ? local_path.split('/').last : config
61
+ info "Downloading config #{server_name} as #{local_path} "
62
+ download! File.join(shared_path, server_name), local_path
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ namespace :load do
70
+ task :defaults do
71
+ set :config_files, -> { fetch(:linked_files) + fetch(:absolute_linked_files) }
72
+ set :config_use_stage_remotely, false
73
+ end
74
+ end
75
+
76
+ before 'deploy:check:linked_files', 'config:push'
@@ -0,0 +1 @@
1
+ require 'sshkit/sudo'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-upload-configs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sshkit-sudo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Capistrano plugin for Upload local config files to remote, and create
28
+ soft link.
29
+ email:
30
+ - huacnlee@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - README.md
37
+ - lib/capistrano/tasks/config.rake
38
+ - lib/capistrano/upload-configs.rb
39
+ homepage: https://github.com/huacnlee/capistrano-upload-configs
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.4.8
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Capistrano plugin for Upload local config files to remote, and create soft
63
+ link ...
64
+ test_files: []