takelage 0.4.5 → 0.5.0

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
  SHA256:
3
- metadata.gz: 9962805477b6efa0976aa88ee6168f638f42bb47457eb6d4a541c8228a484bf6
4
- data.tar.gz: c9cb238ca757eb45b379e245ee76281cba5070594fce8d5c994760a7af2b98fb
3
+ metadata.gz: e94a030afd607b722c46cdb7672eab62d2164b979a667f81adbacf5cfc62fe41
4
+ data.tar.gz: 0a69ac6c28f9212278be3801153eef5e7b15ed746936f02b16bb1d346df2a1d8
5
5
  SHA512:
6
- metadata.gz: c6a2d5152cd63931a85c68a71601adc35a2a70f5f770497864e395deb9c63bbf24122ab329f55275d891e086df39dadb07192a1869c4ca17ec5f0b937440d83b
7
- data.tar.gz: ac21c2529a2a1edf411557a55802ec759f06778d02214c48d2bbe1fe08abfccb17d2219ea1b45bed8055c33e441c45d7b5230454ff2e7fee4a8d893cc4adf5a8
6
+ metadata.gz: 36a7abc07a493f918c12355bad5b84fea6488993e32cf78d5e8bb1b0d530beb12825d4cba651e03b9a84e2285f40ebd9667eb9c7e66a0fb990785e26da3754cd
7
+ data.tar.gz: dadcb5a7aaf475e143477bca61af6edccbc2e029aefd91c46c100b5bc9d5f369eb4fb881aab02ac73e136dbb503e4225b5b6fa72608705f3c3b3c5adcf10e8f9
@@ -7,10 +7,10 @@ module BitCheckModule
7
7
  log.debug 'Check if this is a bit workspace'
8
8
 
9
9
  cmd_bit_repo = config.active['bit_repo']
10
- stdout_str_repo, stderr_str_repo, status_repo = run_and_check cmd_bit_repo
10
+ status_repo = try cmd_bit_repo
11
11
 
12
12
  cmd_pwd = config.active['pwd']
13
- stdout_str_dir, stderr_str_dir, status_dir = run_and_check cmd_pwd
13
+ stdout_str_dir = run cmd_pwd
14
14
 
15
15
  dir = stdout_str_dir.strip
16
16
 
@@ -31,7 +31,7 @@ module BitClipboardModule
31
31
 
32
32
  # check if bit.dev remote scope exists
33
33
  cmd_bit_list_scope = config.active['bit_list_scope'] % {scope: scope}
34
- stdout_str, stderr_str, status = run_and_check cmd_bit_list_scope
34
+ status = try cmd_bit_list_scope
35
35
 
36
36
  unless status.exitstatus.zero?
37
37
  log.error "No bit.dev remote scope \"#{scope}\" found"
@@ -42,7 +42,7 @@ module BitClipboardModule
42
42
 
43
43
  # check if bit remote scope is added to local workspace
44
44
  cmd_bit_list_remotes = config.active['bit_list_remotes']
45
- stdout_str, stderr_str, status = run_and_check cmd_bit_list_remotes
45
+ stdout_str = run cmd_bit_list_remotes
46
46
 
47
47
  unless /.*\s+#{scope}\s+.*/m.match? stdout_str
48
48
  log.error "No bit remote scope \"#{scope}\" found in local bit workspace"
@@ -113,7 +113,7 @@ module BitClipboardModule
113
113
 
114
114
  _remove_bit_artifacts
115
115
 
116
- log.info "Pasted bit component \"#{cid}\"" +
116
+ log.info "Pasted bit component \"#{cid}\" " +
117
117
  "to directory \"#{dir}\""
118
118
  end
119
119
 
@@ -48,7 +48,7 @@ module BitScopeModule
48
48
  cmd_bit_scope_list = config.active['bit_scope_list'] % {root: root}
49
49
 
50
50
  # run ssh command with scope list command
51
- scope_list, stderr, status = run_and_check "#{cmd_bit_ssh} '#{cmd_bit_scope_list}'"
51
+ scope_list = run "#{cmd_bit_ssh} '#{cmd_bit_scope_list}'"
52
52
 
53
53
  # remove bit remote root directory from results
54
54
  scope_list.gsub!(/#{root}\/*/, '')
@@ -0,0 +1,23 @@
1
+ module Takelage
2
+
3
+ # takelage docker check
4
+ class DockerCheck < SubCommandBase
5
+
6
+ include LoggingModule
7
+ include SystemModule
8
+ include DockerCheckModule
9
+
10
+ #
11
+ # docker check running
12
+ #
13
+ desc 'running [TAG]', 'Check if docker daemon is running'
14
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
15
+ Check if docker daemon is running
16
+ LONGDESC
17
+ # Check if docker daemon is running.
18
+ def running
19
+ exit docker_check_running
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # takelage docker check module
2
+ module DockerCheckModule
3
+
4
+ # Backend method for docker check running.
5
+ # @return [Boolean] is the docker daemon running?
6
+ def docker_check_running
7
+ log.debug "Check if the docker daemon is running"
8
+
9
+ cmd_docker_info = 'docker info'
10
+
11
+ status = try cmd_docker_info
12
+
13
+ unless status.exitstatus.zero?
14
+ log.error "The docker daemon is not running"
15
+ return false
16
+ end
17
+
18
+ log.debug "The docker daemon is running"
19
+ true
20
+ end
21
+ end
@@ -3,6 +3,9 @@ module Takelage
3
3
  # takelage docker
4
4
  class Docker < SubCommandBase
5
5
 
6
+ desc 'check [COMMAND]', 'Check docker'
7
+ subcommand 'check', DockerCheck
8
+
6
9
  desc 'container [COMMAND]', 'Handle docker container'
7
10
  subcommand 'container', DockerContainer
8
11
 
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckModule
9
10
  include DockerContainerCheckModule
10
11
 
11
12
  #
@@ -6,11 +6,13 @@ module DockerContainerCheckModule
6
6
  def docker_container_check_existing(container)
7
7
  log.debug "Checking if container \"#{container}\" is existing"
8
8
 
9
+ exit false unless docker_check_running
10
+
9
11
  cmd_docker_existing = 'docker ps ' +
10
12
  "--filter name=^#{container}$ " +
11
13
  '--quiet'
12
14
 
13
- stdout_str, stderr_str, status = run_and_check cmd_docker_existing
15
+ stdout_str = run cmd_docker_existing
14
16
 
15
17
  if stdout_str.to_s.strip.empty?
16
18
  log.debug "Container \"#{container}\" is not existing"
@@ -26,11 +28,13 @@ module DockerContainerCheckModule
26
28
  def docker_container_check_network(network)
27
29
  log.debug "Checking if network \"#{network}\" is existing"
28
30
 
31
+ exit false unless docker_check_running
32
+
29
33
  cmd_docker_network = 'docker network ls ' +
30
34
  '--quiet ' +
31
35
  "--filter name=^#{network}$"
32
36
 
33
- stdout_str, stderr_str, status = run_and_check cmd_docker_network
37
+ stdout_str = run cmd_docker_network
34
38
 
35
39
  if stdout_str.to_s.strip.empty?
36
40
  log.debug "Network \"#{network}\" is not existing"
@@ -46,12 +50,14 @@ module DockerContainerCheckModule
46
50
  def docker_container_check_orphaned(container)
47
51
  log.debug "Check if container \"#{container}\" is orphaned"
48
52
 
53
+ exit false unless docker_check_running
54
+
49
55
  cmd_docker_orphaned = 'docker exec ' +
50
56
  '--interactive ' +
51
57
  "#{container} " +
52
58
  'ps a'
53
59
 
54
- stdout_str, stderr_str, status = run_and_check cmd_docker_orphaned
60
+ stdout_str = run cmd_docker_orphaned
55
61
 
56
62
  if stdout_str.include? '/loginpoint.py'
57
63
  log.debug "Container \"#{container}\" isn't orphaned"
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckModule
9
10
  include DockerContainerCheckModule
10
11
  include DockerContainerModule
11
12
  include DockerImageTagLatestModule
@@ -5,6 +5,8 @@ module DockerContainerModule
5
5
  def docker_container_command(command)
6
6
  log.debug "Running command in container"
7
7
 
8
+ exit false unless docker_check_running
9
+
8
10
  exit false unless configured? %w(docker_repo docker_image docker_tag)
9
11
 
10
12
  docker_socket_start
@@ -18,6 +20,8 @@ module DockerContainerModule
18
20
  def docker_container_daemon
19
21
  log.debug 'Starting docker container as daemon'
20
22
 
23
+ exit false unless docker_check_running
24
+
21
25
  exit false unless configured? %w(docker_repo docker_image docker_tag)
22
26
 
23
27
  _create_network @hostname unless docker_container_check_network @hostname
@@ -28,6 +32,8 @@ module DockerContainerModule
28
32
  def docker_container_login
29
33
  log.debug 'Logging in to docker container'
30
34
 
35
+ exit false unless docker_check_running
36
+
31
37
  exit false unless configured? %w(docker_repo docker_image docker_tag)
32
38
 
33
39
  docker_socket_start
@@ -41,6 +47,8 @@ module DockerContainerModule
41
47
  def docker_container_nuke
42
48
  log.debug 'Removing all docker containers'
43
49
 
50
+ exit false unless docker_check_running
51
+
44
52
  exit false unless configured? %w(docker_image)
45
53
 
46
54
  networks = []
@@ -60,6 +68,8 @@ module DockerContainerModule
60
68
  def docker_container_purge
61
69
  log.debug 'Removing orphaned docker containers'
62
70
 
71
+ exit false unless docker_check_running
72
+
63
73
  exit false unless configured? %w(docker_image)
64
74
 
65
75
  networks = []
@@ -169,7 +179,7 @@ module DockerContainerModule
169
179
  "--filter id=#{container} " +
170
180
  '--format "{{.Names}}"'
171
181
 
172
- stdout_str, stderr_str, status = run_and_check cmd_get_container_name_by_id
182
+ stdout_str = run cmd_get_container_name_by_id
173
183
 
174
184
  name = stdout_str.chomp
175
185
 
@@ -188,7 +198,7 @@ module DockerContainerModule
188
198
  "--filter name=^#{@docker_image}_ " +
189
199
  '--quiet'
190
200
 
191
- stdout_str, stderr_str, status = run_and_check cmd_docker_get
201
+ stdout_str = run cmd_docker_get
192
202
 
193
203
  # convert stdout lines to array and return array
194
204
  stdout_str.split(/\n+/)
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckModule
9
10
  include DockerImageTagListModule
10
11
  include DockerImageTagLatestModule
11
12
  include DockerImageModule
@@ -3,14 +3,9 @@ module DockerImageModule
3
3
 
4
4
  # Backend method for docker image update.
5
5
  def docker_image_update
6
- exit false unless configured? %w(docker_repo docker_image docker_tagsurl)
7
-
8
- tag_latest_local = docker_image_tag_latest_local
6
+ exit false unless docker_check_running
9
7
 
10
- if tag_latest_local.to_s.strip.empty?
11
- log.error "Unable to get latest local tag"
12
- exit false
13
- end
8
+ exit false unless configured? %w(docker_repo docker_image docker_tagsurl)
14
9
 
15
10
  tag_latest_remote = docker_image_tag_latest_remote
16
11
 
@@ -19,9 +14,13 @@ module DockerImageModule
19
14
  exit false
20
15
  end
21
16
 
22
- if Gem::Version.new(tag_latest_local) >= Gem::Version.new(tag_latest_remote)
23
- log.info 'Already up to date.'
24
- exit
17
+ tag_latest_local = docker_image_tag_latest_local
18
+
19
+ unless tag_latest_local.to_s.strip.empty?
20
+ if Gem::Version.new(tag_latest_local) >= Gem::Version.new(tag_latest_remote)
21
+ log.info 'Already up to date.'
22
+ exit
23
+ end
25
24
  end
26
25
 
27
26
  cmd_docker_pull_latest = "docker pull #{@docker_repo}/#{@docker_image}:#{tag_latest_remote}"
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckModule
9
10
  include DockerImageTagListModule
10
11
  include DockerImageTagCheckModule
11
12
 
@@ -6,6 +6,8 @@ module DockerImageTagCheckModule
6
6
  def docker_image_tag_check_local(tag)
7
7
  log.debug "Check if local docker image tag \"#{tag}\" exists"
8
8
 
9
+ exit false unless docker_check_running
10
+
9
11
  exit false unless configured? %w(docker_repo docker_image)
10
12
 
11
13
  if tag.to_s.strip.empty?
@@ -18,7 +20,7 @@ module DockerImageTagCheckModule
18
20
  cmd_docker_images = 'docker images --quiet ' +
19
21
  image
20
22
 
21
- stdout_str, stderr_str, status = run_and_check cmd_docker_images
23
+ stdout_str = run cmd_docker_images
22
24
 
23
25
  if stdout_str.to_s.strip.empty?
24
26
  log.debug "No local docker image \"#{image}\" found"
@@ -34,6 +36,8 @@ module DockerImageTagCheckModule
34
36
  def docker_image_tag_check_remote(tag)
35
37
  log.debug "Check if remote image tag \"#{tag}\" exists"
36
38
 
39
+ exit false unless docker_check_running
40
+
37
41
  exit false unless configured? %w(docker_repo docker_image docker_tagsurl)
38
42
 
39
43
  if tag .to_s.strip.empty?
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckModule
9
10
  include DockerImageTagListModule
10
11
  include DockerImageTagLatestModule
11
12
 
@@ -6,6 +6,8 @@ module DockerImageTagLatestModule
6
6
  def docker_image_tag_latest_local
7
7
  log.debug "Getting latest local docker image tag"
8
8
 
9
+ exit false unless docker_check_running
10
+
9
11
  tags = docker_image_tag_list_local
10
12
 
11
13
  tag_latest_local = tags[-1]
@@ -20,8 +22,15 @@ module DockerImageTagLatestModule
20
22
  def docker_image_tag_latest_remote
21
23
  log.debug "Getting latest remote docker image tag"
22
24
 
25
+ exit false unless docker_check_running
26
+
23
27
  tags = docker_image_tag_list_remote
24
28
 
29
+ if tags.nil?
30
+ log.debug "No latest docker remote tag"
31
+ return ''
32
+ end
33
+
25
34
  tag_latest_remote = tags[-1]
26
35
 
27
36
  log.debug "Latest docker remote tag: #{tag_latest_remote}"
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include SystemModule
8
8
  include ConfigModule
9
+ include DockerCheckModule
9
10
  include DockerImageTagListModule
10
11
 
11
12
  # Initialize takelage docker image tag list
@@ -6,12 +6,13 @@ module DockerImageTagListModule
6
6
  def docker_image_tag_list_local
7
7
  tags = []
8
8
 
9
- cmd_docker_images = 'docker images'
10
- images = run cmd_docker_images
9
+ cmd_docker_images = 'docker images ' +
10
+ "#{@docker_repo}\/#{@docker_image} " +
11
+ ' --format "{{.Tag}}"'
11
12
 
12
- images.scan(/.*#{@docker_repo}\/#{@docker_image}.*/) do |line|
13
- tags << line.split(/\s+/)[1]
14
- end
13
+ stdout_str = run cmd_docker_images
14
+
15
+ tags = stdout_str.split("\n")
15
16
 
16
17
  tags.sort_by(&Gem::Version.method(:new))
17
18
  end
@@ -6,6 +6,7 @@ module Takelage
6
6
  include LoggingModule
7
7
  include ConfigModule
8
8
  include SystemModule
9
+ include DockerCheckModule
9
10
  include DockerSocketModule
10
11
 
11
12
  # Initialize docker socket
@@ -5,6 +5,8 @@ module DockerSocketModule
5
5
  def docker_socket_start
6
6
  log.debug 'Starting sockets for docker container'
7
7
 
8
+ exit false unless docker_check_running
9
+
8
10
  cmds_start_socket = _get_socket_start_commands sockets_up = false
9
11
 
10
12
  unless cmds_start_socket.empty?
@@ -24,11 +26,13 @@ module DockerSocketModule
24
26
  def docker_socket_stop
25
27
  log.debug 'Stopping sockets for docker container'
26
28
 
29
+ exit false unless docker_check_running
30
+
27
31
  cmd_ps = config.active['docker_socket_ps']
28
32
 
29
33
  # get process list
30
34
  # assuming format: "pid command"
31
- stdout_str, stderr_str, status = run_and_check cmd_ps
35
+ stdout_str = run cmd_ps
32
36
 
33
37
  cmds_start_socket = _get_socket_start_commands sockets_up = true
34
38
 
@@ -85,7 +89,7 @@ module DockerSocketModule
85
89
  # get socket paths
86
90
  def _get_socket_paths
87
91
  cmd_gpgconf_listdirs = config.active['docker_socket_gpgconf']
88
- stdout_str, stderr_str, status = run_and_check cmd_gpgconf_listdirs
92
+ stdout_str = run cmd_gpgconf_listdirs
89
93
 
90
94
  stdout_str.split(/\n+/).each do |gpg_path|
91
95
  @sockets.each do |socket, socket_config|
@@ -12,9 +12,9 @@ module GitCheckModule
12
12
  cmd_git_uncommitted = config.active['git_uncommitted']
13
13
  cmd_git_status = config.active['git_status']
14
14
 
15
- stdout_str, stderr_str, status_unstaged = run_and_check cmd_git_unstaged
16
- stdout_str, stderr_str, status_uncommitted = run_and_check cmd_git_uncommitted
17
- stdout_str_status, stderr_str, status = run_and_check cmd_git_status
15
+ status_unstaged = try cmd_git_unstaged
16
+ status_uncommitted = try cmd_git_uncommitted
17
+ stdout_str_status = run cmd_git_status
18
18
 
19
19
  # only return true if neither unstaged nor uncommitted nor empty files
20
20
  sum = status_unstaged.exitstatus +
@@ -32,7 +32,7 @@ module GitCheckModule
32
32
  return false unless git_check_workspace
33
33
 
34
34
  cmd_get_branch = config.active['git_branch']
35
- stdout_str, stderr_str, status = run_and_check cmd_get_branch
35
+ stdout_str = run cmd_get_branch
36
36
 
37
37
  branch = stdout_str.strip.split('/')[-1]
38
38
 
@@ -47,10 +47,10 @@ module GitCheckModule
47
47
  log.debug 'Check if this is a git workspace'
48
48
 
49
49
  cmd_git_repo = config.active['git_repo']
50
- stdout_str_repo, stderr_str_repo, status_repo = run_and_check cmd_git_repo
50
+ status_repo = try cmd_git_repo
51
51
 
52
52
  cmd_pwd = config.active['pwd']
53
- stdout_str_dir, stderr_str_dir, status_dir = run_and_check cmd_pwd
53
+ stdout_str_dir = run cmd_pwd
54
54
 
55
55
  dir = stdout_str_dir.strip
56
56
 
@@ -6,14 +6,6 @@ require 'yaml'
6
6
  # Interaction with the operating system
7
7
  module SystemModule
8
8
 
9
- # Run a command and return the result.
10
- # @return [Boolean] success of command run
11
- def run_and_check(command)
12
- log.debug "Running command \"#{command}\""
13
- stdout_str, stderr_str, status = Open3.capture3 command
14
- return stdout_str, stderr_str, status
15
- end
16
-
17
9
  # Print hash as yaml.
18
10
  def hash_to_yaml(hash)
19
11
  if hash == {}
@@ -62,30 +54,12 @@ module SystemModule
62
54
  Pathname.new(directory).rmtree
63
55
  end
64
56
 
65
- # Run a command.
57
+ # Run a command and return the standard output.
66
58
  # @return [String] stdout of command
67
59
  def run(command, realtime=false)
68
60
  log.debug "Running command \"#{command}\""
69
- stdout_str = ''
70
- stderr_str = ''
71
- status = ''
72
- exitstatus = -1
73
- Open3.popen3 command do |stdin, stdout, stderr, thread|
74
- stdout.each do |line|
75
- say line if realtime
76
- stdout_str += line
77
- end
78
- stderr_str = stderr
79
- status = thread.value
80
- exitstatus = thread.value.exitstatus
81
- end
82
- unless status.success?
83
- log.error "Command \"#{command}\" failed!"
84
- log.debug "status: #{status}"
85
- log.debug "stdout: #{stdout_str}"
86
- log.debug "stderr: #{stderr_str}"
87
- exit exitstatus
88
- end
61
+ stdout_str, stderr_str, status = Open3.capture3 command
62
+ log.debug "Command \"#{command}\" has stdout:\"\n#{stdout_str}\""
89
63
  stdout_str
90
64
  end
91
65
 
@@ -104,4 +78,12 @@ module SystemModule
104
78
  Process.detach(job)
105
79
  end
106
80
 
81
+ # Run a command and return the result.
82
+ # @return [Boolean] success of command run
83
+ def try(command)
84
+ log.debug "Running command \"#{command}\""
85
+ stdout_str, stderr_str, status = Open3.capture3 command
86
+ log.debug "Command \"#{command}\" has exit status \"#{status.exitstatus}\""
87
+ status
88
+ end
107
89
  end
data/lib/takelage/version CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.5.0
data/lib/takelage.rb CHANGED
@@ -27,6 +27,8 @@ require_relative 'takelage/bit/clipboard/module'
27
27
  require_relative 'takelage/bit/clipboard/cli'
28
28
  require_relative 'takelage/bit/cli'
29
29
  require_relative 'takelage/completion/cli'
30
+ require_relative 'takelage/docker/check/module'
31
+ require_relative 'takelage/docker/check/cli'
30
32
  require_relative 'takelage/docker/socket/module'
31
33
  require_relative 'takelage/docker/socket/cli'
32
34
  require_relative 'takelage/docker/image/tag/list/module'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takelage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geospin
@@ -186,6 +186,8 @@ files:
186
186
  - lib/takelage/bit/scope/module.rb
187
187
  - lib/takelage/completion/cli.rb
188
188
  - lib/takelage/default.yml
189
+ - lib/takelage/docker/check/cli.rb
190
+ - lib/takelage/docker/check/module.rb
189
191
  - lib/takelage/docker/cli.rb
190
192
  - lib/takelage/docker/container/check/cli.rb
191
193
  - lib/takelage/docker/container/check/module.rb