dctl_rb 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/exe/dctl +25 -23
  4. data/lib/dctl/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6297d5b6b0bb0266f791a4c1a6b559b27c774ff384c8d96f297870723a44f5d1
4
- data.tar.gz: 2cef8f9c71696aeabe7658084162dd8d671a97ce15999206117440c21d81eeb5
3
+ metadata.gz: 76b106d7f164cf92f1e20f3634edb3967087ac9f00105aa7aad6de6a3826ee85
4
+ data.tar.gz: 289ecb2b23ce9f6f0e9c591aca62a08ffdd1a6008917981bf17aff34e2e4e591
5
5
  SHA512:
6
- metadata.gz: caa23a96d0d7dbd28e1f1c88d7c68b65fdfeb42ecc44ee14bf6caf7911c45587c797ad70a0b05f273a4eb56ef64be09ea1d89ab2473b989e31cb717e7987ac0f
7
- data.tar.gz: d8ba8cdae1e836c0f1790b107927797b70b31b134c449323a0c118cf4edccda8591844106901049e0eba66727cfd6b925eb8e35d60335aeeef2081f77dfa03c3
6
+ metadata.gz: ea66ea9ab27f284139660889b8795773d8817d619a9127b94c93dd980d807ead40f78af8be3ffa2ef05ad2ecb90826833dad951bf1f738b206fb0fb79a9f38ab
7
+ data.tar.gz: fee291bd1101ba45e5895b17e854ab23534e8c94e683383e7577ebd746c8c11f368e32d9a00033fc83178287c8d62dea69a1f660e858141a18cedddc47193cce
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dctl_rb (0.9.1)
4
+ dctl_rb (0.9.2)
5
5
  config (>= 1, < 2)
6
6
  rainbow (>= 2.2, < 3)
7
7
  rake (~> 12)
data/exe/dctl CHANGED
@@ -14,6 +14,7 @@ module Dctl
14
14
  CMD_COLOR = :dimgray
15
15
 
16
16
  class_option :env, default: "dev", type: :string
17
+ class_option :host, type: :string
17
18
 
18
19
  desc "build", "Build images. Pass image name to build a specific one; otherwise builds all"
19
20
  option :pull, type: :boolean, default: true
@@ -44,7 +45,7 @@ module Dctl
44
45
 
45
46
  images.each do |image|
46
47
  tag = dctl.image_tag(image)
47
- push_cmds << "#{sudo}docker push #{tag}"
48
+ push_cmds << "#{sudo}docker #{docker_opts} push #{tag}"
48
49
  end
49
50
 
50
51
  push_cmd = push_cmds.join " && "
@@ -59,7 +60,7 @@ module Dctl
59
60
 
60
61
  images.each do |image|
61
62
  tag = dctl.image_tag(image)
62
- pull_cmds << "#{sudo}docker pull #{tag}"
63
+ pull_cmds << "#{sudo}docker #{docker_opts} pull #{tag}"
63
64
  end
64
65
 
65
66
  pull_cmd = pull_cmds.join " && "
@@ -74,13 +75,13 @@ module Dctl
74
75
  FileUtils.rm pidfile if File.exist? pidfile
75
76
 
76
77
  compose_opts = %w(--remove-orphans)
77
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} up #{compose_opts.join(" ")}", exec: true
78
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} up #{compose_opts.join(" ")}", exec: true
78
79
  end
79
80
 
80
81
  desc "down", "Stop one or many containers"
81
82
  def down(*images)
82
83
  dctl = Dctl::Main.new env: options[:env]
83
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} down #{images.join(" ")}", exec: true
84
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} down #{images.join(" ")}", exec: true
84
85
  end
85
86
 
86
87
  desc "rm", "Remove one or many containers"
@@ -88,44 +89,44 @@ module Dctl
88
89
  def rm(*images)
89
90
  dctl = Dctl::Main.new env: options[:env]
90
91
  opts = " --force" if options[:force]
91
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} rm#{opts} #{images.join(" ")}", exec: true
92
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} rm#{opts} #{images.join(" ")}", exec: true
92
93
  end
93
94
 
94
95
  desc "start", "Start one or many containers"
95
96
  def start(*images)
96
97
  dctl = Dctl::Main.new env: options[:env]
97
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} start #{images.join(" ")}", exec: true
98
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} start #{images.join(" ")}", exec: true
98
99
  end
99
100
 
100
101
  desc "stop", "Stop one or many containers"
101
102
  def stop(*images)
102
103
  dctl = Dctl::Main.new env: options[:env]
103
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} stop #{images.join(" ")}", exec: true
104
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} stop #{images.join(" ")}", exec: true
104
105
  end
105
106
 
106
107
  desc "restart", "Restart one or many containers"
107
108
  def restart(*images)
108
109
  dctl = Dctl::Main.new env: options[:env]
109
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} restart #{images.join(" ")}", exec: true
110
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} restart #{images.join(" ")}", exec: true
110
111
  end
111
112
 
112
113
  desc "create", "Bring an image up without starting it"
113
114
  def create(*images)
114
115
  dctl = Dctl::Main.new env: options[:env]
115
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} up --no-start #{images.join(" ")}", exec: true
116
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} up --no-start #{images.join(" ")}", exec: true
116
117
  end
117
118
 
118
119
  desc "run [IMAGE] [COMMAND]", "Run a command on the given image"
119
120
  def runcmd(image, *commands)
120
121
  dctl = Dctl::Main.new env: options[:env]
121
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} run #{image} #{commands.join(" ")}", exec: true
122
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} run #{image} #{commands.join(" ")}", exec: true
122
123
  end
123
124
 
124
125
  desc "exec [IMAGE] [COMMAND]", "Execute a command on the given _running_ image"
125
126
  map exec: :_exec # avoid overwriting Kernel#exec
126
127
  def _exec(image, *commands)
127
128
  dctl = Dctl::Main.new env: options[:env]
128
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} exec #{image} #{commands.join(" ")}", exec: true
129
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} exec #{image} #{commands.join(" ")}", exec: true
129
130
  end
130
131
 
131
132
  desc "recreate", "Stop, remove, build, create, and start a container"
@@ -142,7 +143,7 @@ module Dctl
142
143
  desc "ps", "List running containers for this environment"
143
144
  def ps
144
145
  dctl = Dctl::Main.new env: options[:env]
145
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} ps", exec: true
146
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} ps", exec: true
146
147
  end
147
148
 
148
149
  desc "release IMAGE", "Increase the version number for the given image"
@@ -158,7 +159,7 @@ module Dctl
158
159
  local_data_dir = File.expand_path "../tmp/psql-#{env}", __FILE__
159
160
  `#{sudo}rm -r #{local_data_dir}` if File.exists? local_data_dir # todo prompt
160
161
 
161
- cmd = "#{sudo}docker-compose -f #{dctl.compose_file_path} run --rm psql /bin/bash -c /etc/initdb.sh"
162
+ cmd = "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} run --rm psql /bin/bash -c /etc/initdb.sh"
162
163
 
163
164
  stream_output cmd, exec: true
164
165
  end
@@ -178,7 +179,7 @@ module Dctl
178
179
 
179
180
  next if keep_after_tag < 0
180
181
 
181
- cmd = "#{sudo}docker images #{dctl.image_tag(image, version: nil)} --filter before=#{dctl.image_tag(image, version: keep_after_tag)} -q"
182
+ cmd = "#{sudo}docker #{docker_opts} images #{dctl.image_tag(image, version: nil)} --filter before=#{dctl.image_tag(image, version: keep_after_tag)} -q"
182
183
  puts Rainbow(cmd).fg CMD_COLOR
183
184
  stdout, stderr, status = Open3.capture3(cmd)
184
185
  if status.success?
@@ -207,7 +208,7 @@ module Dctl
207
208
  desc "bash CONTAINER", "Create a new instance of the given image with a bash prompt"
208
209
  def bash(container = "app")
209
210
  dctl = Dctl::Main.new env: options[:env]
210
- cmd = "#{sudo}docker-compose -f #{dctl.compose_file_path} run --rm #{container} /bin/bash"
211
+ cmd = "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} run --rm #{container} /bin/bash"
211
212
 
212
213
  stream_output cmd, exec: true
213
214
  end
@@ -215,7 +216,7 @@ module Dctl
215
216
  desc "connect CONTAINER", "Connect to a running container."
216
217
  def connect(image = "app")
217
218
  dctl = Dctl::Main.new env: options[:env]
218
- stream_output "#{sudo}docker-compose -f #{dctl.compose_file_path} exec #{image} /bin/bash", exec: true
219
+ stream_output "#{sudo}docker-compose #{docker_opts} -f #{dctl.compose_file_path} exec #{image} /bin/bash", exec: true
219
220
  end
220
221
 
221
222
  desc "attach CONTAINER", "Connect to a running container."
@@ -224,7 +225,7 @@ module Dctl
224
225
  dctl = Dctl::Main.new env: options[:env]
225
226
  tag = dctl.image_tag(image)
226
227
 
227
- cmd = "#{sudo}docker ps --filter ancestor=#{image} -aq | head -n1"
228
+ cmd = "#{sudo}docker #{docker_opts} ps --filter ancestor=#{image} -aq | head -n1"
228
229
  puts cmd
229
230
  container = `#{cmd}`.chomp
230
231
 
@@ -259,14 +260,15 @@ module Dctl
259
260
  end
260
261
 
261
262
  def docker_opts
262
- return "" unless ENV["JENKINS"]
263
- opts = "--tls"
263
+ opts = []
264
264
 
265
- if host = ENV["DOCKER_HOST_IP"]
266
- opts += " --host tcp://#{host}"
267
- end
265
+ # Respect both DOCKER_HOST and --host, but prefer --host if both are
266
+ # present.
267
+ host = options[:host]
268
+ host ||= !ENV["DOCKER_HOST"].nil? ? ENV["DOCKER_HOST"] : nil
269
+ opts << "--host #{host}" if host
268
270
 
269
- opts
271
+ opts.join " "
270
272
  end
271
273
  end
272
274
  end
data/lib/dctl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dctl
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dctl_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Toniazzo