capistrano-yutiriti 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41b3f4479b5404581279f996857a5742ec22d03e
4
+ data.tar.gz: 6deef239355524d00e632b243066de4142c1c7e7
5
+ SHA512:
6
+ metadata.gz: a0e8ac6d61cef53a5f54f9a84c1d88c50849e08da702632f38f70d2738edf66e24926f682640ce7f14a08910b10af23c364ba4063bd45f66df271f2654455eac
7
+ data.tar.gz: ac8ab06e29f1b4484a3ef5bbca6684d6ad7072c4b8e810984ede61eb597c144cc8df47a1ffc6a584dc910c6a105ff9f55531cf51f6a8b5da88bbeecaeb3841fe
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-yutiriti.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Martin Andert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # capistrano-yutiriti
2
+
3
+ WIP.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capistrano-yutiriti"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Martin Andert"]
9
+ spec.email = ["mandert@gmail.com"]
10
+
11
+ spec.summary = %q{capistrano-yutiriti}
12
+ spec.description = %q{capistrano-yutiriti}
13
+ spec.homepage = "https://github.com/martinandert/capistrano-yutiriti"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "capistrano", "~> 3.4"
19
+ end
@@ -0,0 +1,53 @@
1
+ namespace :buildpack do
2
+ desc "Compile the buildpack"
3
+ task :compile do
4
+ on roles :app do
5
+ url, branch = fetch(:buildpack_url).split('#')
6
+ next unless url
7
+
8
+ bp_dir = capture("mktemp -t buildpackXXXXX").chomp
9
+ execute "rm -rf #{bp_dir}"
10
+
11
+ if url =~ /\.tgz$/
12
+ execute "mkdir -p #{bp_dir}"
13
+ execute "curl -s #{url} | tar xvz -C #{bp_dir} >/dev/null 2>&1"
14
+ else
15
+ execute "git clone #{url} #{bp_dir} >/dev/null 2>&1"
16
+
17
+ within bp_dir do
18
+ if File.exist? ".gitmodules"
19
+ execute :git, "submodule update --init --recursive"
20
+ end
21
+
22
+ if branch
23
+ execute :git, "checkout", branch, "> /dev/null 2>&1"
24
+ end
25
+ end
26
+ end
27
+
28
+ within bp_dir do
29
+ execute :chmod, "-f +x bin/{detect,compile} || true"
30
+
31
+ execute :"bin/detect", release_path, "> /dev/null"
32
+ execute :"bin/compile", release_path, shared_path.join("cache/build"), shared_path.join("config/env")
33
+ end
34
+
35
+ export_file = "#{bp_dir}/export"
36
+
37
+ if test("[ -r #{export_file} ]")
38
+ execute "source #{export_file}"
39
+
40
+ exports = capture(:cat, export_file).split("\n").reject { |line| line =~ /^\s*$/ }.inject({}) do |memo, line|
41
+ key, value = line.split("=", 2)
42
+ key = key.strip.split(" ").last
43
+ memo.merge key => value.strip
44
+ end
45
+
46
+ set_config_vars exports
47
+ end
48
+ end
49
+ end
50
+
51
+ after "deploy:updated", "buildpack:compile"
52
+ end
53
+
@@ -0,0 +1,114 @@
1
+ desc "Display the config vars"
2
+ task :config do
3
+ path = config_path
4
+
5
+ on roles :app do
6
+ vars = capture(<<-EOCOMMAND)
7
+ config_path=#{path}
8
+ if [ -d "$config_path" ]
9
+ then for e in $(ls $config_path)
10
+ do echo "$e: $(cat $config_path/$e)"
11
+ done
12
+ fi
13
+ EOCOMMAND
14
+
15
+ puts vars
16
+ end
17
+ end
18
+
19
+ namespace :config do
20
+ def ignore(*args)
21
+ args.each do |arg|
22
+ Rake::Task.define_task arg.to_sym
23
+ end
24
+ end
25
+
26
+ desc "Import the config vars"
27
+ task :import do
28
+ on roles :app do
29
+ vars = capture(:cat, dot_env_path).split("\n").reject { |line| line =~ /^\s*$/ }.map { |var| var.split("=", 2) }.inject({}) do |memo, (key, value)|
30
+ memo.merge key => value
31
+ end
32
+
33
+ execute :rm, "-rf", config_path
34
+ set_config_vars vars
35
+ end
36
+ end
37
+
38
+ desc "Export the config vars"
39
+ task :export do
40
+ path = config_path
41
+
42
+ on roles :app do
43
+ execute <<-EOCOMMAND
44
+ config_path=#{path}
45
+ if [ -d "$config_path" ]
46
+ then for e in $(ls $config_path)
47
+ do export "$e=$(cat $config_path/$e)"
48
+ done
49
+ fi
50
+ EOCOMMAND
51
+ end
52
+ end
53
+
54
+ desc "Display a config value for KEY"
55
+ task :get do
56
+ on roles :app do
57
+ keys = ARGV[2..-1]
58
+
59
+ case keys.size
60
+ when 0
61
+ error "Usage: cap STAGE config:get KEY"
62
+ error "Must specify KEY."
63
+ when 1
64
+ key = keys.first
65
+
66
+ within config_path do
67
+ info capture(:cat, key)
68
+ end
69
+
70
+ ignore key
71
+ else
72
+ keys[1..-1].each do |key|
73
+ error "Invalid argument: \"#{key}\""
74
+ end
75
+
76
+ ignore(*keys)
77
+ end
78
+ end
79
+ end
80
+
81
+ desc "Set one or more config vars KEY1=VALUE1 [KEY2=VALUE2 ...]"
82
+ task :set do
83
+ on roles :app do
84
+ vars = ARGV[2..-1].map { |var| var.split("=", 2) }
85
+
86
+ if vars.empty? || vars.any? { |var| var.size != 2 }
87
+ error "Usage: cap STAGE config:set KEY1=VALUE1 [KEY2=VALUE2 ...]"
88
+ error "Must specify KEY and VALUE to set."
89
+
90
+ ignore(*vars.select { |var| var.size == 1 }.map(&:first))
91
+ else
92
+ vars = vars.inject({}) do |memo, (key, value)|
93
+ info "#{key}: #{value}"
94
+ memo.merge key => value
95
+ end
96
+
97
+ set_config_vars vars
98
+ end
99
+ end
100
+ end
101
+
102
+ desc "Unset one or more config vars KEY1 [KEY2 ...]"
103
+ task :unset do
104
+ on roles :app do
105
+ keys = ARGV[2..-1]
106
+
107
+ unset_config_vars keys
108
+
109
+ ignore(*keys)
110
+ end
111
+ end
112
+ end
113
+
114
+ set :linked_files, fetch(:linked_files, []).push(".env")
@@ -0,0 +1,46 @@
1
+ namespace :foreman do
2
+ task :setup do
3
+ invoke "foreman:export"
4
+ invoke "foreman:start"
5
+ end
6
+
7
+ desc "Export the Procfile"
8
+ task :export do
9
+ on roles :app do
10
+ options = {
11
+ app: fetch(:application),
12
+ log: File.join(shared_path, "log"),
13
+ }.merge fetch(:foreman_options, {})
14
+
15
+ execute :mkdir, "-p", options[:log]
16
+
17
+ within release_path do
18
+ sudo :foreman, "export", "upstart", "/etc/init", *options.map { |key, value| "--#{key}=\"#{value}\"" }
19
+ end
20
+ end
21
+ end
22
+
23
+ desc "Start the application services"
24
+ task :start do
25
+ on roles :app do
26
+ sudo :start, fetch(:application)
27
+ end
28
+ end
29
+
30
+ desc "Stop the application services"
31
+ task :stop do
32
+ on roles :app do
33
+ sudo :stop, fetch(:application)
34
+ end
35
+ end
36
+
37
+ desc "Restart the application services"
38
+ task :restart do
39
+ on roles :app do
40
+ sudo :restart, fetch(:application)
41
+ end
42
+ end
43
+
44
+ after "deploy:restart", "foreman:export"
45
+ after "deploy:restart", "foreman:restart"
46
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/buildpack.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/config.rake", __FILE__)
@@ -0,0 +1,54 @@
1
+ module Capistrano
2
+ module Yutiriti
3
+ module DSL
4
+ def config_path
5
+ shared_path.join("config")
6
+ end
7
+
8
+ def dot_env_path
9
+ shared_path.join(".env")
10
+ end
11
+
12
+ def set_config_vars(vars = {})
13
+ return if vars.empty?
14
+
15
+ execute :mkdir, "-p", config_path
16
+
17
+ within config_path do
18
+ vars.each do |key, value|
19
+ execute :echo, value, ">", key
20
+ end
21
+ end
22
+
23
+ update_dot_env
24
+ end
25
+
26
+ def unset_config_vars(keys)
27
+ return if keys.empty?
28
+
29
+ execute :mkdir, "-p", config_path
30
+
31
+ within config_path do
32
+ execute :rm, "-f", *keys
33
+ end
34
+
35
+ update_dot_env
36
+ end
37
+
38
+ def update_dot_env
39
+ execute <<-EOCOMMAND
40
+ config_path=#{config_path}
41
+ dot_env_path=#{dot_env_path}
42
+ rm -f $dot_env_path
43
+ mkdir -p $config_path
44
+ for e in $(ls $config_path)
45
+ do echo "$e=$(cat $config_path/$e)" >> $dot_env_path
46
+ done
47
+ chmod 600 $dot_env_path
48
+ EOCOMMAND
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ include Capistrano::Yutiriti::DSL
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/foreman.rake", __FILE__)
@@ -0,0 +1,4 @@
1
+ require "capistrano/yutiriti/dsl"
2
+ require "capistrano/yutiriti/buildpack"
3
+ require "capistrano/yutiriti/config"
4
+ require "capistrano/yutiriti/foreman"
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-yutiriti
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Andert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-11 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.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ description: capistrano-yutiriti
28
+ email:
29
+ - mandert@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - capistrano-yutiriti.gemspec
40
+ - lib/capistrano/tasks/buildpack.rake
41
+ - lib/capistrano/tasks/config.rake
42
+ - lib/capistrano/tasks/foreman.rake
43
+ - lib/capistrano/yutiriti.rb
44
+ - lib/capistrano/yutiriti/buildpack.rb
45
+ - lib/capistrano/yutiriti/config.rb
46
+ - lib/capistrano/yutiriti/dsl.rb
47
+ - lib/capistrano/yutiriti/foreman.rb
48
+ homepage: https://github.com/martinandert/capistrano-yutiriti
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.4.5
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: capistrano-yutiriti
71
+ test_files: []