minke 1.14.1 → 1.14.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: 97c33c7f7fd702358fb6091c3520b45fc1f7a17c
4
- data.tar.gz: 2e17caa1c46785d9ca1e00b0e70979506fb00388
3
+ metadata.gz: 3796c60b0992fa90f5b2408e24de7b731ea396cc
4
+ data.tar.gz: 395db562982e41ca0351c498458808248c91b149
5
5
  SHA512:
6
- metadata.gz: 68a625d619a2b710d61023d60b966dbf30fe3056b4aa55c768439a2d7c2205db72a873493307396e57f84d79c7c50d68b3396ae2ffbb91daa67a93ed284b04a0
7
- data.tar.gz: 5f87d6bedc1685a06dd7a259bbf5382a9a90028be55af1f9f64ea76964f6ddb405d18c9a4e954a734cfba3c3bfb2867e4864acde37cc86043b5b42322288c129
6
+ metadata.gz: ef53172cc692ab629f97a81fd97115fca54ba817ccdee931e970945c64bd708024d953f2ade1ed2e589ae6b3f886dcd330eb9505c019753f6f3ace0d7d261526
7
+ data.tar.gz: 5a68dee19e8eea1bec8881722f1e832e19a492e355f2e4613bea0405ad81e25f41f40fffe4ae650e8e4945c70373e826ebae3fde3fb5935a76217ad10b9bdf1c
data/.travis.yml CHANGED
@@ -30,7 +30,7 @@ after_deploy:
30
30
  docker build -t nicholasjackson/minke --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --build-arg VCS_REF=`git rev-parse --short HEAD` .;
31
31
  docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
32
32
  docker push nicholasjackson/minke:latest;
33
- docker tag nicholasjackson/minke nicholasjackson/minke:1.14.1;
34
- docker push nicholasjackson/minke:1.14.1;
33
+ docker tag nicholasjackson/minke nicholasjackson/minke:1.14.2;
34
+ docker push nicholasjackson/minke:1.14.2;
35
35
  curl https://hooks.microbadger.com/images/nicholasjackson/minke/tkpohfdrYPE0B0TL5NzLcOap4k0=;
36
36
  fi
data/docker/Gemfile CHANGED
@@ -3,8 +3,8 @@ source 'https://rubygems.org'
3
3
  gem "rake"
4
4
  gem "cucumber"
5
5
 
6
- gem 'minke', "= 1.14.1"
6
+ gem 'minke', "= 1.14.2"
7
7
  gem 'minke-generator-swift', "= 0.4"
8
8
  gem 'minke-generator-netmvc'
9
- gem 'minke-generator-go', "= 0.8.6"
9
+ gem 'minke-generator-go', "= 0.9.0"
10
10
  gem 'minke-generator-spring'
data/lib/minke/command.rb CHANGED
@@ -18,12 +18,6 @@ module Minke
18
18
  logger = Minke::Logging.create_logger(self.verbose)
19
19
  shell = Minke::Helpers::Shell.new(logger)
20
20
 
21
- # variables = Minke::Generators::ConfigVariables.new.tap do |v|
22
- # v.application_name = @config.application_name
23
- # v.namespace = @config.namespace
24
- # v.src_root = File.expand_path('../')
25
- # end
26
-
27
21
  task_runner = Minke::Tasks::TaskRunner.new ({
28
22
  :ruby_helper => Minke::Helpers::Ruby.new,
29
23
  :copy_helper => Minke::Helpers::Copy.new,
@@ -51,7 +45,7 @@ module Minke
51
45
  return {
52
46
  :config => @config,
53
47
  :task_name => task,
54
- :docker_runner => Minke::Docker::DockerRunner.new(logger, network_name),
48
+ :docker_runner => Minke::Docker::DockerRunner.new(logger, network_name, project_name),
55
49
  :task_runner => task_runner,
56
50
  :shell_helper => shell,
57
51
  :logger_helper => logger,
@@ -110,7 +104,7 @@ module Minke
110
104
  end
111
105
 
112
106
  def build_image
113
- if config.test != nil
107
+ if config.build != nil
114
108
  test
115
109
  tasks = create_tasks :build
116
110
  tasks[:build_image].run
@@ -249,10 +249,10 @@ module Minke
249
249
  attr_accessor :docker
250
250
 
251
251
  ##
252
- # container_addresses contains an array of Minke::Config::ContainerAddress which holds the details
252
+ # ports contains an array of Minke::Config::ContainerAddress which holds the details
253
253
  # for the address the public and private ports of any containers which will be started by this
254
254
  # task.
255
- attr_accessor :container_addresses
255
+ attr_accessor :ports
256
256
  end
257
257
 
258
258
  ##
@@ -335,5 +335,6 @@ module Minke
335
335
  # - private used for linked containers
336
336
  attr_accessor :type
337
337
  end
338
+
338
339
  end
339
340
  end
@@ -63,6 +63,7 @@ module Minke
63
63
  t.docker = read_docker_section section['docker'] unless section['docker'] == nil
64
64
  t.pre = read_pre_post_section section['pre'] unless section['pre'] == nil
65
65
  t.post = read_pre_post_section section['post'] unless section['post'] == nil
66
+ t.ports = section['ports'] unless section['ports'] == nil
66
67
  end
67
68
  end
68
69
 
@@ -69,6 +69,10 @@ module Minke
69
69
  { 'networks' => {'default' => { 'external' => { 'name' => @docker_network } } } }
70
70
  end
71
71
 
72
+ def services
73
+ create_compose['services']
74
+ end
75
+
72
76
  def create_compose
73
77
  existing = YAML.load(File.read(@compose_file))
74
78
  services = {}
@@ -1,9 +1,10 @@
1
1
  module Minke
2
2
  module Docker
3
3
  class DockerRunner
4
- def initialize logger, network = nil
4
+ def initialize logger, network = nil, project = nil
5
5
  @network = network ||= 'bridge'
6
6
  @logger = logger
7
+ @project = project
7
8
  end
8
9
 
9
10
  ##
@@ -74,8 +75,8 @@ module Minke
74
75
  'Cmd' => args[:command],
75
76
  "Binds" => args[:volumes],
76
77
  "Env" => args[:environment],
78
+ 'NetworkMode' => @network,
77
79
  'WorkingDir' => args[:working_directory],
78
- 'NetworkMode' => @network,
79
80
  'name' => args[:name],
80
81
  'PublishAllPorts' => true
81
82
  )
@@ -106,42 +107,57 @@ module Minke
106
107
  return container, success
107
108
  end
108
109
 
109
- #
110
- # create_and_run_blocking_container starts a conatainer of the given image name and executes a command, this method blocks until the container exits
110
+ ##
111
+ # create_and_run_blocking_container starts a conatainer of the given image name and executes a command,
112
+ # this method blocks until the container exits
111
113
  #
112
114
  # Returns:
113
115
  # - Docker::Container
114
116
  # - sucess (true if command succeded without error)
115
117
  def create_and_run_blocking_container args
118
+ host_config = get_port_bindings args
119
+ host_config['NetworkMode'] = @network
120
+ host_config['Binds'] = args[:volumes]
121
+
122
+ if args[:links] != nil
123
+ network = {'EndpointsConfig' => {@network =>
124
+ {'Links' => args[:links].map {|l| "#{@project}_#{l}_1:#{l}"}}
125
+ }}
126
+ end
127
+
128
+ exposed_ports = get_exposed_ports args
129
+
116
130
  # update the timeout for the Excon Http Client
117
131
  # set the chunk size to enable streaming of log files
118
- ::Docker.options = {:chunk_size => 1, :read_timeout => 3600}
132
+ #::Docker.options = {:chunk_size => 1, :read_timeout => 3600}
119
133
  container = ::Docker::Container.create(
120
- 'Image' => args[:image],
121
- 'Cmd' => args[:command],
122
- "Binds" => args[:volumes],
123
- "Env" => args[:environment],
124
- 'WorkingDir' => args[:working_directory],
125
- 'name' => args[:name],
126
- 'NetworkMode' => @network,
127
- "OpenStdin" => true,
128
- "StdinOnce" => true,
129
- "Tty" => true,
130
- 'PublishAllPorts' => true
134
+ 'Image' => args[:image],
135
+ 'Cmd' => args[:command],
136
+ "Binds" => args[:volumes],
137
+ "Env" => args[:environment],
138
+ 'WorkingDir' => args[:working_directory],
139
+ 'name' => args[:name],
140
+ 'NetworkMode' => @network,
141
+ "OpenStdin" => true,
142
+ "Tty" => true,
143
+ 'PublishAllPorts' => true,
144
+ 'ExposedPorts' => exposed_ports,
145
+ 'HostConfig' => host_config,
146
+ 'NetworkingConfig' => network
131
147
  )
132
148
 
133
149
  container.start
134
150
 
151
+ success = (container.json['State']['ExitCode'] == 0) ? true: false
152
+ @logger.error("Unable to start docker container") unless success
153
+
135
154
  STDIN.raw do |stdin|
136
155
  container.attach(stdin: stdin, tty: true) do |chunk|
137
156
  print chunk
138
157
  end
139
158
  end
140
159
 
141
- success = (container.json['State']['ExitCode'] == 0) ? true: false
142
- @logger.error(output) unless success
143
-
144
- return container, success
160
+ return container, success
145
161
  end
146
162
 
147
163
  ##
@@ -152,12 +168,12 @@ module Minke
152
168
  ::Docker::Image.build_from_dir(dockerfile_dir, {:t => name}) do |v|
153
169
  data = /{"stream.*:"(.*)".*/.match(v)
154
170
  data = data[1].encode(Encoding.find('UTF-8'), {invalid: :replace, undef: :replace, replace: ''}) unless data == nil || data.length < 1
171
+ data.chomp('\n')
155
172
  $stdout.puts data unless data == nil
156
173
  end
157
174
  rescue => e
158
- @logger.error e
159
- message = /.*{"message":"(.*?)"}/.match(e.to_s)
160
- @logger.error "Error: #{message[1]}" unless message == nil || message.length < 1
175
+ message = e.message
176
+ @logger.error "Error: #{message}" unless message == nil || message.length < 1
161
177
  end
162
178
  end
163
179
 
@@ -198,6 +214,37 @@ module Minke
198
214
  def docker_version
199
215
  ::Docker.version['Version']
200
216
  end
217
+
218
+ def get_port_bindings args
219
+ host_config = {}
220
+ if args[:ports] != nil
221
+ port_bindings = {}
222
+ args[:ports].each do |p|
223
+ hostDest = p.split(":")
224
+ if hostDest[0] == ""
225
+ port_bindings[hostDest[1] + "/tcp"] = [{'HostPort' => "#{rand(40000..50000)}", 'HostIp' => "0.0.0.0"}]
226
+ else
227
+ port_bindings[hostDest[1] + "/tcp"] = [{'HostPort' => hostDest[0], 'HostIp' => "0.0.0.0"}]
228
+ end
229
+ end
230
+ host_config = {'PortBindings' => port_bindings }
231
+ end
232
+
233
+ return host_config
234
+ end
235
+
236
+ def get_exposed_ports args
237
+ port_bindings = {}
238
+ if args[:ports] != nil
239
+ args[:ports].each do |p|
240
+ hostDest = p.split(":")
241
+ port_bindings[hostDest[1] + "/tcp"] = {}
242
+ end
243
+ end
244
+
245
+ return port_bindings
246
+ end
247
+
201
248
  end
202
249
  end
203
250
  end
@@ -4,14 +4,20 @@ module Minke
4
4
  def initialize network_name, shell_runner
5
5
  @network_name = network_name
6
6
  @shell_runner = shell_runner
7
+ @created_network = false
7
8
  end
8
9
 
9
10
  def create
10
- @shell_runner.execute("docker network create #{@network_name}") if find_network.to_s == ''
11
+ if find_network.to_s == ''
12
+ @shell_runner.execute("docker network create #{@network_name}")
13
+ @created_network = true
14
+ end
11
15
  end
12
16
 
13
17
  def remove
14
- @shell_runner.execute("docker network rm #{@network_name}", true) unless find_network.to_s == ''
18
+ if find_network.to_s != '' && @created_network == true
19
+ @shell_runner.execute("docker network rm #{@network_name}", true)
20
+ end
15
21
  end
16
22
 
17
23
  private
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
- MINKE_VERSION="1.14.1"
3
+ MINKE_VERSION="1.14.2"
4
4
 
5
5
  DOCKER_SOCK="/var/run/docker.sock:/var/run/docker.sock"
6
6
  NEW_UUID=$(base64 /dev/urandom | tr -d '/+' | head -c 32 | tr '[:upper:]' '[:lower:]')
@@ -9,13 +9,15 @@ module Minke
9
9
  compose_file = @config.compose_file_for(@task_name)
10
10
  compose_file = File.expand_path(compose_file)
11
11
  compose = @docker_compose_factory.create compose_file unless compose_file == nil
12
-
12
+
13
13
  run_with_block do |pre_tasks, post_tasks|
14
14
  begin
15
+ services = create_list_of_links(compose.services)
15
16
  compose.up
16
17
  pre_tasks.call
18
+
17
19
  @logger.info "## Shell open to build container"
18
- run_command_in_container('/bin/sh', true)
20
+ run_command_in_container(['/bin/sh','-c','ls && /bin/sh'], true, services, @task_settings.ports)
19
21
  rescue SystemExit, Interrupt
20
22
  @logger.info "Stopping...."
21
23
  raise SystemExit
@@ -26,6 +28,15 @@ module Minke
26
28
  end
27
29
  end
28
30
 
31
+ def create_list_of_links compose_services
32
+ services = []
33
+ compose_services.each do |k,v|
34
+ services.push(k)
35
+ end
36
+
37
+ services
38
+ end
29
39
  end
40
+
30
41
  end
31
42
  end
@@ -63,7 +63,7 @@ module Minke
63
63
 
64
64
  ##
65
65
  # runs the given command in a docker container
66
- def run_command_in_container command, blocking = false
66
+ def run_command_in_container(command, blocking = false, links = nil, ports = nil)
67
67
  begin
68
68
  @logger.info "Running command: #{command}"
69
69
  settings = @generator_config.build_settings.docker_settings
@@ -78,12 +78,19 @@ module Minke
78
78
  environment.push "GIT_SSH_COMMAND=ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
79
79
  end
80
80
 
81
+ if @task_settings.consul_loader != nil && links != nil
82
+ links.push "consul"
83
+ end
84
+
85
+
81
86
  args = {
82
87
  :image => build_image,
83
88
  :command => command,
84
89
  :volumes => volumes,
85
90
  :environment => environment,
86
- :working_directory => working_directory
91
+ :working_directory => working_directory,
92
+ :links => links,
93
+ :ports => ports,
87
94
  }
88
95
 
89
96
  if blocking == false
data/lib/minke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Minke
2
- VERSION = "1.14.1"
2
+ VERSION = "1.14.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minke
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.1
4
+ version: 1.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nic Jackson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler