viaduct-archfile 1.0.1 → 1.1.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.
- checksums.yaml +4 -4
- data/bin/vdt-archfile-check +30 -21
- data/lib/viaduct/archfile.rb +30 -27
- data/lib/viaduct/archfile_remote_backend.rb +28 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502a658bf4d86831fc2ecc3ef374d49cb3cd9a95
|
4
|
+
data.tar.gz: a79ee80a23d723efc98eb42cfce061b8ef2f2815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f386fb0f5e89237322d10bc53b5ee5669d53b6caef840ff8dc7ef16d17d3c8d4ca6a4d8d075d10a6815d88e2ff42ccf7012e01820b5892ad00305d540da930a
|
7
|
+
data.tar.gz: 8ba2c3c562eaa9b5f9a8c15a73c082f9c549a2fc34e0c66d4c11fb9c849916474f142ff6698004d02b295ffca2e156e30214e3f6c3ce37ff11217cf88040feb8
|
data/bin/vdt-archfile-check
CHANGED
@@ -2,27 +2,36 @@
|
|
2
2
|
$:.unshift(File.expand_path('../../lib', __FILE__))
|
3
3
|
require 'viaduct/archfile'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
begin
|
6
|
+
path = ARGV[0] || './Archfile'
|
7
|
+
if File.exist?(path)
|
8
|
+
archfile = Viaduct::Archfile.new(File.read(path))
|
9
|
+
errors = archfile.validate
|
10
|
+
if errors.empty?
|
11
|
+
puts
|
12
|
+
puts " \e[32mCongratulations. That Archfile looks excellent and should work well!\e[0m"
|
13
|
+
puts
|
14
|
+
puts " Just head over to \e[35mhttps://my.viaduct.io\e[0m to create your new application."
|
15
|
+
puts " Don't forget to add your Archfile to your repository so we can find it."
|
16
|
+
puts
|
17
|
+
else
|
18
|
+
puts
|
19
|
+
puts " \e[31mOh no. It seems there's a problem with your Archfile!\e[0m"
|
20
|
+
puts
|
21
|
+
errors.each do |field, value|
|
22
|
+
puts " * #{field ? field + ' ' : nil}\e[33m#{value}\e[0m"
|
23
|
+
end
|
24
|
+
puts
|
22
25
|
end
|
23
|
-
|
26
|
+
else
|
27
|
+
$stderr.puts "\e[31m!! Couldn't find Viaduct Archfile at #{path}\e[0m"
|
28
|
+
exit 1
|
24
29
|
end
|
25
|
-
|
26
|
-
$stderr.puts "\e[31m!! Couldn't
|
30
|
+
rescue Viaduct::ArchfileRemoteBackend::Error
|
31
|
+
$stderr.puts "\e[31m!! Couldn't download required data from Viaduct. Please try again later.\e[0m"
|
32
|
+
exit 1
|
33
|
+
rescue Psych::SyntaxError => e
|
34
|
+
$stderr.puts "\e[31m!! The Archfile could not be read as it was not valid YAML. Please check and try again.\e[0m"
|
35
|
+
$stderr.puts e.message
|
27
36
|
exit 1
|
28
|
-
end
|
37
|
+
end
|
data/lib/viaduct/archfile.rb
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
require 'safe_yaml/load'
|
2
|
+
require 'viaduct/archfile_remote_backend'
|
2
3
|
|
3
4
|
module Viaduct
|
4
5
|
class Archfile
|
5
6
|
|
6
|
-
APPLICATION_STACKS = ['ruby2.0']
|
7
|
-
SHARED_DATABASE_TYPES = ['mysql']
|
8
|
-
START_DETECTOR_MODULES = ['none', 'log_string', 'timer']
|
9
|
-
COMMAND_EVENTS = ['build', 'start', 'firstrun']
|
10
|
-
|
11
7
|
PATH_REGEX = /\A[a-z0-9\_\-\/\.]+\z/
|
12
8
|
|
13
|
-
|
14
9
|
#
|
15
10
|
# Create a new Archfile object from raw yaml
|
16
11
|
#
|
17
|
-
def initialize(yaml)
|
12
|
+
def initialize(yaml, remote_backend = ArchfileRemoteBackend)
|
18
13
|
@yaml = yaml
|
14
|
+
@remote_backend = remote_backend
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Return the spec document
|
19
|
+
#
|
20
|
+
def spec
|
21
|
+
@spec ||= SafeYAML.load(@yaml)
|
19
22
|
end
|
20
23
|
|
21
24
|
#
|
@@ -40,6 +43,13 @@ module Viaduct
|
|
40
43
|
errors << [key.nil? ? nil : "#{@current_namespace.join('.')}.#{key}", message]
|
41
44
|
end
|
42
45
|
|
46
|
+
#
|
47
|
+
# Return remote properties for this archfile
|
48
|
+
#
|
49
|
+
def remote_properties
|
50
|
+
@remote_properties ||= @remote_backend.properties
|
51
|
+
end
|
52
|
+
|
43
53
|
#
|
44
54
|
# Validate that the object is valid, returning an array of errors
|
45
55
|
# or an empty array if there are no errors.
|
@@ -47,23 +57,15 @@ module Viaduct
|
|
47
57
|
def validate
|
48
58
|
@errors = []
|
49
59
|
|
50
|
-
#
|
51
|
-
# Load the YAML
|
52
|
-
#
|
53
|
-
begin
|
54
|
-
spec = SafeYAML.load(@yaml)
|
55
|
-
rescue Psych::SyntaxError => e
|
56
|
-
errors << [nil, "YAML document could not be read (#{e.message})"]
|
57
|
-
return @errors
|
58
|
-
end
|
59
|
-
|
60
60
|
#
|
61
61
|
# Check settings
|
62
62
|
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
if spec['settings']
|
64
|
+
namespace spec['settings'], 'settings'
|
65
|
+
ensure_boolean('sleep_inactive_web_processes') if spec['settings'].keys.include?('sleep_inactive_web_processes')
|
66
|
+
ensure_boolean('serve_static_files') if spec['settings'].keys.include?('serve_static_files')
|
67
|
+
ensure_matches(/\A[a-z0-9\_\-\/]+\z/, 'document_root') if spec['settings'].keys.include?('document_root')
|
68
|
+
end
|
67
69
|
|
68
70
|
#
|
69
71
|
# Check that we have some processes to begin with
|
@@ -79,13 +81,14 @@ module Viaduct
|
|
79
81
|
spec['processes'].each_with_index do |process, index|
|
80
82
|
namespace process, 'processes', index
|
81
83
|
ensure_string('command')
|
82
|
-
ensure_inclusion(
|
84
|
+
ensure_inclusion(remote_properties['container_memory_allocations'], 'memory')
|
85
|
+
ensure_inclusion(remote_properties['application_stacks'], 'stack')
|
83
86
|
ensure_integer('quantity')
|
84
87
|
ensure_matches(PATH_REGEX, 'name')
|
85
88
|
ensure_integer('kill_after') if process['kill_after']
|
86
89
|
if sm = process['start_monitor']
|
87
90
|
namespace sm, 'processes', index, 'start_monitor'
|
88
|
-
ensure_inclusion(
|
91
|
+
ensure_inclusion(remote_properties['process_start_detectors'], 'module')
|
89
92
|
ensure_integer('timer') if sm['module'] == 'timer'
|
90
93
|
ensure_string('string') if sm['module'] == 'log_string'
|
91
94
|
end
|
@@ -98,7 +101,7 @@ module Viaduct
|
|
98
101
|
if spec['shared_databases'].is_a?(Array)
|
99
102
|
spec['shared_databases'].each_with_index do |db, index|
|
100
103
|
namespace db, 'shared_databases', index
|
101
|
-
ensure_inclusion(
|
104
|
+
ensure_inclusion(remote_properties['shared_database_backends'], 'type')
|
102
105
|
ensure_string('label')
|
103
106
|
end
|
104
107
|
end
|
@@ -129,8 +132,8 @@ module Viaduct
|
|
129
132
|
if spec['commands'].is_a?(Array)
|
130
133
|
spec['commands'].each_with_index do |command, index|
|
131
134
|
namespace command, 'commands', index
|
132
|
-
ensure_inclusion
|
133
|
-
ensure_inclusion
|
135
|
+
ensure_inclusion remote_properties['application_stacks'], 'stack'
|
136
|
+
ensure_inclusion remote_properties['command_events'], 'event'
|
134
137
|
ensure_string 'command'
|
135
138
|
ensure_integer 'success_exit_code'
|
136
139
|
end
|
@@ -153,7 +156,7 @@ module Viaduct
|
|
153
156
|
private
|
154
157
|
|
155
158
|
def value_for(item)
|
156
|
-
@current_hash[item]
|
159
|
+
@current_hash.is_a?(Hash) ? @current_hash[item] : nil
|
157
160
|
end
|
158
161
|
|
159
162
|
def ensure_boolean(*items)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Viaduct
|
5
|
+
class ArchfileRemoteBackend
|
6
|
+
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
def self.properties
|
10
|
+
req = Net::HTTP::Get.new('/archfile/properties')
|
11
|
+
http = Net::HTTP.new(ENV['VDT_HOST'] || 'my.viaduct.io', ENV['VDT_PORT'] || 443)
|
12
|
+
if ENV['VDT_PORT'] == 443
|
13
|
+
res.use_ssl = true
|
14
|
+
res.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
15
|
+
end
|
16
|
+
|
17
|
+
result = http.request(req)
|
18
|
+
if result.is_a?(Net::HTTPSuccess)
|
19
|
+
JSON.parse(result.body)
|
20
|
+
else
|
21
|
+
raise Error, "Unable to download data from Viaduct host. Please try again later."
|
22
|
+
end
|
23
|
+
rescue
|
24
|
+
raise Error, "Unable to download data from Viaduct host. Please try again later."
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viaduct-archfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.1
|
27
41
|
description: A validation tool for checking the validity of a Viaduct Archfile
|
28
42
|
email:
|
29
43
|
- adam@viaduct.io
|
@@ -34,6 +48,7 @@ extra_rdoc_files: []
|
|
34
48
|
files:
|
35
49
|
- bin/vdt-archfile-check
|
36
50
|
- lib/viaduct/archfile.rb
|
51
|
+
- lib/viaduct/archfile_remote_backend.rb
|
37
52
|
- README.md
|
38
53
|
homepage: http://viaduct.io
|
39
54
|
licenses: []
|