james_bond-mission_build 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73270dcac7f114beb21f46183ea8d9d43708f851
4
+ data.tar.gz: a89f50fe1f3d7828cb53e3d7db55ef73badf93b8
5
+ SHA512:
6
+ metadata.gz: 89ff8716c37a4f1edb7aa69d7941a0117deb0f3af854d169cb94eee6bd0d708b891e0bcf95eee9a70602f83d43e02821f033411b9a540f1b5b88a65e5d56b5f5
7
+ data.tar.gz: 34b51133bc12e610c1cf2ee85cd1a07e7f7b40be12fab8633ebfd1fb401a06fac944e71605c4b0716f9a7bdfebc41b54572688f07043c2d8ffffdd942c9859d1
data/README.md ADDED
@@ -0,0 +1 @@
1
+ ## Build Mission
@@ -0,0 +1,11 @@
1
+ module JamesBond
2
+ class MissionBuild
3
+ class BuildHandler
4
+ class UnableToFindDockerfileError < StandardError
5
+ def initialize(file_path)
6
+ super("The dockerfile \"#{file_path}\" doesn't exists!")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ require "open3"
2
+ require "james_bond/mission_build/build_handler/unable_to_find_dockerfile_error"
3
+
4
+ module JamesBond
5
+ class MissionBuild
6
+ class BuildHandler
7
+ attr_accessor :config
8
+
9
+ def initialize(command, config)
10
+ @command = command
11
+ @config = config
12
+ @docker_config = config.docker_config
13
+ end
14
+
15
+ def run
16
+ image_name = build_image_name
17
+ dockerfile_name = build_dockerfile_name
18
+ raise(UnableToFindDockerfileError, dockerfile_path(dockerfile_name)) \
19
+ if !dockerfile_exists?(dockerfile_name)
20
+
21
+ command = "docker build -t #{image_name} -f #{dockerfile_name} ."
22
+ puts "Building docker image \"#{image_name}\" with #{dockerfile_name}.. "
23
+ Open3.popen3(command) do |stdin, stdout, stderr, thread|
24
+ Thread.new do
25
+ until (line = stdout.gets).nil? do
26
+ puts line
27
+ end
28
+ end
29
+
30
+ thread.join
31
+ end
32
+ puts "Done!"
33
+ end
34
+
35
+ private
36
+
37
+ def build_image_name
38
+ namespace = @docker_config["image"]["namespace"]
39
+ name = @docker_config["image"]["name"]
40
+ tag = build_tag
41
+ "#{namespace}/#{name}:#{tag}"
42
+ end
43
+
44
+ def build_dockerfile_name
45
+ @docker_config["dockerfile"]["pattern"].gsub("$environment", @command.env)
46
+ end
47
+
48
+ def build_tag
49
+ @command.options[:tag] || "devel-#{Time.now.to_i}"
50
+ end
51
+
52
+ def dockerfile_exists?(dockerfile_name)
53
+ File.file?(dockerfile_path(dockerfile_name))
54
+ end
55
+
56
+ def dockerfile_path(dockerfile_name)
57
+ File.join(Dir.pwd, dockerfile_name)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ module JamesBond
2
+ class MissionBuild
3
+ class Config
4
+ class InvalidFileError < StandardError
5
+ def initialize(file_path)
6
+ super("The configuration file for the #{JamesBond::MissionBuild::MISSION_NAME.capitalize} Mission " \
7
+ + "doesn't exist or is unreachable [It should be in #{file_path}]")
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module JamesBond
2
+ class MissionBuild
3
+ class Config
4
+ class NoConfigAvailableError < StandardError
5
+ def initialize(file_path:, config_path:)
6
+ super("The configuration file for the #{JamesBond::MissionBuild::MISSION_NAME.capitalize} Mission [It should be in #{file_path}] " \
7
+ + "doesn't have the required path: '#{config_path}'")
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,64 @@
1
+ require "yaml"
2
+ require "james_bond/mission_build/config/invalid_file_error"
3
+ require "james_bond/mission_build/config/no_config_available_error"
4
+
5
+ module JamesBond
6
+ class MissionBuild
7
+ class Config
8
+ attr_accessor :yaml_path,
9
+ :raw_hash,
10
+ :docker_config
11
+
12
+ def initialize(yaml_path:)
13
+ @yaml_path = yaml_path
14
+ extract_config_from_yaml(@yaml_path)
15
+
16
+ validate_config
17
+ @docker_config = @raw_hash["build"]["docker"]
18
+ end
19
+
20
+ private
21
+
22
+ def extract_config_from_yaml(yaml_path)
23
+ raise(self.class::InvalidFileError, yaml_path) if !file_exists?(yaml_path)
24
+ @raw_hash = YAML.load(File.read(yaml_path)).freeze
25
+ end
26
+
27
+ def file_exists?(path)
28
+ File.file?(path)
29
+ end
30
+
31
+ def validate_config
32
+ build_config = (@raw_hash || {})["build"]
33
+ raise(self.class::NoConfigAvailableError,
34
+ { file_path: yaml_path, config_path: "build" }) if !build_config
35
+
36
+ docker_config = build_config["docker"]
37
+ raise(self.class::NoConfigAvailableError,
38
+ { file_path: yaml_path, config_path: "build.docker" }) if !docker_config
39
+
40
+ docker_image_config = docker_config["image"]
41
+ raise(self.class::NoConfigAvailableError,
42
+ { file_path: yaml_path, config_path: "build.docker.image" }) if !docker_image_config
43
+
44
+ if !docker_image_config["namespace"]
45
+ raise(self.class::NoConfigAvailableError,
46
+ { file_path: yaml_path, config_path: "build.docker.image.namespace" })
47
+ end
48
+ if !docker_image_config["name"]
49
+ raise(self.class::NoConfigAvailableError,
50
+ { file_path: yaml_path, config_path: "build.docker.image.name" })
51
+ end
52
+
53
+ dockerfile_config = docker_config["dockerfile"]
54
+ raise(self.class::NoConfigAvailableError,
55
+ { file_path: yaml_path, config_path: "build.docker.dockerfile" }) if !dockerfile_config
56
+
57
+ if !dockerfile_config["pattern"]
58
+ raise(self.class::NoConfigAvailableError,
59
+ { file_path: yaml_path, config_path: "build.docker.dockerfile.pattern" })
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,34 @@
1
+ require "james_bond/core/mission"
2
+ require "james_bond/mission_build/config"
3
+ require "james_bond/mission_build/build_handler"
4
+
5
+ module JamesBond
6
+ class MissionBuild
7
+ include JamesBond::Core::Mission
8
+
9
+ MISSION_NAME = "build"
10
+ MISSION_MAIN_COMMANDS = ["build"]
11
+ CONFIGURATION_FILE_PATH = File.join(Dir.pwd, "config", "james_bond", "build.yml")
12
+
13
+ def build(config, params)
14
+ config.name = MISSION_NAME
15
+ config.main_commands = MISSION_MAIN_COMMANDS
16
+ arguments_parser do |parser|
17
+ parser.banner = "bond #{MISSION_MAIN_COMMANDS[0]} [options]"
18
+ parser.string "-t", "--tag",
19
+ "Creates a docker image with the specified tag. If omitted, a tag " + \
20
+ "like devel-212121 will be generated automaticaly."
21
+ end
22
+ end
23
+
24
+ def run_build_command(command:, mission_pool:)
25
+ self.class::BuildHandler.new(command, config_file).run
26
+ end
27
+
28
+ private
29
+
30
+ def config_file
31
+ @config_file ||= self.class::Config.new(yaml_path: CONFIGURATION_FILE_PATH)
32
+ end
33
+ end
34
+ end
data/lib/james_bond.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "james_bond/mission_build"
2
+
3
+ module JamesBond
4
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: james_bond-mission_build
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Airton Sobral
8
+ - Guilherme Cavalcanti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: james_bond-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 3.4.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 3.4.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: byebug
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 9.0.5
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 9.0.5
56
+ description: Fully building automation
57
+ email:
58
+ - airtonsobral@gmail.com
59
+ - guiocavalcanti@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.md
64
+ files:
65
+ - README.md
66
+ - lib/james_bond.rb
67
+ - lib/james_bond/mission_build.rb
68
+ - lib/james_bond/mission_build/build_handler.rb
69
+ - lib/james_bond/mission_build/build_handler/unable_to_find_dockerfile_error.rb
70
+ - lib/james_bond/mission_build/config.rb
71
+ - lib/james_bond/mission_build/config/invalid_file_error.rb
72
+ - lib/james_bond/mission_build/config/no_config_available_error.rb
73
+ homepage: http://rubygemgem.org/gems/james_bond-build_mission
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '2.1'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Building a new world should be easy!
97
+ test_files: []