construi 0.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.
Files changed (56) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +4 -0
  7. data/Rakefile +7 -0
  8. data/VERSION +1 -0
  9. data/bin/construi +6 -0
  10. data/construi.gemspec +29 -0
  11. data/lib/construi.rb +36 -0
  12. data/lib/construi/config.rb +36 -0
  13. data/lib/construi/container.rb +69 -0
  14. data/lib/construi/image.rb +74 -0
  15. data/lib/construi/version.rb +3 -0
  16. data/spec/sanity_spec.rb +7 -0
  17. data/spec/spec_helper.rb +78 -0
  18. data/vendor/bundle/ruby/1.9.1/build_info/codeclimate-test-reporter-0.4.6.info +1 -0
  19. data/vendor/bundle/ruby/1.9.1/cache/codeclimate-test-reporter-0.4.6.gem +0 -0
  20. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/.gitignore +18 -0
  21. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/.rspec +2 -0
  22. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/.travis.yml +8 -0
  23. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/Gemfile +12 -0
  24. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/LICENSE.txt +40 -0
  25. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/README.md +131 -0
  26. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/Rakefile +6 -0
  27. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/bin/cc-tddium-post-worker +24 -0
  28. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/codeclimate-test-reporter.gemspec +29 -0
  29. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/config/cacert.pem +3895 -0
  30. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter.rb +56 -0
  31. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb +39 -0
  32. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/ci.rb +89 -0
  33. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/client.rb +99 -0
  34. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/configuration.rb +57 -0
  35. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/exception_message.rb +74 -0
  36. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/formatter.rb +114 -0
  37. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/git.rb +68 -0
  38. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/payload_validator.rb +59 -0
  39. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/version.rb +5 -0
  40. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/codeclimate-test-reporter.rb +8 -0
  41. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/fixtures/encoding_test.rb +6 -0
  42. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/fixtures/encoding_test_iso.rb +6 -0
  43. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/calculate_blob_spec.rb +27 -0
  44. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/ci_spec.rb +26 -0
  45. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/client_spec.rb +24 -0
  46. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/configuration_spec.rb +75 -0
  47. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/formatter_spec.rb +141 -0
  48. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/git_spec.rb +39 -0
  49. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/payload_validator_spec.rb +89 -0
  50. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/lib/test_reporter_spec.rb +36 -0
  51. data/vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/spec/spec_helper.rb +46 -0
  52. data/vendor/bundle/ruby/1.9.1/gems/json-1.8.2/ext/json/Makefile +174 -0
  53. data/vendor/bundle/ruby/1.9.1/gems/json-1.8.2/ext/json/ext/generator/Makefile +221 -0
  54. data/vendor/bundle/ruby/1.9.1/gems/json-1.8.2/ext/json/ext/parser/Makefile +221 -0
  55. data/vendor/bundle/ruby/1.9.1/specifications/codeclimate-test-reporter-0.4.6.gemspec +50 -0
  56. metadata +199 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTI0OGIxMmQ1YWM2YTk4NDFlMDBjYWY2MDRlNDlkYzIyYjZjZmZjYg==
5
+ data.tar.gz: !binary |-
6
+ ZmMxMDE3YmI1N2M4Mzc1YjAzODIwZTJlYzUwNzZlZjgyNzNlOGY5Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjNkMjM3Y2QxNDM5YmI0N2U1ZDY5NGE0NzA2YzNlODQ1Y2JhYWExNGYwZDZm
10
+ MzJlZTMyMDdlOGU1YmYxMDhlODdiZTgyODg3YzEwNGVjNWJlYjM1NjljMDg4
11
+ NmIxMmU3MGM5YjUzZmYzMWI5NWU0MTBlN2Y5NzVlMGEyNTQ3NjE=
12
+ data.tar.gz: !binary |-
13
+ NmM4Y2FjNDAzZGI2ODRlMjUxMzQ2ZWIyZDU2MDI5YTRjNGE0NTMwMmU3OGVl
14
+ NzFlYTIwYWZmM2EwMzZmZGJlNWJiZDg3YTE1MTc1MDE5N2U5NTQyN2RkMDM1
15
+ YmFmMTM2MGM2OGU4NTRhMjUwNDYwNDMxNjY4Y2JlMjU5MzZiMjA=
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in construi.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 lestephen
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,4 @@
1
+ # Construi
2
+
3
+ [![Code Climate](https://codeclimate.com/github/lstephen/construi/badges/gpa.svg)](https://codeclimate.com/github/lstephen/construi) [![Test Coverage](https://codeclimate.com/github/lstephen/construi/badges/coverage.svg)](https://codeclimate.com/github/lstephen/construi) [![Coveralls](https://img.shields.io/coveralls/lstephen/construi/develop.svg?style=plastic)](https://coveralls.io/r/lstephen/construi)
4
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/construi ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'construi'
4
+
5
+ Construi.run ARGV
6
+
data/construi.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'construi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "construi"
8
+ spec.version = Construi::VERSION
9
+ spec.authors = ["lstephen"]
10
+ spec.email = ["levi.stephen@gmail.com"]
11
+ spec.summary = %q{Build tool using Docker to specify build environment}
12
+ spec.description = %q{Build tool using Docker to specify build environment}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'docker-api'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'codeclimate-test-reporter'
25
+ spec.add_development_dependency 'coveralls'
26
+ spec.add_development_dependency 'gem-release'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec'
29
+ end
data/lib/construi.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'construi/config'
2
+ require 'construi/container'
3
+ require 'construi/image'
4
+
5
+ require 'docker'
6
+ require 'yaml'
7
+
8
+ module Construi
9
+
10
+ class Runner
11
+ def initialize(config)
12
+ @config = config
13
+ end
14
+
15
+ def run(targets)
16
+ Docker.validate_version!
17
+ Docker.options[:read_timeout] = 60
18
+ Docker.options[:chunk_size] = 8
19
+
20
+ initial_image = Image.create(@config.image)
21
+
22
+ commands = targets.map { |t| @config.target(t).commands }.flatten
23
+
24
+ final_image = commands.reduce(IntermediateImage.seed(initial_image)) do |image, command|
25
+ image.run(command)
26
+ end
27
+
28
+ final_image.delete
29
+ end
30
+ end
31
+
32
+ def self.run(targets)
33
+ Runner.new(Config.load('construi.yml')).run(targets)
34
+ end
35
+
36
+ end
@@ -0,0 +1,36 @@
1
+
2
+ module Construi
3
+
4
+ class Config
5
+ private_class_method :new
6
+
7
+ attr_reader :yaml
8
+
9
+ def initialize(yaml)
10
+ @yaml = yaml
11
+ end
12
+
13
+ def self.load(path)
14
+ new(YAML.load_file(path))
15
+ end
16
+
17
+ def image
18
+ @yaml['image']
19
+ end
20
+
21
+ def target(target)
22
+ Target.new(@yaml['targets'][target])
23
+ end
24
+ end
25
+
26
+ class Target
27
+ def initialize(yaml)
28
+ @yaml = yaml
29
+ end
30
+
31
+ def commands
32
+ @yaml
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,69 @@
1
+ require 'construi/image'
2
+
3
+ module Construi
4
+
5
+ class Container
6
+ private_class_method :new
7
+
8
+ def initialize(container)
9
+ @container = container
10
+ end
11
+
12
+ def delete
13
+ @container.delete
14
+ end
15
+
16
+ def attach_stdout
17
+ @container
18
+ .tap(&:start)
19
+ .attach(:stream => true, :logs => true) { |s, c| puts c; $stdout.flush }
20
+ end
21
+
22
+ def commit
23
+ Image.wrap(@container.commit)
24
+ end
25
+
26
+ def run
27
+ attach_stdout
28
+
29
+ @container.start
30
+ status_code = @container.wait['StatusCode']
31
+
32
+ raise RunError 'Cmd returned status code: #{status_code}' unless status_code == 0
33
+
34
+ commit
35
+ end
36
+
37
+ def self.create(image, cmd)
38
+ wrap Docker::Container.create(
39
+ 'Cmd' => cmd.split,
40
+ 'Image' => image.id,
41
+ 'Tty' => false,
42
+ 'WorkingDir' => '/var/workspace',
43
+ 'HostConfig' => { 'Binds' => ["#{Dir.pwd}:/var/workspace"] })
44
+ end
45
+
46
+ def self.wrap(container)
47
+ new container
48
+ end
49
+
50
+ def self.use(image, cmd)
51
+ container = create(image, cmd)
52
+ yield container
53
+ ensure
54
+ container.delete unless container.nil?
55
+ end
56
+
57
+ def self.run(image, cmd)
58
+ use(image, cmd, &:run)
59
+ end
60
+
61
+ end
62
+
63
+ class ContainerError < StandardError
64
+ end
65
+
66
+ class RunError < ContainerError
67
+ end
68
+
69
+ end
@@ -0,0 +1,74 @@
1
+ require 'construi/container'
2
+
3
+ module Construi
4
+
5
+ class Image
6
+ private_class_method :new
7
+
8
+ def initialize(image)
9
+ @image = image.refresh!
10
+ end
11
+
12
+ def id
13
+ @image.id
14
+ end
15
+
16
+ def delete
17
+ @image.delete
18
+ end
19
+
20
+ def tagged?
21
+ @image.info['RepoTags'] != '<none>:<none>'
22
+ end
23
+
24
+ def run(cmd)
25
+ Container.run(self, cmd)
26
+ end
27
+
28
+ def self.create(image)
29
+ wrap Docker::Image.create('fromImage' => image)
30
+ end
31
+
32
+ def self.wrap(image)
33
+ new image
34
+ end
35
+
36
+ def self.use(image)
37
+ begin
38
+ i = create(image)
39
+ yield i
40
+ ensure
41
+ i.delete unless i.tagged?
42
+ end
43
+ end
44
+ end
45
+
46
+ class IntermediateImage
47
+ private_class_method :new
48
+
49
+ def initialize(image)
50
+ @image = image
51
+ end
52
+
53
+ def run(cmd)
54
+ map { |i| i.run(cmd) }
55
+ end
56
+
57
+ def map
58
+ update(yield @image)
59
+ end
60
+
61
+ def update(image)
62
+ @image.delete unless @image.tagged?
63
+ @image = image
64
+ end
65
+
66
+ def delete
67
+ @image.delete unless @image.tagged?
68
+ end
69
+
70
+ def self.seed(image)
71
+ new image
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Construi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Sanity' do
4
+ it { expect(true).to be_truthy }
5
+ end
6
+
7
+
@@ -0,0 +1,78 @@
1
+
2
+ require 'codeclimate-test-reporter'
3
+ require 'coveralls'
4
+
5
+ Coveralls.wear!
6
+
7
+ CodeClimate::TestReporter.start
8
+
9
+ RSpec.configure do |config|
10
+
11
+ # rspec-expectations config goes here. You can use an alternate
12
+ # assertion/expectation library such as wrong or the stdlib/minitest
13
+ # assertions if you prefer.
14
+ config.expect_with :rspec do |expectations|
15
+ # This option will default to `true` in RSpec 4. It makes the `description`
16
+ # and `failure_message` of custom matchers include text for helper methods
17
+ # defined using `chain`, e.g.:
18
+ # be_bigger_than(2).and_smaller_than(4).description
19
+ # # => "be bigger than 2 and smaller than 4"
20
+ # ...rather than:
21
+ # # => "be bigger than 2"
22
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
+ end
24
+
25
+ # rspec-mocks config goes here. You can use an alternate test double
26
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
27
+ config.mock_with :rspec do |mocks|
28
+ # Prevents you from mocking or stubbing a method that does not exist on
29
+ # a real object. This is generally recommended, and will default to
30
+ # `true` in RSpec 4.
31
+ mocks.verify_partial_doubles = true
32
+ end
33
+
34
+ # These two settings work together to allow you to limit a spec run
35
+ # to individual examples or groups you care about by tagging them with
36
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
37
+ # get run.
38
+ config.filter_run :focus
39
+ config.run_all_when_everything_filtered = true
40
+
41
+ # Limits the available syntax to the non-monkey patched syntax that is
42
+ # recommended. For more details, see:
43
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
44
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
45
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
46
+ config.disable_monkey_patching!
47
+
48
+ # This setting enables warnings. It's recommended, but in some cases may
49
+ # be too noisy due to issues in dependencies.
50
+ config.warnings = true
51
+
52
+ # Many RSpec users commonly either run the entire suite or an individual
53
+ # file, and it's useful to allow more verbose output when running an
54
+ # individual spec file.
55
+ if config.files_to_run.one?
56
+ # Use the documentation formatter for detailed output,
57
+ # unless a formatter has already been configured
58
+ # (e.g. via a command-line flag).
59
+ config.default_formatter = 'doc'
60
+ end
61
+
62
+ # Print the 10 slowest examples and example groups at the
63
+ # end of the spec run, to help surface which specs are running
64
+ # particularly slow.
65
+ config.profile_examples = 10
66
+
67
+ # Run specs in random order to surface order dependencies. If you find an
68
+ # order dependency and want to debug it, you can fix the order by providing
69
+ # the seed, which is printed after each run.
70
+ # --seed 1234
71
+ config.order = :random
72
+
73
+ # Seed global randomization in this process using the `--seed` CLI option.
74
+ # Setting this allows you to use `--seed` to deterministically reproduce
75
+ # test failures related to randomization by passing the same `--seed` value
76
+ # as the one that triggered the failure.
77
+ Kernel.srand config.seed
78
+ end