skynet-deploy 1.1.0 → 1.2.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.
- data/lib/skynet/app.rb +29 -10
- data/lib/skynet/builder/base.rb +2 -0
- data/lib/skynet/cli.rb +18 -0
- data/lib/skynet/hook_generator.rb +29 -0
- data/lib/skynet/templates/config.yml +4 -12
- data/lib/skynet/version.rb +1 -1
- data/lib/skynet.rb +1 -0
- data/skynet.gemspec +1 -0
- metadata +20 -3
data/lib/skynet/app.rb
CHANGED
@@ -6,27 +6,46 @@ module Skynet
|
|
6
6
|
|
7
7
|
class App < Sinatra::Base
|
8
8
|
|
9
|
+
before do
|
10
|
+
@payload = JSON.parse params[:payload] unless params[:payload].nil?
|
11
|
+
end
|
12
|
+
|
9
13
|
get '/' do
|
10
14
|
%[Hello. Check <a href="https://github.com/coshx/skynet">github</a> for more infomation on skynet]
|
11
15
|
end
|
12
16
|
|
17
|
+
post '/' do
|
18
|
+
Skynet.logger.debug "post root params: #{params.inspect}"
|
19
|
+
app_name = settings.config.each { |n, c| break n if c[:url] == @payload['repository']['url'] }
|
20
|
+
if app_name.is_a? String
|
21
|
+
deploy app_name
|
22
|
+
else
|
23
|
+
Skynet.logger.warn "Could not find application to deploy"
|
24
|
+
"42"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
13
28
|
post '/:app_name' do |app_name|
|
14
|
-
Skynet.logger.debug "params: #{params.inspect}"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
Skynet.logger.debug "post /#{app_name} params: #{params.inspect}"
|
30
|
+
deploy app_name
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def deploy(app_name)
|
36
|
+
Skynet.logger.info %{Attempting to deploy "#{app_name.class.name}"}
|
37
|
+
config = settings.config[app_name]
|
38
|
+
if deployable? config
|
39
|
+
Builder.build app_name, config, branch
|
19
40
|
else
|
20
41
|
Skynet.logger.warn "#{app_name} is not deployable"
|
21
42
|
end
|
22
43
|
"42"
|
23
44
|
end
|
24
45
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@config.present? &&
|
29
|
-
@config[:url] == @payload['repository']['url'] &&
|
46
|
+
def deployable?(config)
|
47
|
+
config.present? &&
|
48
|
+
config[:url] == @payload['repository']['url'] &&
|
30
49
|
@payload['after'] !~ /^0{40}$/
|
31
50
|
end
|
32
51
|
|
data/lib/skynet/builder/base.rb
CHANGED
@@ -27,6 +27,8 @@ module Skynet
|
|
27
27
|
@key = config[:key]
|
28
28
|
|
29
29
|
if config[:branches].blank?
|
30
|
+
Skynet.logger.warn "Passing a single branch and destination is deprecated and will be removed in 2.0"
|
31
|
+
Skynet.logger.warn "Please change to:\nbranches:\n #{config[:branch]}: #{config[:destination]}"
|
30
32
|
self.branches = { config[:branch] => config[:destination] }
|
31
33
|
else
|
32
34
|
self.branches = config[:branches]
|
data/lib/skynet/cli.rb
CHANGED
@@ -97,6 +97,20 @@ module Skynet
|
|
97
97
|
run_wizard options[:file]
|
98
98
|
end
|
99
99
|
|
100
|
+
desc 'hook PROJECT_NAME', 'Generates an example post_receive hook for PROJECT_NAME'
|
101
|
+
method_option :file, type: :string, default: './config.yml', aliases: '-f', desc: 'Configuration file'
|
102
|
+
method_option :output, type: :string, default: './post-receive', aliases: '-o', desc: 'Output file'
|
103
|
+
method_option :server, type: :string, default: 'http://localhost:7575', aliases: '-s', desc: 'Location of running skynet server'
|
104
|
+
def hook(project)
|
105
|
+
if File.exists? options[:output]
|
106
|
+
Skynet.logger.fatal %{Output file "#{options[:output]}" already exists}
|
107
|
+
exit 1
|
108
|
+
end
|
109
|
+
config = load_configuration(options[:file])[project]
|
110
|
+
server = "#{options[:server].chomp '/'}/#{project}"
|
111
|
+
HookGenerator.new(config, server, options[:output]).generate
|
112
|
+
end
|
113
|
+
|
100
114
|
private
|
101
115
|
|
102
116
|
def run_wizard(file = './config.yml')
|
@@ -104,6 +118,10 @@ module Skynet
|
|
104
118
|
end
|
105
119
|
|
106
120
|
def load_configuration(file)
|
121
|
+
unless File.exists? file
|
122
|
+
Skynet.logger.fatal %{Configuration file "#{file}" does not exist}
|
123
|
+
exit 1
|
124
|
+
end
|
107
125
|
YAML.load_file(file).with_indifferent_access
|
108
126
|
end
|
109
127
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'active_support/core_ext/string/strip'
|
3
|
+
|
4
|
+
class HookGenerator
|
5
|
+
|
6
|
+
attr_reader :config, :server, :output
|
7
|
+
|
8
|
+
def initialize(config, server, output)
|
9
|
+
@config = config
|
10
|
+
@server = server
|
11
|
+
@output = output
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate
|
15
|
+
File.open(output, 'w') do |file|
|
16
|
+
payload = {
|
17
|
+
repository: { url: config[:url] },
|
18
|
+
before: '$oldrev',
|
19
|
+
after: '$newrev',
|
20
|
+
ref: '$refname'
|
21
|
+
}
|
22
|
+
file.write <<-EOS.strip_heredoc
|
23
|
+
read oldrev newrev refname
|
24
|
+
|
25
|
+
curl -d "payload=#{payload.to_json.gsub('"', '\"')}" #{server}
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,26 +1,18 @@
|
|
1
1
|
# Base configuration for Skynet
|
2
2
|
#
|
3
|
-
# Example for
|
4
|
-
# project_name:
|
5
|
-
# url: https://github.com/owner/project_name
|
6
|
-
# type: jekyll
|
7
|
-
# branch: master
|
8
|
-
# destination: /var/www/project_name
|
9
|
-
#
|
10
|
-
# Example for multiple branch deployment:
|
3
|
+
# Example for public repository deployment:
|
11
4
|
# project_name:
|
12
5
|
# url: https://github.com/owner/project_name
|
13
6
|
# type: jekyll
|
14
7
|
# branches:
|
15
8
|
# master: /var/www/project_name_production
|
16
|
-
# develop: /var/www/project_name_staging
|
17
9
|
#
|
18
10
|
# Example for private repository deployment:
|
19
11
|
# project_name:
|
20
12
|
# url: https://github.com/owner/project_name
|
21
13
|
# type: jekyll
|
22
14
|
# key: /home/username/.ssh/id_rsa
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
15
|
+
# branches:
|
16
|
+
# master: /var/www/project_name
|
17
|
+
# develop: /var/www/project_name_staging
|
26
18
|
|
data/lib/skynet/version.rb
CHANGED
data/lib/skynet.rb
CHANGED
data/skynet.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_runtime_dependency 'thor', '~> 0.16'
|
27
27
|
s.add_runtime_dependency 'activesupport', '~> 3.2'
|
28
28
|
s.add_runtime_dependency 'activemodel', '~> 3.2'
|
29
|
+
s.add_runtime_dependency 'multi_json', '~> 1.0'
|
29
30
|
|
30
31
|
s.add_development_dependency 'rake', '~> 0.9'
|
31
32
|
s.add_development_dependency 'rspec', '~> 2.11'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skynet-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -123,6 +123,22 @@ dependencies:
|
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '3.2'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: multi_json
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '1.0'
|
126
142
|
- !ruby/object:Gem::Dependency
|
127
143
|
name: rake
|
128
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,6 +210,7 @@ files:
|
|
194
210
|
- lib/skynet/builder/jekyll.rb
|
195
211
|
- lib/skynet/builder/static.rb
|
196
212
|
- lib/skynet/cli.rb
|
213
|
+
- lib/skynet/hook_generator.rb
|
197
214
|
- lib/skynet/templates/config.yml
|
198
215
|
- lib/skynet/version.rb
|
199
216
|
- lib/skynet/wizard.rb
|
@@ -217,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
234
|
version: '0'
|
218
235
|
segments:
|
219
236
|
- 0
|
220
|
-
hash: -
|
237
|
+
hash: -3009597360161477294
|
221
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
239
|
none: false
|
223
240
|
requirements:
|