percheron 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 275f1a0fa8f2b50676a512e6f06a1ee4831766a5
4
- data.tar.gz: 99c850dc1bc237a36496a0abc97544c643fc1bc3
3
+ metadata.gz: 15de7f98c12439599c7f39ba23c9667d3114d493
4
+ data.tar.gz: e5efd6cf80b855d2bc6a477db9406165708f0b9d
5
5
  SHA512:
6
- metadata.gz: 24428f1616dfacdf8f6d593634b262ba32e1a57502970fc45722985f94154bc6f89f7426ff15fdb2cf45300b60bb55469c0830900f78d8643b99a6b6806a6dfb
7
- data.tar.gz: 6be1aaa7380e32af478b7f08414edea06a17165d977d6e983ce69eda7cffc724356583461e62f01c5f42aea82902e5776564802a8a711c03a3a74089523df3b9
6
+ metadata.gz: ad718e1b22ec751f618b29d0bd37e716fea413291152738d692746dbd9fec849190f78e324de88608271c138455c682d02ef15b3cdcbb23b70593b9b7cc6878b
7
+ data.tar.gz: 77b283bb036e996e2847ebfb5fe6c77ce11351fd6061ae1352e319d9fd464cef506dbfd30c8cccdbe395bfc44d199d2ed007be08f9dd9402355704ef71ba7a51
data/.travis.yml CHANGED
@@ -6,6 +6,5 @@ branches:
6
6
  - master
7
7
  - wip
8
8
  script:
9
- - bundle exec cane
10
- - bundle exec rubocop
9
+ - bundle exec rake test:style
11
10
  - bundle exec rake spec:unit
data/README.md CHANGED
@@ -8,6 +8,21 @@
8
8
 
9
9
  Organise your Docker containers with muscle and intelligence.
10
10
 
11
+ ## Features
12
+
13
+ * Single, easy to write `.percheron.yml` controls everything
14
+ * Supports building, creating and starting of containers and their dependancies
15
+ * Supports building using a Dockerfile or pulling a Docker image from Docker Hub
16
+ * Build 'base' images as a dependancy and then build from there
17
+ * Support for pre-build and post-start scripts when generating images and starting containers
18
+ * Version control of building images and containers
19
+ * Written in Ruby :)
20
+
21
+ ## Supported platforms
22
+
23
+ * Linux
24
+ * MacOS 10.9+
25
+
11
26
  ## Installation
12
27
 
13
28
  Add this line to your application's Gemfile:
@@ -31,7 +46,8 @@ $ gem install percheron
31
46
  ## Requirements
32
47
 
33
48
  * Ruby 2.x
34
- * Docker 1.6.x
49
+ * [Docker 1.6.x](https://docs.docker.com/installation/) / [Boot2Docker v1.6.x+](https://docs.docker.com/installation)
50
+ * [Docker client](https://docs.docker.com/installation) (nice to have)
35
51
 
36
52
  ## Usage
37
53
 
@@ -39,29 +55,29 @@ TODO
39
55
 
40
56
  ## Examples
41
57
 
42
- * Rails - https://github.com/ashmckenzie/percheron-rails#quickstart
43
- * Torrent - https://github.com/ashmckenzie/percheron-torrent#quickstart
44
- * SaltStack - https://github.com/ashmckenzie/percheron-saltstack#quickstart
58
+ * [Rails](https://github.com/ashmckenzie/percheron-rails#quickstart) - Rails 4.2, PostgreSQL, redis, HAProxy and postfix
59
+ * [Torrent](https://github.com/ashmckenzie/percheron-torrent#quickstart) - Tracker (chihaya), seeder (aria2) and three peers (aria2)
60
+ * [SaltStack](https://github.com/ashmckenzie/percheron-saltstack#quickstart) - SaltStack v2015.2.0rc2 with master and minion
45
61
 
46
62
  ## Testing
47
63
 
48
64
  All (cane, RuboCop, unit and integration):
49
65
 
50
66
  ```shell
51
- bundle exec test
67
+ bundle exec rake test
52
68
  ```
53
69
 
54
70
  Style (cane and RuboCop):
55
71
 
56
72
  ```shell
57
- bundle exec test:style
73
+ bundle exec rake test:style
58
74
  ```
59
75
 
60
-
61
76
  ## Contributing
62
77
 
63
78
  1. Fork it ( https://github.com/ashmckenzie/percheron/fork )
64
79
  2. Create your feature branch (`git checkout -b my-new-feature`)
65
80
  3. Commit your changes (`git commit -am 'Add some feature'`)
66
- 4. Push to the branch (`git push origin my-new-feature`)
67
- 5. Create a new Pull Request
81
+ 4. Run `bundle exec rake test`
82
+ 5. Push to the branch (`git push origin my-new-feature`)
83
+ 6. Create a new Pull Request
@@ -4,6 +4,7 @@ module Percheron
4
4
  include Base
5
5
 
6
6
  DEFAULT_SHELL = '/bin/sh'
7
+ DOCKER_CLIENT = 'docker'
7
8
 
8
9
  def initialize(container, shell: DEFAULT_SHELL)
9
10
  @container = container
@@ -11,7 +12,8 @@ module Percheron
11
12
  end
12
13
 
13
14
  def execute!
14
- $logger.debug "Executing a bash shell on '#{container.name}' container"
15
+ Validators::DockerClient.new.validate_docker_client_available!
16
+ $logger.debug "Executing #{shell} on '#{container.name}' container"
15
17
  exec!
16
18
  end
17
19
 
@@ -20,7 +22,7 @@ module Percheron
20
22
  attr_reader :container, :shell
21
23
 
22
24
  def exec!
23
- system('docker exec -ti %s %s' % [ container.full_name, shell ])
25
+ system('%s exec -ti %s %s' % [ DOCKER_CLIENT, container.full_name, shell ])
24
26
  end
25
27
  end
26
28
  end
@@ -10,6 +10,8 @@ module Percheron
10
10
  def execute
11
11
  super
12
12
  stack.shell!(container_name, shell: shell)
13
+ rescue Errors::DockerClientInvalid => e
14
+ signal_usage_error(e.message)
13
15
  end
14
16
  end
15
17
  end
@@ -4,5 +4,6 @@ module Percheron
4
4
  class StackInvalid < StandardError; end
5
5
  class ContainerInvalid < StandardError; end
6
6
  class ContainerDoesNotExist < StandardError; end
7
+ class DockerClientInvalid < StandardError; end
7
8
  end
8
9
  end
@@ -8,18 +8,17 @@ module Percheron
8
8
 
9
9
  def valid?
10
10
  message = rules.return { |rule| send(rule) }
11
-
12
- if message
13
- fail Errors::ConfigFileInvalid, message
14
- else
15
- true
16
- end
11
+ message ? fail(Errors::ConfigFileInvalid, formatted_message(message)) : true
17
12
  end
18
13
 
19
14
  private
20
15
 
21
16
  attr_reader :config_file
22
17
 
18
+ def formatted_message(message)
19
+ "Config is invalid: #{message}"
20
+ end
21
+
23
22
  def rules
24
23
  [
25
24
  :validate_config_file_defined,
@@ -34,24 +33,21 @@ module Percheron
34
33
  end
35
34
 
36
35
  def validate_config_file_defined
37
- 'Config file is not defined' if config_file.nil?
36
+ 'Is not defined' if config_file.nil?
38
37
  end
39
38
 
40
39
  def validate_config_file_existence
41
- "#{base_message} does not exist" unless config_file.exist?
40
+ 'Does not exist' unless config_file.exist?
42
41
  end
43
42
 
44
43
  def validate_config_file_not_empty
45
- "#{base_message} is empty" if config_file_contents.empty?
44
+ 'Is empty' if config_file_contents.empty?
46
45
  end
47
46
 
48
47
  def validate_config_file_contents
49
- "#{base_message} is invalid" unless config_file_contents.docker
48
+ 'Is invalid' unless config_file_contents.docker
50
49
  end
51
50
 
52
- def base_message
53
- "Config file '#{config_file}'"
54
- end
55
51
  end
56
52
  end
57
53
  end
@@ -8,12 +8,7 @@ module Percheron
8
8
 
9
9
  def valid?
10
10
  message = rules.return { |rule| send(rule) }
11
-
12
- if message
13
- fail Errors::ContainerInvalid, formatted_message(message)
14
- else
15
- true
16
- end
11
+ message ? fail(Errors::ContainerInvalid, formatted_message(message)) : true
17
12
  end
18
13
 
19
14
  private
@@ -41,25 +36,25 @@ module Percheron
41
36
  # rubocop:disable Style/GuardClause
42
37
  def validate_name
43
38
  if container.name.nil? || !container.name.to_s.match(/[\w]{3,}/)
44
- 'Container name is invalid'
39
+ 'Name is invalid'
45
40
  end
46
41
  end
47
42
 
48
43
  def validate_dockerfile_and_image_name
49
44
  if container.dockerfile.nil? && container.docker_image.nil?
50
- 'Container Dockerfile OR image name not provided'
45
+ 'Dockerfile OR image name not provided'
51
46
  end
52
47
  end
53
48
 
54
49
  def validate_dockerfile
55
50
  if !container.dockerfile.nil? && !File.exist?(container.dockerfile)
56
- 'Container Dockerfile is invalid'
51
+ 'Dockerfile is invalid'
57
52
  end
58
53
  end
59
54
 
60
55
  def validate_image
61
56
  if !container.docker_image.nil? && !container.docker_image.match(/^.+:.+$/)
62
- 'Container Docker image is invalid'
57
+ 'Docker image is invalid'
63
58
  end
64
59
  end
65
60
  # rubocop:enable Style/GuardClause
@@ -67,7 +62,7 @@ module Percheron
67
62
  def validate_version
68
63
  container.version ? nil : fail(ArgumentError)
69
64
  rescue ArgumentError
70
- 'Container version is invalid'
65
+ 'Version is invalid'
71
66
  end
72
67
 
73
68
  end
@@ -0,0 +1,56 @@
1
+ module Percheron
2
+ module Validators
3
+ class DockerClient
4
+
5
+ def valid?
6
+ message = rules.return { |rule| send(rule) }
7
+ message ? fail(Errors::DockerClientInvalid, formatted_message(message)) : true
8
+ end
9
+
10
+ private
11
+
12
+ def formatted_message(message)
13
+ "Docker client is invalid: #{message}"
14
+ end
15
+
16
+ def rules
17
+ [
18
+ :validate_existence,
19
+ :validate_version
20
+ ]
21
+ end
22
+
23
+ def validate_existence
24
+ return nil if docker_client_exists?
25
+ 'Is not in your PATH'
26
+ end
27
+
28
+ def validate_version
29
+ return nil if docker_client_exists? &&
30
+ Semantic::Version.new(current_version) >= minimum_version
31
+ "Version is insufficient, need #{minimum_version}"
32
+ end
33
+
34
+ def paths
35
+ ENV['PATH'].split(File::PATH_SEPARATOR)
36
+ end
37
+
38
+ def docker_client_exists?
39
+ paths.each do |path|
40
+ exe = File.join(path, Actions::Shell::DOCKER_CLIENT)
41
+ return true if File.executable?(exe) && !File.directory?(exe)
42
+ end
43
+ false
44
+ end
45
+
46
+ def minimum_version
47
+ @minimum_version ||= Semantic::Version.new('1.6.0')
48
+ end
49
+
50
+ def current_version
51
+ `#{Actions::Shell::DOCKER_CLIENT} --version`.chomp.match(/version (.+),/)[1]
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -8,24 +8,24 @@ module Percheron
8
8
 
9
9
  def valid?
10
10
  message = rules.return { |rule| send(rule) }
11
-
12
- if message
13
- fail Errors::StackInvalid, message
14
- else
15
- true
16
- end
11
+ message ? fail(Errors::StackInvalid, formatted_message(message)) : true
17
12
  end
18
13
 
19
14
  private
20
15
 
21
16
  attr_reader :stack
22
17
 
18
+ def formatted_message(message)
19
+ "Stack is invalid: #{message}"
20
+ end
21
+
23
22
  def rules
24
23
  [ :validate_name ]
25
24
  end
26
25
 
27
26
  def validate_name
28
- 'Stack name is invalid' if stack.name.nil? || !stack.name.to_s.match(/[\w\d]{3,}/)
27
+ return nil if !stack.name.nil? && stack.name.to_s.match(/\w{3,}/)
28
+ 'Name is invalid'
29
29
  end
30
30
 
31
31
  end
@@ -1,6 +1,7 @@
1
1
  require 'percheron/validators/config'
2
2
  require 'percheron/validators/stack'
3
3
  require 'percheron/validators/container'
4
+ require 'percheron/validators/docker_client'
4
5
 
5
6
  module Percheron
6
7
  module Validators
@@ -1,3 +1,3 @@
1
1
  module Percheron
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percheron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash McKenzie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-23 00:00:00.000000000 Z
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -314,6 +314,7 @@ files:
314
314
  - lib/percheron/validators.rb
315
315
  - lib/percheron/validators/config.rb
316
316
  - lib/percheron/validators/container.rb
317
+ - lib/percheron/validators/docker_client.rb
317
318
  - lib/percheron/validators/stack.rb
318
319
  - lib/percheron/version.rb
319
320
  - percheron.gemspec