panamax_template_validator 0.0.2
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/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/lib/panamax_template_validator.rb +43 -0
- data/lib/panamax_template_validator/image.rb +98 -0
- data/lib/panamax_template_validator/repo.rb +28 -0
- data/lib/panamax_template_validator/template.rb +38 -0
- data/lib/panamax_template_validator/template_file.rb +43 -0
- data/lib/panamax_template_validator/version.rb +3 -0
- data/lib/refinements/string_colorization.rb +16 -0
- data/panamax_template_validator.gemspec +22 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03c5deb9ecb1660cb51a5277d75ff09f57f06dfb
|
4
|
+
data.tar.gz: 37919827546114e7b6f80091e3a9c9da6a7e43df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 055212f2c01f845e555800388475e0c33dcae747d9462ce715c368918962be4da75f3b29a224d22e2d6e12c822b89897b524404c0b9f24f4e5c644e7104683c5
|
7
|
+
data.tar.gz: a8534cb070f9f42275ea836ee48fff181f7147a931d8ddb7802cfb5d7f1fe9bc707b04450791f78d0b284b8894e7507537d5780745d0fde1e8969ecdc1b9cd9b
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alex
|
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,60 @@
|
|
1
|
+
# Panamax: Docker Management for Humans
|
2
|
+
|
3
|
+
[Panamax](http://panamax.io) is a containerized app creator with an open-source app marketplace hosted in GitHub. Panamax provides a friendly interface for users of Docker, Fleet & CoreOS. With Panamax, you can easily create, share, and deploy any containerized app no matter how complex it might be. Learn more at [Panamax.io](http://panamax.io) or browse the [Panamax Wiki](https://github.com/CenturyLinkLabs/panamax-ui/wiki).
|
4
|
+
|
5
|
+
|
6
|
+
# Panamax Template Validator
|
7
|
+
|
8
|
+
Validator for panamax templates. Runs a quick sanity check against .pmx files.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'panamax_template_validator', git: 'https://github.com/CenturyLinkLabs/panamax-template-validator.git'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install panamax_template_validator
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
##### validate a single file:
|
27
|
+
```
|
28
|
+
PanamaxTemplateValidator.validate('/path/to/your_template.pmx')
|
29
|
+
```
|
30
|
+
|
31
|
+
##### validate a collection of files:
|
32
|
+
```
|
33
|
+
PanamaxTemplateValidator.validate_file_list(['/path/to/your_template.pmx', '/path/to/another_template.pmx'])
|
34
|
+
```
|
35
|
+
|
36
|
+
##### validate all *.pmx files in the current working directory:
|
37
|
+
|
38
|
+
```
|
39
|
+
PanamaxTemplateValidator.validate_repo
|
40
|
+
```
|
41
|
+
|
42
|
+
##### we generally create a default rake task in our template repos that our CI solution will execute, for example:
|
43
|
+
|
44
|
+
```
|
45
|
+
# Rakefile
|
46
|
+
require 'rake'
|
47
|
+
require 'panamax_template_validator'
|
48
|
+
|
49
|
+
task :default do
|
50
|
+
PanamaxTemplateValidator.validate_repo
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it ( https://github.com/[my-github-username]/panamax_template_validator/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'panamax_template_validator/version'
|
2
|
+
require 'panamax_template_validator/repo'
|
3
|
+
require 'panamax_template_validator/template_file'
|
4
|
+
require 'panamax_template_validator/template'
|
5
|
+
require 'panamax_template_validator/image'
|
6
|
+
require 'refinements/string_colorization'
|
7
|
+
|
8
|
+
using StringColorization
|
9
|
+
|
10
|
+
module PanamaxTemplateValidator
|
11
|
+
def self.validate(file)
|
12
|
+
template_file = TemplateFile.new(file)
|
13
|
+
template_file.validate
|
14
|
+
|
15
|
+
if template_file.errors.empty?
|
16
|
+
puts 'VALID!'.green
|
17
|
+
exit 0
|
18
|
+
else
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.validate_file_list(files)
|
24
|
+
errors = []
|
25
|
+
|
26
|
+
files.each do |file|
|
27
|
+
template_file = TemplateFile.new(file)
|
28
|
+
template_file.validate
|
29
|
+
errors += template_file.errors
|
30
|
+
end
|
31
|
+
|
32
|
+
if errors.empty?
|
33
|
+
puts 'THESE FILES ARE ALL VALID!'.green
|
34
|
+
exit 0
|
35
|
+
else
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.validate_repo
|
41
|
+
Repo.new.validate
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module PanamaxTemplateValidator
|
4
|
+
class Image
|
5
|
+
attr_reader :errors
|
6
|
+
|
7
|
+
def initialize(image_attrs, image_names)
|
8
|
+
@image_attrs = image_attrs
|
9
|
+
@image_names = image_names
|
10
|
+
@errors = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate
|
14
|
+
validate_presence_of('name')
|
15
|
+
validate_presence_of('source')
|
16
|
+
validate_source_exists_publicly
|
17
|
+
validate_presence_of_container_ports
|
18
|
+
validate_uniqueness_of_host_ports
|
19
|
+
validate_volumes_have_container_path
|
20
|
+
validate_presence_of_env_var
|
21
|
+
validate_presence_of_link_alias
|
22
|
+
validate_linked_service_exists
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def validate_linked_service_exists
|
28
|
+
Array(@image_attrs['links']).each_with_index do |link, i|
|
29
|
+
unless @image_names.include? link['service']
|
30
|
+
@errors << "#{@image_attrs['name']}'s link ##{i + 1} is linked to a service (#{link['service']}) that does not exist in this template"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_presence_of_link_alias
|
36
|
+
Array(@image_attrs['links']).each_with_index do |link, i|
|
37
|
+
if link['alias'].to_s == ''
|
38
|
+
@errors << "#{@image_attrs['name']}'s link ##{i + 1} does not have an alias"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate_source_exists_publicly
|
44
|
+
source = @image_attrs['source'].split(':')[0]
|
45
|
+
res1 = Net::HTTP.get_response(URI("https://registry.hub.docker.com/u/#{source}/")).code
|
46
|
+
res2 = Net::HTTP.get_response(URI("https://registry.hub.docker.com/_/#{source}/")).code
|
47
|
+
|
48
|
+
unless [res1, res2].include?('200')
|
49
|
+
@errors << "#{@image_attrs['name']}'s source does not exist publicly in the docker index"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate_presence_of_env_var
|
54
|
+
Array(@image_attrs['environment']).each do |env|
|
55
|
+
if env['variable'].to_s == ''
|
56
|
+
@errors << 'each environment entry should have a variable (name)'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def validate_volumes_have_container_path
|
62
|
+
Array(@image_attrs['volumes']).each do |vol|
|
63
|
+
if vol['container_path'].to_s == ''
|
64
|
+
@errors << 'each volume must have a container path'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def validate_presence_of_container_ports
|
70
|
+
Array(@image_attrs['ports']).each do |port|
|
71
|
+
if port['container_port'].to_s == ''
|
72
|
+
@errors << 'each port must have a container port'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def validate_uniqueness_of_host_ports
|
78
|
+
host_ports = Array(@image_attrs['ports']).map { |p| p['host_port'] }.compact
|
79
|
+
|
80
|
+
if host_ports.length != host_ports.uniq.length
|
81
|
+
@errors << 'host ports must be unique'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def validate_presence_of(key)
|
86
|
+
if @image_attrs[key].nil? || @image_attrs[key] == ''
|
87
|
+
@errors << "image: #{@image_attrs['name']}'s #{key} is required"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def validate_length_of(key, inequality, length)
|
92
|
+
return unless @image_attrs[key]
|
93
|
+
unless @image_attrs[key].length.send(inequality, length)
|
94
|
+
@errors << "image: #{@image_attrs['name']}'s #{key} should #{inequality} #{length}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'refinements/string_colorization'
|
2
|
+
|
3
|
+
using StringColorization
|
4
|
+
|
5
|
+
module PanamaxTemplateValidator
|
6
|
+
class Repo
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@errors = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate
|
13
|
+
puts ' --- Validating .pmx files in working directory --- '
|
14
|
+
Dir.glob('*.pmx') do |file|
|
15
|
+
file = TemplateFile.new(file)
|
16
|
+
file.validate
|
17
|
+
@errors += file.errors
|
18
|
+
end
|
19
|
+
|
20
|
+
if @errors.empty?
|
21
|
+
puts 'THIS REPO IS VALID!'.green
|
22
|
+
exit 0
|
23
|
+
else
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PanamaxTemplateValidator
|
2
|
+
class Template
|
3
|
+
attr_reader :errors
|
4
|
+
|
5
|
+
def initialize(template_attrs)
|
6
|
+
@template_attrs = template_attrs
|
7
|
+
@errors = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate
|
11
|
+
validate_presence_of('name')
|
12
|
+
validate_presence_of('description')
|
13
|
+
validate_presence_of('documentation')
|
14
|
+
validate_length_of('documentation', '>', 40)
|
15
|
+
image_names = @template_attrs['images'].map { |image| image['name'] }
|
16
|
+
@template_attrs['images'].each do |image_attrs|
|
17
|
+
image = Image.new(image_attrs, image_names)
|
18
|
+
image.validate
|
19
|
+
@errors += image.errors
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def validate_presence_of(key)
|
26
|
+
if @template_attrs[key].nil? || @template_attrs[key] == ''
|
27
|
+
@errors << "template #{key} is required"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_length_of(key, inequality, length)
|
32
|
+
return unless @template_attrs[key]
|
33
|
+
unless @template_attrs[key].length.send(inequality, length)
|
34
|
+
@errors << "template #{key} should #{inequality} #{length}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'refinements/string_colorization'
|
3
|
+
|
4
|
+
using StringColorization
|
5
|
+
|
6
|
+
module PanamaxTemplateValidator
|
7
|
+
class TemplateFile
|
8
|
+
|
9
|
+
attr_reader :errors
|
10
|
+
|
11
|
+
def initialize(file)
|
12
|
+
@file = file
|
13
|
+
@errors = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate
|
17
|
+
if template = load_template(@file)
|
18
|
+
template_validator = Template.new(template)
|
19
|
+
template_validator.validate
|
20
|
+
errors = template_validator.errors
|
21
|
+
if errors.empty?
|
22
|
+
puts "#{@file} is valid".green
|
23
|
+
else
|
24
|
+
puts "#{@file} has the following errors:".red
|
25
|
+
puts errors.map { |x| x.red }
|
26
|
+
@errors += errors
|
27
|
+
end
|
28
|
+
else
|
29
|
+
no_exist = "#{@file} does not exist"
|
30
|
+
puts no_exist
|
31
|
+
@errors << no_exist
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def load_template(path)
|
38
|
+
YAML.load_file(path)
|
39
|
+
rescue Errno::ENOENT
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'panamax_template_validator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "panamax_template_validator"
|
8
|
+
spec.version = PanamaxTemplateValidator::VERSION
|
9
|
+
spec.authors = ["Centurylink Labs"]
|
10
|
+
spec.email = ["alex.welch@centurylink.com"]
|
11
|
+
spec.summary = %q{Validates panamax template files}
|
12
|
+
spec.homepage = "https://github.com/CenturyLinkLabs/panamax-template-validator"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
# spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: panamax_template_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Centurylink Labs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-20 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: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- alex.welch@centurylink.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- lib/panamax_template_validator.rb
|
52
|
+
- lib/panamax_template_validator/image.rb
|
53
|
+
- lib/panamax_template_validator/repo.rb
|
54
|
+
- lib/panamax_template_validator/template.rb
|
55
|
+
- lib/panamax_template_validator/template_file.rb
|
56
|
+
- lib/panamax_template_validator/version.rb
|
57
|
+
- lib/refinements/string_colorization.rb
|
58
|
+
- panamax_template_validator.gemspec
|
59
|
+
homepage: https://github.com/CenturyLinkLabs/panamax-template-validator
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Validates panamax template files
|
83
|
+
test_files: []
|