hat 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 +7 -0
- data/.gitignore +17 -0
- data/Capfile +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/hat +3 -0
- data/deploy.yml +21 -0
- data/hat.gemspec +28 -0
- data/lib/hat.rb +16 -0
- data/lib/hat/deployment.rb +52 -0
- data/lib/hat/recipes.rb +41 -0
- data/lib/hat/stage.rb +33 -0
- data/lib/hat/version.rb +3 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afc59ac07f96b058c96802f388b6647031ae625b
|
4
|
+
data.tar.gz: 75400e0a322ae58c21e346ad3f22ead37b862dbc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55c8217308a9e7ec95d9a257b492e05d7efdabdea6709371171f8c8ba5bee39637c1cc3722e9199ac0583f798c8689ead995becba7f3dc102348acdee68e1d30
|
7
|
+
data.tar.gz: 94dc8692adcb91a32d8f8fb7ae630117f4e186b7c6f4ec0c1efc1c7895b9a30244ae1524cb6044087d0b7894d8d4ffe8bbeb42ec9e4d22abcaf5219e4b3c3756
|
data/.gitignore
ADDED
data/Capfile
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Marcin Stecki
|
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,29 @@
|
|
1
|
+
# Hat
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hat'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install hat
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hat
ADDED
data/deploy.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
recipes:
|
2
|
+
url: git@github.com:sample/recipes/repo.git
|
3
|
+
use:
|
4
|
+
- default_recipe
|
5
|
+
|
6
|
+
defaults:
|
7
|
+
some_var: with_value
|
8
|
+
|
9
|
+
stages:
|
10
|
+
staging:
|
11
|
+
webserver: "some server somewhere"
|
12
|
+
other: "variable"
|
13
|
+
|
14
|
+
production:
|
15
|
+
webserver: "production stage"
|
16
|
+
use:
|
17
|
+
- extra
|
18
|
+
- recipes
|
19
|
+
- for
|
20
|
+
- production
|
21
|
+
|
data/hat.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hat"
|
8
|
+
spec.version = Hat::VERSION
|
9
|
+
spec.authors = ["Marcin Stecki"]
|
10
|
+
spec.email = ["marcin@netguru.pl"]
|
11
|
+
spec.summary = %q{Capistrano deployments from yml files.}
|
12
|
+
spec.description = %q{Hat for your cap. Enabled you to move your deployment code our from the repoistory with ease - leaving just one simple config file.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_dependency "capistrano", "~> 3.0"
|
25
|
+
spec.add_dependency "git", "~> 1.2"
|
26
|
+
spec.add_dependency "konf"
|
27
|
+
|
28
|
+
end
|
data/lib/hat.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "hat/version"
|
2
|
+
require "hat/deployment"
|
3
|
+
|
4
|
+
module Hat
|
5
|
+
# Your code goes here...
|
6
|
+
|
7
|
+
def self.default_config_file
|
8
|
+
"deploy.yml"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.deploy(stage_name, file_name, *args)
|
12
|
+
deployment = Deployment.new(stage_name, file_name)
|
13
|
+
deployment.run
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'konf'
|
3
|
+
require 'capistrano/all'
|
4
|
+
require 'capistrano/setup'
|
5
|
+
require 'capistrano/deploy'
|
6
|
+
require 'hat/recipes'
|
7
|
+
require 'hat/stage'
|
8
|
+
require 'bundler'
|
9
|
+
module Hat
|
10
|
+
class Deployment
|
11
|
+
|
12
|
+
attr_accessor :configuration, :cap, :stage_name
|
13
|
+
|
14
|
+
def initialize stage_name, file_name = nil
|
15
|
+
self.configuration = Konf.new(file_name || 'deploy.yml')
|
16
|
+
self.stage_name = stage_name || "staging"
|
17
|
+
self.cap = Capistrano::Application.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
recipes.download
|
22
|
+
run_with_bundler(recipes.gemfile) do
|
23
|
+
stage.set_defaults(configuration['defaults'])
|
24
|
+
stage.define_task(recipes)
|
25
|
+
cap.invoke stage.name # http://capistranorb.com/documentation/advanced-features/capistrano-pure-ruby/
|
26
|
+
cap.invoke 'deploy'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def recipes
|
33
|
+
@recipes ||= Recipes.new(configuration['recipes'] || {})
|
34
|
+
end
|
35
|
+
|
36
|
+
def stage
|
37
|
+
@stage ||= Stage.new(stage_name, configuration['stages'][stage_name] || {}, recipes.list)
|
38
|
+
end
|
39
|
+
|
40
|
+
def run_with_bundler(gemfile)
|
41
|
+
if File.exists?(gemfile)
|
42
|
+
Bundler.with_clean_env do
|
43
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
44
|
+
Bundler.setup
|
45
|
+
yield
|
46
|
+
end
|
47
|
+
else
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/hat/recipes.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'fileutils'
|
3
|
+
module Hat
|
4
|
+
class Recipes
|
5
|
+
|
6
|
+
attr_accessor :url, :list
|
7
|
+
|
8
|
+
def initialize options
|
9
|
+
self.url = options['url']
|
10
|
+
self.list = options['use'] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def download
|
14
|
+
if File.directory?(url)
|
15
|
+
FileUtils.rm_rf(dir) if File.directory?(dir)
|
16
|
+
FileUtils.cp_r(url, Dir.tmpdir)
|
17
|
+
else
|
18
|
+
if File.directory?(dir)
|
19
|
+
Git.open(dir).pull
|
20
|
+
else
|
21
|
+
Git.clone(url, repo_name, path: Dir.tmpdir)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def dir
|
27
|
+
@dir ||= File.join(Dir.tmpdir, repo_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def gemfile
|
31
|
+
File.join(dir, 'Gemfile')
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def repo_name
|
37
|
+
@repo_name ||= File.basename(url, ".git")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/hat/stage.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Hat
|
2
|
+
class Stage
|
3
|
+
attr_accessor :name, :configuration
|
4
|
+
|
5
|
+
def initialize name, configuration, list
|
6
|
+
self.name = name.to_sym
|
7
|
+
self.configuration = configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_defaults(defaults)
|
11
|
+
configuration.merge!(Hash[defaults])
|
12
|
+
end
|
13
|
+
|
14
|
+
def define_task(recipes)
|
15
|
+
conf = self.configuration
|
16
|
+
name = self.name
|
17
|
+
|
18
|
+
task = Rake::Task.define_task(name) do
|
19
|
+
invoke 'load:defaults'
|
20
|
+
conf.each do |k, v|
|
21
|
+
set k.to_sym, v
|
22
|
+
end
|
23
|
+
recipes.list.each{|l| load "#{recipes.dir}/recipes/#{l}.rb" }
|
24
|
+
set(:stage, name)
|
25
|
+
load "capistrano/#{fetch(:scm)}.rb"
|
26
|
+
I18n.locale = fetch(:locale, :en)
|
27
|
+
configure_backend
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/hat/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcin Stecki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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: capistrano
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: git
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: konf
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Hat for your cap. Enabled you to move your deployment code our from the
|
98
|
+
repoistory with ease - leaving just one simple config file.
|
99
|
+
email:
|
100
|
+
- marcin@netguru.pl
|
101
|
+
executables:
|
102
|
+
- hat
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- .gitignore
|
107
|
+
- Capfile
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/hat
|
113
|
+
- deploy.yml
|
114
|
+
- hat.gemspec
|
115
|
+
- lib/hat.rb
|
116
|
+
- lib/hat/deployment.rb
|
117
|
+
- lib/hat/recipes.rb
|
118
|
+
- lib/hat/stage.rb
|
119
|
+
- lib/hat/version.rb
|
120
|
+
homepage: ''
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.0.3
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Capistrano deployments from yml files.
|
144
|
+
test_files: []
|