takelage 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/takelage/docker/container/module.rb +81 -7
- data/lib/takelage/lib/system.rb +4 -4
- data/lib/takelage/version +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: 2fd909364c4dbb82c0c9e8ac1ba6ccfed67e51fe56794b7a6aa36af3ea86e6f2
|
4
|
+
data.tar.gz: b5343bcba1852c0d56ce454c5ff8ed6172220747087b13a0b24cd8c4748761aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1565a6d13da908d8fae2f10bcd0e45264945559c32483d90952940a1225fd5c3643579a8f20e9ab3c6d9e0a4e10d2618c0d0e01a027049e8ffcf25b53c19667b
|
7
|
+
data.tar.gz: d395c04730066c07d2b288913b0353538305e03d5cda5717414f5475357a2b19a7e0286f5f85f3548d69d9ae1ee6d208d85ab63d1de2677643566594a5e782fc
|
data/README.md
CHANGED
@@ -16,8 +16,8 @@ The takelage devops framework consists of these projects:
|
|
16
16
|
|
17
17
|
| App | Description |
|
18
18
|
| --- | ----------- |
|
19
|
-
| *[takelage-cli](https://github.com/geospin-takelage/takelage-cli)* | takelage command line interface |
|
20
19
|
| *[takelage-dev](https://github.com/geospin-takelage/takelage-dev)* | takelage development environment |
|
20
|
+
| *[takelage-cli](https://github.com/geospin-takelage/takelage-cli)* | takelage command line interface |
|
21
21
|
| *[takelage-bit](https://github.com/geospin-takelage/takelage-bit)* | takelage [bit](https://github.com/teambit/bit) server |
|
22
22
|
|
23
23
|
## Installation
|
@@ -9,6 +9,7 @@ module DockerContainerModule
|
|
9
9
|
|
10
10
|
docker_socket_start
|
11
11
|
|
12
|
+
_create_network @hostname unless _network_check_existing @hostname
|
12
13
|
_create_container @hostname unless docker_container_check_existing @hostname
|
13
14
|
_run_command_in_container @hostname, command
|
14
15
|
end
|
@@ -19,6 +20,7 @@ module DockerContainerModule
|
|
19
20
|
|
20
21
|
exit false unless configured? %w(docker_repo docker_image docker_tag)
|
21
22
|
|
23
|
+
_create_network @hostname unless _network_check_existing @hostname
|
22
24
|
_create_container @hostname unless docker_container_check_existing @hostname
|
23
25
|
end
|
24
26
|
|
@@ -30,6 +32,7 @@ module DockerContainerModule
|
|
30
32
|
|
31
33
|
docker_socket_start
|
32
34
|
|
35
|
+
_create_network @hostname unless _network_check_existing @hostname
|
33
36
|
_create_container @hostname unless docker_container_check_existing @hostname
|
34
37
|
_enter_container @hostname
|
35
38
|
end
|
@@ -40,8 +43,16 @@ module DockerContainerModule
|
|
40
43
|
|
41
44
|
exit false unless configured? %w(docker_image)
|
42
45
|
|
46
|
+
networks = []
|
47
|
+
|
43
48
|
_get_containers.each do |container|
|
49
|
+
name = _get_container_name_by_id container
|
44
50
|
_stop_container container
|
51
|
+
networks << name unless networks.include? name
|
52
|
+
end
|
53
|
+
|
54
|
+
networks.each do |network|
|
55
|
+
_remove_network network if _network_check_existing network
|
45
56
|
end
|
46
57
|
end
|
47
58
|
|
@@ -51,8 +62,18 @@ module DockerContainerModule
|
|
51
62
|
|
52
63
|
exit false unless configured? %w(docker_image)
|
53
64
|
|
65
|
+
networks = []
|
66
|
+
|
54
67
|
_get_containers.each do |container|
|
55
|
-
|
68
|
+
if docker_container_check_orphaned container
|
69
|
+
name = _get_container_name_by_id container
|
70
|
+
_stop_container container
|
71
|
+
networks << name unless networks.include? name
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
networks.each do |network|
|
76
|
+
_remove_network network if _network_check_existing network
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
@@ -90,6 +111,7 @@ module DockerContainerModule
|
|
90
111
|
"--env TZ=#{@timezone} " +
|
91
112
|
"--hostname #{container} " +
|
92
113
|
"--name #{container} " +
|
114
|
+
"--network #{container} " +
|
93
115
|
'--privileged ' +
|
94
116
|
'--rm ' +
|
95
117
|
'--tty ' +
|
@@ -110,6 +132,16 @@ module DockerContainerModule
|
|
110
132
|
run cmd_docker_create
|
111
133
|
end
|
112
134
|
|
135
|
+
# Create docker network.
|
136
|
+
def _create_network(network)
|
137
|
+
log.debug "Create network \"#{network}\""
|
138
|
+
|
139
|
+
cmd_create_network = 'docker network create ' +
|
140
|
+
"#{network}"
|
141
|
+
|
142
|
+
run cmd_create_network
|
143
|
+
end
|
144
|
+
|
113
145
|
# Enter existing docker container.
|
114
146
|
def _enter_container(container)
|
115
147
|
log.debug "Entering container \"#{container}\""
|
@@ -129,6 +161,19 @@ module DockerContainerModule
|
|
129
161
|
run_and_exit cmd_docker_enter
|
130
162
|
end
|
131
163
|
|
164
|
+
# Get container name by id.
|
165
|
+
def _get_container_name_by_id container
|
166
|
+
log.debug "Getting name of container #{container}"
|
167
|
+
|
168
|
+
cmd_get_container_name_by_id = 'docker ps ' +
|
169
|
+
"--filter id=#{container} "+
|
170
|
+
'--format "{{.Names}}"'
|
171
|
+
|
172
|
+
stdout_str, stderr_str, status = run_and_check cmd_get_container_name_by_id
|
173
|
+
|
174
|
+
stdout_str.chomp
|
175
|
+
end
|
176
|
+
|
132
177
|
# Get all docker containers.
|
133
178
|
# @return [Array] list of docker containers
|
134
179
|
def _get_containers
|
@@ -145,14 +190,33 @@ module DockerContainerModule
|
|
145
190
|
stdout_str.split(/\n+/)
|
146
191
|
end
|
147
192
|
|
148
|
-
#
|
149
|
-
def
|
150
|
-
log.debug "
|
193
|
+
# Check if docker network exists.
|
194
|
+
def _network_check_existing(network)
|
195
|
+
log.debug "Checking if network \"#{network}\" is existing"
|
151
196
|
|
152
|
-
|
153
|
-
|
197
|
+
cmd_docker_network_exist = 'docker network ls ' +
|
198
|
+
'--quiet ' +
|
199
|
+
"--filter name=#{network}"
|
154
200
|
|
155
|
-
|
201
|
+
stdout_str, stderr_str, status = run_and_check cmd_docker_network_exist
|
202
|
+
|
203
|
+
if stdout_str.to_s.strip.empty?
|
204
|
+
log.debug "Network \"#{network}\" is not existing"
|
205
|
+
return false
|
206
|
+
end
|
207
|
+
|
208
|
+
log.debug "Network \"#{network}\" is existing"
|
209
|
+
true
|
210
|
+
end
|
211
|
+
|
212
|
+
# Remove docker network.
|
213
|
+
def _remove_network network
|
214
|
+
log.debug "Remove network \"#{network}\""
|
215
|
+
|
216
|
+
cmd_remove_network = 'docker network rm ' +
|
217
|
+
"#{network}"
|
218
|
+
|
219
|
+
run cmd_remove_network
|
156
220
|
end
|
157
221
|
|
158
222
|
# Enter existing docker container.
|
@@ -166,4 +230,14 @@ module DockerContainerModule
|
|
166
230
|
|
167
231
|
run_and_exit cmd_docker_run_command
|
168
232
|
end
|
233
|
+
|
234
|
+
# Stop container.
|
235
|
+
def _stop_container(container)
|
236
|
+
log.debug "Stopping container \"#{container}\""
|
237
|
+
|
238
|
+
cmd_docker_stop = 'docker stop ' +
|
239
|
+
"#{container}"
|
240
|
+
|
241
|
+
run cmd_docker_stop
|
242
|
+
end
|
169
243
|
end
|
data/lib/takelage/lib/system.rb
CHANGED
@@ -9,7 +9,7 @@ module SystemModule
|
|
9
9
|
# Run a command and return the result.
|
10
10
|
# @return [Boolean] success of command run
|
11
11
|
def run_and_check(command)
|
12
|
-
log.debug "Running command
|
12
|
+
log.debug "Running command \"#{command}\""
|
13
13
|
stdout_str, stderr_str, status = Open3.capture3 command
|
14
14
|
return stdout_str, stderr_str, status
|
15
15
|
end
|
@@ -65,7 +65,7 @@ module SystemModule
|
|
65
65
|
# Run a command.
|
66
66
|
# @return [String] stdout of command
|
67
67
|
def run(command, realtime=false)
|
68
|
-
log.debug "Running command
|
68
|
+
log.debug "Running command \"#{command}\""
|
69
69
|
stdout_str = ''
|
70
70
|
stderr_str = ''
|
71
71
|
status = ''
|
@@ -91,13 +91,13 @@ module SystemModule
|
|
91
91
|
|
92
92
|
# Use Kernel#exec to replace the ruby process with a command.
|
93
93
|
def run_and_exit(command)
|
94
|
-
log.debug "Running command
|
94
|
+
log.debug "Running command \"#{command}\" and exiting afterwards"
|
95
95
|
exec command
|
96
96
|
end
|
97
97
|
|
98
98
|
# Use Kernel#fork and Kernel#exec to run a command as a background process.
|
99
99
|
def run_and_fork(command)
|
100
|
-
log.debug "Running command
|
100
|
+
log.debug "Running command \"#{command}\" as a background process"
|
101
101
|
job = fork do
|
102
102
|
exec command
|
103
103
|
end
|
data/lib/takelage/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|