dctl_rb 0.9.1 → 0.9.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/exe/dctl +25 -23
- data/lib/dctl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76b106d7f164cf92f1e20f3634edb3967087ac9f00105aa7aad6de6a3826ee85
|
4
|
+
data.tar.gz: 289ecb2b23ce9f6f0e9c591aca62a08ffdd1a6008917981bf17aff34e2e4e591
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea66ea9ab27f284139660889b8795773d8817d619a9127b94c93dd980d807ead40f78af8be3ffa2ef05ad2ecb90826833dad951bf1f738b206fb0fb79a9f38ab
|
7
|
+
data.tar.gz: fee291bd1101ba45e5895b17e854ab23534e8c94e683383e7577ebd746c8c11f368e32d9a00033fc83178287c8d62dea69a1f660e858141a18cedddc47193cce
|
data/Gemfile.lock
CHANGED
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
|
-
|
263
|
-
opts = "--tls"
|
263
|
+
opts = []
|
264
264
|
|
265
|
-
|
266
|
-
|
267
|
-
|
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