dce 0.0.0 → 1.0.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.
- checksums.yaml +4 -4
- data/bin/dce +13 -132
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbf00e5fba8316d9b49e3ddec96306f03a04d6aa
|
4
|
+
data.tar.gz: a4226ca5bbca2c08333a9dc62c1abeb03f091709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3019a466710734d02250d5e0694caaa81fef083db39f70ae6621a671cdfa9ef6236e5f45575ec1a4a6538bd28ed64e430ef8cca9426571fdaa6c2d3219862cbf
|
7
|
+
data.tar.gz: 36529e899d0fcf4ecaa0dc587e3e6c49c39588ec56f5d7cb0729c0b623edf5e10158cb910a36868c5d1bfa0f8fb5146d8deb4e1bc7f12bb4409d63cd603aa8c3
|
data/bin/dce
CHANGED
@@ -1,145 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Wishlist:
|
4
|
-
# Option to delete .dce_container.
|
5
|
-
# Option for using run instead of exec?
|
6
|
-
|
7
3
|
require 'yaml'
|
4
|
+
if ENV['COVERAGE']
|
5
|
+
require 'simplecov'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
parse_args
|
13
|
-
|
14
|
-
@conf_file = File.join(File.dirname(docker_compose_file), '.dce_container')
|
15
|
-
config_container = nil
|
16
|
-
if File.exists? @conf_file
|
17
|
-
config_container = File.read @conf_file
|
18
|
-
end
|
19
|
-
|
20
|
-
if @query
|
21
|
-
if config_container
|
22
|
-
STDOUT.puts(config_container)
|
23
|
-
exit
|
24
|
-
else
|
25
|
-
STDERR.puts("No container saved.")
|
26
|
-
exit!
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
if !@container
|
31
|
-
@container = config_container ? config_container : query_container
|
32
|
-
end
|
33
|
-
|
34
|
-
if @container != config_container
|
35
|
-
File.write(@conf_file, @container)
|
36
|
-
end
|
37
|
-
|
38
|
-
# If no command given, open a shell.
|
39
|
-
if (@command.strip.empty?)
|
40
|
-
@command = "if [ -e /usr/bin/fish ]; then /usr/bin/fish; elif [ -e /bin/bash ]; then /bin/bash; else /bin/sh; fi"
|
41
|
-
end
|
42
|
-
|
43
|
-
args = '-i'
|
44
|
-
args += 't' if STDIN.tty?
|
45
|
-
container_id = %x{docker-compose ps -q #{@container}}.chomp
|
46
|
-
command = "docker exec #{args} #{container_id} sh -c '#{@command}'"
|
47
|
-
STDERR.puts "Exec'ing: " + command if @verbose
|
48
|
-
exec command unless @dry_run
|
49
|
-
end
|
50
|
-
|
51
|
-
# Return path to the docker-compose.yml file
|
52
|
-
# Will exit with an error if not found
|
53
|
-
def docker_compose_file
|
54
|
-
unless @compose_file
|
55
|
-
dir = Dir.pwd()
|
56
|
-
while dir != "/"
|
57
|
-
file = File.join(dir, 'docker-compose.yml')
|
58
|
-
if FileTest.exists?(file)
|
59
|
-
@compose_file = file
|
60
|
-
break;
|
61
|
-
end
|
62
|
-
dir = File.dirname(dir)
|
63
|
-
end
|
7
|
+
# Redefine exec to save coverage first.
|
8
|
+
module Kernel
|
9
|
+
alias_method :exec_real, :exec
|
64
10
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
11
|
+
def exec(command)
|
12
|
+
SimpleCov.result
|
13
|
+
exec_real command
|
69
14
|
end
|
70
|
-
|
71
|
-
return @compose_file
|
72
15
|
end
|
73
16
|
|
74
|
-
|
75
|
-
|
76
|
-
# Not using a proper option parse library, as it will get confused
|
77
|
-
# by options for the command given. We use a simple parser.
|
78
|
-
while /^-/ =~ ARGV[0]
|
79
|
-
option = ARGV.shift
|
80
|
-
case option
|
81
|
-
when '-c', '--container'
|
82
|
-
@container = ARGV.shift
|
83
|
-
if !get_containers.include? @container
|
84
|
-
STDERR.puts "Unknown container #{@container}"
|
85
|
-
exit!
|
86
|
-
end
|
87
|
-
when '-v', '--verbose'
|
88
|
-
@verbose = true
|
89
|
-
when '-n', '--dry-run'
|
90
|
-
@verbose = true
|
91
|
-
@dry_run = true
|
92
|
-
when '-?', '--print-service'
|
93
|
-
@query = true
|
94
|
-
when '-h', '--help'
|
95
|
-
STDERR.puts <<-HEREDOC
|
96
|
-
Usage: #{File.basename($0)} [OPTIONS]... COMMAND
|
97
|
-
Runs COMMAND in docker-compose container.
|
98
|
-
|
99
|
-
On first run, asks for the service container to use and saves it to .dce_container next
|
100
|
-
to the docker-compose.yml file.
|
101
|
-
|
102
|
-
If no command given, opens a shell.
|
103
|
-
|
104
|
-
Options:
|
105
|
-
-c, --container SERVICE use the container of the specified service
|
106
|
-
replaces the selected container in the .dce_container
|
107
|
-
-v, --verbose print exec'ed command
|
108
|
-
-n, --dry-run only print exec'ed command, don't run
|
109
|
-
-?, --print-service print the service saved
|
110
|
-
-h, --help print this help and exit
|
111
|
-
|
112
|
-
HEREDOC
|
113
|
-
exit
|
114
|
-
else
|
115
|
-
STDERR.puts "Unknown option #{option}"
|
116
|
-
exit!
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
@command = ARGV.join(' ')
|
121
|
-
end
|
122
|
-
|
123
|
-
# Ask the user to select a container
|
124
|
-
# The options are taken from the docker-compose.yml file
|
125
|
-
def query_container
|
126
|
-
containers = get_containers
|
127
|
-
STDERR.puts "Please select container [#{containers.join(', ')}]"
|
128
|
-
choice = STDIN.gets.strip
|
129
|
-
exit if choice.empty?
|
130
|
-
if !containers.include?(choice)
|
131
|
-
STDERR.puts "Illegal choice."
|
132
|
-
exit!
|
133
|
-
end
|
134
|
-
choice
|
135
|
-
end
|
136
|
-
|
137
|
-
# Read containers from docker-compose.yml
|
138
|
-
def get_containers
|
139
|
-
content = YAML::load(File.read(docker_compose_file))
|
140
|
-
content.has_key?('version') ? content['services'].keys : content.keys
|
17
|
+
SimpleCov.at_exit do
|
18
|
+
SimpleCov.result
|
141
19
|
end
|
142
20
|
end
|
143
21
|
|
22
|
+
# Possibly not the right way to load file.
|
23
|
+
require_relative '../lib/dce.rb'
|
24
|
+
|
144
25
|
app = DCE.new
|
145
26
|
app.run
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Fini Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Run shell commands in docker.
|
14
14
|
email: xen@xen.dk
|
15
15
|
executables:
|
16
16
|
- dce
|
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.
|
41
|
+
rubygems_version: 2.6.14.4
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: DCE
|