capistrano-demo 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c9e3886675994348216bf70fe0eec9129d2a747
4
+ data.tar.gz: e22139cf8964c663c81af921b2b3e7a8e5984a28
5
+ SHA512:
6
+ metadata.gz: c90ce90aeecd9d39298dd149b6f5d37a801e8fd68dc1fd1a6e92c6f092f5516704703c8c313c422e9d759b464bb9a94fb35a6748ae647f477608a3b5e0adc5c4
7
+ data.tar.gz: 808410ad115f5e5e2a516e7d04b0bb5dff3fe15bf3473a905c9a9517506ed0e7c08a81c81f0c6a4481aaa4669872734492e3da698156bdba81522e687d4ed45b
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-demo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 fc_arny
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Capistrano::Demo
2
+
3
+ Creating demo-host for git branch.
4
+
5
+ ## Requirements/Restrictions
6
+ * git
7
+ * nginx
8
+ * unicorn
9
+
10
+ Allow deploy user restart server or run other command without sudo password
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'capistrano-demo'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install capistrano-demo
25
+
26
+ In Capfile add line:
27
+
28
+ require 'capistrano/demo'
29
+
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+ ## TODO
36
+ 1. Database config
37
+ 2. Nginx config
38
+ 3. Unicorn config
39
+ 4.
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/capistrano-demo/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'capistrano-demo'
6
+ spec.version = '0.0.3'
7
+ spec.authors = ['Arthur Shcheglov (fc_arny)']
8
+ spec.email = ['arthur.shcheglov@gmail.com']
9
+ spec.summary = %q{Create demo-host by branch name}
10
+ spec.description = %q{Create demo-host by branch name}
11
+ spec.homepage = 'http://at-consulting.ru'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_dependency 'capistrano', '~> 3.1'
19
+ # spec.add_dependency 'yaml_db', '~> 0.3.0'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10.0'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 3.2.0'
24
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/db.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/setup.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/demo.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/utils.rake", __FILE__)
@@ -0,0 +1,28 @@
1
+ # require 'yaml_db'
2
+
3
+ require_relative 'demo/tasks'
4
+ require_relative 'demo/setup'
5
+ require_relative 'demo/utils'
6
+ require_relative 'demo/db'
7
+
8
+ def demo_branch
9
+ fetch(:demo_branch, `git rev-parse --abbrev-ref HEAD`.strip).downcase
10
+ end
11
+
12
+ def demo_host
13
+ fetch(:demo_host)
14
+ end
15
+
16
+ def demo_url
17
+ format("%s.%s", demo_branch, demo_host)
18
+ end
19
+
20
+ def demo_dir
21
+ deploy_path.join('demo', demo_branch)
22
+ end
23
+
24
+ def demo_default_db
25
+ format("%s_%s", fetch(:application), fetch(:stage))
26
+ end
27
+
28
+
@@ -0,0 +1 @@
1
+ # TODO: task for work with database - create/clone/delete etc
@@ -0,0 +1,62 @@
1
+ namespace :demo do
2
+
3
+ desc 'Chain of task for creating demo-host'
4
+ task :create do
5
+ %w{code configs gems db assets}.each do |task|
6
+ invoke "demo:setup:#{task}"
7
+ end
8
+
9
+ invoke 'demo:restart'
10
+
11
+ msg = "* Demo host created => http://#{demo_url} *"
12
+
13
+ puts '*' * msg.length, msg, '*' * msg.length
14
+ end
15
+
16
+ desc 'Destroy demo-host'
17
+ task :destroy => [:'setup:branch'] do
18
+ on roles(fetch(:demo_role)) do
19
+ # TODO: remove nginx config
20
+ execute :rm, '-rf', fetch(:demo_dir)
21
+ end
22
+ end
23
+
24
+ desc 'TODO: Update demo-host'
25
+ task :update => [:'setup:branch']do
26
+ # set :tasks, ask('what do you want to update (code, db, assets, gems, settings)?', 'code')
27
+ %w{code configs gems db assets}.each do |task|
28
+ invoke "demo:setup:#{task}"
29
+ end
30
+
31
+ invoke 'demo:restart'
32
+ end
33
+
34
+ desc 'Restart servers (for example app, web, sidekiq etc)'
35
+ task :restart => [:'setup:branch'] do
36
+ on roles(fetch(:demo_role)) do
37
+ fetch(:demo_app_restart_cmd)
38
+ fetch(:demo_web_restart_cmd)
39
+ end
40
+ end
41
+ end
42
+
43
+ namespace :load do
44
+ task :defaults do
45
+ set :demo_role, :all
46
+ set :demo_branch, demo_branch
47
+
48
+ set :demo_dir, -> { demo_dir }
49
+ set :demo_host, fetch(:application)
50
+
51
+ set :demo_db, -> { demo_default_db }
52
+
53
+ set :demo_app_restart_cmd, -> { raise 'You mast specify "demo_app_restart_cmd" proc for creating demo-host' }
54
+ set :demo_web_restart_cmd, -> { on roles(fetch(:demo_role)) do execute :sudo, :service, 'nginx restart' end }
55
+
56
+ set :demo_linked_dirs, %w(public/uploads)
57
+ set :demo_copied_dirs, %w(vendor/cache)
58
+
59
+ set :demo_templates_dir, nil
60
+ set :demo_templates_entries, []
61
+ end
62
+ end
@@ -0,0 +1,95 @@
1
+ namespace :demo do
2
+ namespace :setup do
3
+ task :branch do
4
+ set :demo_branch, ask('branch for demo-host', demo_branch)
5
+ set :demo_db, ask('database name', fetch(:demo_db, demo_default_db))
6
+ end
7
+
8
+ desc 'Fetch code from repo\'s branch'
9
+ task :code => [:branch] do
10
+ set :branch, demo_branch
11
+
12
+ on roles(fetch(:demo_role)) do
13
+ # Create dir for demo-host
14
+ execute :mkdir, "-p #{fetch(:demo_dir)}"
15
+
16
+ # Upload code
17
+ with fetch(:git_environmental_variables) do
18
+ within repo_path do
19
+ set :release_path, fetch(:demo_dir)
20
+ strategy.update
21
+ strategy.release
22
+ end
23
+ end
24
+
25
+ invoke 'demo:utils:link_dirs'
26
+ invoke 'demo:utils:copy_dirs'
27
+ end
28
+ end
29
+
30
+ desc 'Install gems'
31
+ task :gems => [:code] do
32
+ set :bundle_gemfile, demo_dir.join('Gemfile')
33
+
34
+ on roles(fetch(:demo_role)) do
35
+ invoke 'bundler:install'
36
+ end
37
+ end
38
+
39
+ desc 'Setting database name and run migration'
40
+ task :db => [:code, :configs] do
41
+ on roles(fetch(:demo_role)) do
42
+ within fetch(:demo_dir) do
43
+ with rails_env: fetch(:rails_env) do
44
+ # if fetch(:create_db).downcase == 'y'
45
+ # info '[Re]Creating database'
46
+ #
47
+ # invoke 'demo:utils:link_data'
48
+ # execute :rake, 'db:drop db:create db:schema:load db:data:load db:migrate'
49
+ # else
50
+ info 'Running migration'
51
+ execute :rake, 'db:migrate'
52
+ # end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ desc 'Setup server configs from templates'
59
+ task :configs => [:code] do
60
+ next if fetch(:demo_templates_dir).nil?
61
+
62
+ branch = demo_branch
63
+ db = fetch(:demo_db)
64
+
65
+ on roles(fetch(:demo_role)) do
66
+ within fetch(:demo_dir) do
67
+ fetch(:demo_templates_entries).each do |entry|
68
+ upload! StringIO.new(ERB.new(File.read(fetch(:demo_templates_dir) + entry[:template])).result(binding)), entry[:file]
69
+
70
+ next if entry[:link].nil?
71
+
72
+ unless test "[ -L #{entry[:link]} ]"
73
+ if test "[ -d #{entry[:link]} ]"
74
+ execute :rm, '-rf', entry[:link]
75
+ end
76
+ execute :ln, '-s', entry[:file], entry[:link]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ desc 'Precompile assets for demo host'
84
+ task :assets => [:code] do
85
+ on roles(fetch(:demo_role)) do
86
+ within fetch(:demo_dir) do
87
+ with rails_env: fetch(:rails_env) do
88
+ execute :rake, 'assets:precompile'
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,56 @@
1
+ namespace :demo do
2
+ namespace :utils do
3
+ # desc 'Create symlink to file'
4
+ # task :link_data do
5
+ # on roles(fetch(:demo_role)) do
6
+ # within fetch(:demo_dir) do
7
+ # source = fetch(:demo_db)
8
+ # target = fetch(:demo_dir).join('db', 'data.yml')
9
+ #
10
+ #
11
+ # unless test "[ -L #{target} ]"
12
+ # if test "[ -f #{target} ]"
13
+ # execute :rm, target
14
+ # end
15
+ # execute :sudo, :ln, '-s', source, target
16
+ # end
17
+ # end
18
+ # end
19
+ # end
20
+
21
+ desc 'Symlink directories'
22
+ task :link_dirs do
23
+ next unless any? :demo_linked_dirs
24
+ on roles(fetch(:demo_role)) do
25
+
26
+ fetch(:demo_linked_dirs).each do |dir|
27
+ target = fetch(:demo_dir).join(dir)
28
+ source = shared_path.join(dir)
29
+
30
+ unless test "[ -L #{target} ]"
31
+ if test "[ -d #{target} ]"
32
+ execute :rm, '-rf', target
33
+ end
34
+ execute :ln, '-s', source, target
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ desc 'Copy dirs (cache) for speed-up (by default bundler cache and precompiled assets)'
41
+ task :copy_dirs do
42
+ next unless any? :demo_copied_dirs
43
+
44
+ on roles(fetch(:demo_role)) do
45
+ fetch(:demo_copied_dirs).each do |dir|
46
+ source = shared_path.join(dir)
47
+ target = fetch(:demo_dir).join(dir)
48
+
49
+ execute :mkdir, '-p', target
50
+ execute :cp, '-an', "#{source}/. #{target}"
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+ describe Capistrano::Demo do
4
+ it "provides a --trace option which enables SSHKit/NetSSH trace output"
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'capistrano/demo'
5
+
6
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-demo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Arthur Shcheglov (fc_arny)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-30 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.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.10.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ description: Create demo-host by branch name
70
+ email:
71
+ - arthur.shcheglov@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - capistrano-demo.gemspec
82
+ - lib/capistrano-demo.rb
83
+ - lib/capistrano/demo.rb
84
+ - lib/capistrano/demo/db.rb
85
+ - lib/capistrano/demo/setup.rb
86
+ - lib/capistrano/demo/tasks.rb
87
+ - lib/capistrano/demo/utils.rb
88
+ - lib/capistrano/tasks/db.rake
89
+ - lib/capistrano/tasks/demo.rake
90
+ - lib/capistrano/tasks/setup.rake
91
+ - lib/capistrano/tasks/utils.rake
92
+ - spec/lib/demo_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: http://at-consulting.ru
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Create demo-host by branch name
118
+ test_files:
119
+ - spec/lib/demo_spec.rb
120
+ - spec/spec_helper.rb