takeltau 0.34.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +674 -0
  3. data/README.md +235 -0
  4. data/bin/tau +6 -0
  5. data/lib/Thorfile +3 -0
  6. data/lib/takeltau.rb +257 -0
  7. data/lib/takeltau/bit/check/cli.rb +23 -0
  8. data/lib/takeltau/bit/check/workspace.rb +37 -0
  9. data/lib/takeltau/bit/cli.rb +18 -0
  10. data/lib/takeltau/bit/clipboard/cli.rb +73 -0
  11. data/lib/takeltau/bit/clipboard/copy.rb +142 -0
  12. data/lib/takeltau/bit/clipboard/lib.rb +143 -0
  13. data/lib/takeltau/bit/clipboard/paste.rb +60 -0
  14. data/lib/takeltau/bit/clipboard/pull.rb +37 -0
  15. data/lib/takeltau/bit/clipboard/push.rb +37 -0
  16. data/lib/takeltau/bit/require/cli.rb +57 -0
  17. data/lib/takeltau/bit/require/export.rb +34 -0
  18. data/lib/takeltau/bit/require/import.rb +133 -0
  19. data/lib/takeltau/bit/require/lib.rb +19 -0
  20. data/lib/takeltau/bit/scope/add.rb +55 -0
  21. data/lib/takeltau/bit/scope/cli.rb +74 -0
  22. data/lib/takeltau/bit/scope/list.rb +41 -0
  23. data/lib/takeltau/bit/scope/new.rb +44 -0
  24. data/lib/takeltau/bit/scope/ssh.rb +13 -0
  25. data/lib/takeltau/completion/cli.rb +24 -0
  26. data/lib/takeltau/default.yml +95 -0
  27. data/lib/takeltau/docker/check/cli.rb +23 -0
  28. data/lib/takeltau/docker/check/daemon.rb +27 -0
  29. data/lib/takeltau/docker/cli.rb +15 -0
  30. data/lib/takeltau/docker/container/check/cli.rb +57 -0
  31. data/lib/takeltau/docker/container/check/existing.rb +32 -0
  32. data/lib/takeltau/docker/container/check/network.rb +32 -0
  33. data/lib/takeltau/docker/container/check/orphaned.rb +32 -0
  34. data/lib/takeltau/docker/container/clean.rb +40 -0
  35. data/lib/takeltau/docker/container/cli.rb +118 -0
  36. data/lib/takeltau/docker/container/command.rb +38 -0
  37. data/lib/takeltau/docker/container/daemon.rb +17 -0
  38. data/lib/takeltau/docker/container/lib.rb +181 -0
  39. data/lib/takeltau/docker/container/login.rb +58 -0
  40. data/lib/takeltau/docker/container/prune.rb +31 -0
  41. data/lib/takeltau/docker/image/cli.rb +39 -0
  42. data/lib/takeltau/docker/image/tag/check.rb +42 -0
  43. data/lib/takeltau/docker/image/tag/cli.rb +68 -0
  44. data/lib/takeltau/docker/image/tag/latest.rb +24 -0
  45. data/lib/takeltau/docker/image/tag/list.rb +19 -0
  46. data/lib/takeltau/docker/image/update.rb +27 -0
  47. data/lib/takeltau/git/check/bit.rb +26 -0
  48. data/lib/takeltau/git/check/clean.rb +46 -0
  49. data/lib/takeltau/git/check/cli.rb +49 -0
  50. data/lib/takeltau/git/check/workspace.rb +34 -0
  51. data/lib/takeltau/git/cli.rb +9 -0
  52. data/lib/takeltau/info/cli.rb +12 -0
  53. data/lib/takeltau/info/project/cli.rb +69 -0
  54. data/lib/takeltau/info/status/bar.rb +112 -0
  55. data/lib/takeltau/info/status/cli.rb +107 -0
  56. data/lib/takeltau/info/status/git.rb +47 -0
  57. data/lib/takeltau/info/status/gopass.rb +37 -0
  58. data/lib/takeltau/info/status/gpg.rb +39 -0
  59. data/lib/takeltau/info/status/lib.rb +46 -0
  60. data/lib/takeltau/info/status/ssh.rb +46 -0
  61. data/lib/takeltau/init/cli.rb +12 -0
  62. data/lib/takeltau/init/lib.rb +86 -0
  63. data/lib/takeltau/init/packer/cli.rb +82 -0
  64. data/lib/takeltau/init/packer/docker.rb +64 -0
  65. data/lib/takeltau/init/packer/templates/ansiblelint.tt +3 -0
  66. data/lib/takeltau/init/packer/templates/bitrequireyml.tt +13 -0
  67. data/lib/takeltau/init/packer/templates/groupvarsprojectyml.tt +2 -0
  68. data/lib/takeltau/init/packer/templates/playbooksiteyml.tt +6 -0
  69. data/lib/takeltau/init/packer/templates/projectyml.tt +19 -0
  70. data/lib/takeltau/init/takelage/cli.rb +70 -0
  71. data/lib/takeltau/init/takelage/rake.rb +61 -0
  72. data/lib/takeltau/init/takelage/templates/bitrequireyml.tt +5 -0
  73. data/lib/takeltau/init/takelage/templates/projectyml.tt +3 -0
  74. data/lib/takeltau/init/templates/Rakefile.tt +3 -0
  75. data/lib/takeltau/init/templates/gitignore.tt +16 -0
  76. data/lib/takeltau/lib/config.rb +130 -0
  77. data/lib/takeltau/lib/logging.rb +49 -0
  78. data/lib/takeltau/lib/project.rb +72 -0
  79. data/lib/takeltau/lib/subcmd.rb +18 -0
  80. data/lib/takeltau/lib/system.rb +194 -0
  81. data/lib/takeltau/mutagen/check/cli.rb +40 -0
  82. data/lib/takeltau/mutagen/check/daemon.rb +76 -0
  83. data/lib/takeltau/mutagen/cli.rb +12 -0
  84. data/lib/takeltau/mutagen/socket/check.rb +33 -0
  85. data/lib/takeltau/mutagen/socket/cli.rb +103 -0
  86. data/lib/takeltau/mutagen/socket/create.rb +47 -0
  87. data/lib/takeltau/mutagen/socket/list.rb +33 -0
  88. data/lib/takeltau/mutagen/socket/terminate.rb +32 -0
  89. data/lib/takeltau/mutagen/socket/tidy.rb +21 -0
  90. data/lib/takeltau/self/cli.rb +43 -0
  91. data/lib/takeltau/self/config/cli.rb +82 -0
  92. data/lib/takeltau/self/list.rb +35 -0
  93. data/lib/takeltau/version +1 -0
  94. metadata +319 -0
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau docker container prune
4
+ module DockerContainerPrune
5
+ # Backend method for docker container prune.
6
+ def docker_container_prune
7
+ log.debug 'Removing orphaned docker containers'
8
+
9
+ return false unless docker_check_daemon
10
+
11
+ networks = _docker_container_prune_kill_orphaned_containers
12
+ _docker_container_lib_remove_networks networks
13
+ end
14
+
15
+ private
16
+
17
+ # Kill orphaned docker containers and return list of networks.
18
+ def _docker_container_prune_kill_orphaned_containers
19
+ networks = []
20
+
21
+ _docker_container_lib_get_containers.each do |container|
22
+ next unless docker_container_check_orphaned container
23
+
24
+ name = _docker_container_lib_get_container_name_by_id container
25
+ mutagen_socket_terminate "--label-selector='hostname=#{name}'"
26
+ _docker_container_lib_stop_container container
27
+ networks << name unless networks.include? name
28
+ end
29
+ networks
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Takeltau
4
+ # takeltau docker image
5
+ class DockerImage < SubCommandBase
6
+ include LoggingModule
7
+ include SystemModule
8
+ include ConfigModule
9
+ include DockerCheckDaemon
10
+ include DockerImageUpdate
11
+
12
+ # Initialize takelage docker image
13
+ def initialize(args = [], local_options = {}, configuration = {})
14
+ # initialize thor parent class
15
+ super args, local_options, configuration
16
+
17
+ @docker_user = config.active['docker_user']
18
+ @docker_repo = config.active['docker_repo']
19
+ @docker_registry = config.active['docker_registry']
20
+ end
21
+
22
+ desc 'tag [COMMAND]', 'Handle docker image tags'
23
+ subcommand 'tag', DockerImageTag
24
+
25
+ #
26
+ # docker image update
27
+ #
28
+ desc 'update', 'Get latest remote docker container'
29
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
30
+ Get latest remote docker container
31
+ This command will download the latest remote version of the takelage docker container.
32
+ When you start the environment the latest locally available container will be used.
33
+ LONGDESC
34
+ # Get latest remote docker container.
35
+ def update
36
+ exit docker_image_update
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau docker image tag check
4
+ module DockerImageTagCheck
5
+ # Backend method for docker image tag check.
6
+ # @return [Boolean] does docker image tag exist?
7
+ def docker_image_tag_check(tag)
8
+ log.debug "Check if docker image tag \"#{tag}\" exists"
9
+
10
+ return false unless docker_check_daemon
11
+
12
+ if tag.to_s.chomp.empty?
13
+ log.warn 'No docker image tag specified'
14
+ return false
15
+ end
16
+
17
+ image = "#{@docker_user}/#{@docker_repo}:#{tag}"
18
+
19
+ return false unless _docker_image_check_image? image
20
+
21
+ log.debug "Found docker image \"#{image}\""
22
+ true
23
+ end
24
+
25
+ private
26
+
27
+ # Check if image exists.
28
+ def _docker_image_check_image?(image)
29
+ cmd_docker_images =
30
+ format(
31
+ config.active['cmd_docker_image_tag_check_docker_images'],
32
+ image: image
33
+ )
34
+
35
+ if (run cmd_docker_images).to_s.chomp.empty?
36
+ log.debug "No docker image \"#{image}\" found"
37
+ return false
38
+ end
39
+
40
+ true
41
+ end
42
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Takeltau
4
+ # takeltau docker image tag
5
+ class DockerImageTag < SubCommandBase
6
+ include LoggingModule
7
+ include SystemModule
8
+ include ConfigModule
9
+ include DockerCheckDaemon
10
+ include DockerImageTagList
11
+ include DockerImageTagList
12
+ include DockerImageTagLatest
13
+ include DockerImageTagCheck
14
+
15
+ # Initialize takelage docker image tag check
16
+ def initialize(args = [], local_options = {}, configuration = {})
17
+ # initialize thor parent class
18
+ super args, local_options, configuration
19
+
20
+ @docker_user = config.active['docker_user']
21
+ @docker_repo = config.active['docker_repo']
22
+ @docker_registry = config.active['docker_registry']
23
+ end
24
+
25
+ #
26
+ # docker image tag check
27
+ #
28
+ desc 'check [TAG]', 'Check if docker image [TAG] exists'
29
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
30
+ Check if docker image tag exists
31
+ LONGDESC
32
+ # Check if docker image tag exists.
33
+ def check(tag)
34
+ exit docker_image_tag_check tag
35
+ end
36
+
37
+ #
38
+ # docker image tag latest
39
+ #
40
+ desc 'latest', 'Print latest docker image tag'
41
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
42
+ Print latest docker image tag
43
+ Print the tag of the docker image with the highest tag.
44
+ LONGDESC
45
+ # Print latest docker image tag.
46
+ def latest
47
+ tag_latest = docker_image_tag_latest
48
+ exit false if tag_latest == false
49
+ say tag_latest
50
+ true
51
+ end
52
+
53
+ #
54
+ # docker image tag list
55
+ #
56
+ desc 'list', 'Print docker image tags'
57
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
58
+ Print docker image tags
59
+ LONGDESC
60
+ # Print docker image tags.
61
+ def list
62
+ tag_list = docker_image_tag_list
63
+ exit false if tag_list == false
64
+ say tag_list
65
+ true
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau docker image tag latest
4
+ module DockerImageTagLatest
5
+ # Backend method for docker image tag latest.
6
+ # @return [String] latest docker image tag
7
+ def docker_image_tag_latest
8
+ log.debug 'Getting latest docker image tag'
9
+
10
+ return false unless docker_check_daemon
11
+
12
+ tags = docker_image_tag_list
13
+
14
+ tag_latest = if tags.include? 'latest'
15
+ 'latest'
16
+ else
17
+ tags[-1]
18
+ end
19
+
20
+ log.debug "Latest docker tag: #{tag_latest}"
21
+
22
+ tag_latest
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau docker image tag list
4
+ module DockerImageTagList
5
+ # Backend method for docker image tag list.
6
+ # @return [Array] docker image tags
7
+ def docker_image_tag_list
8
+ cmd_docker_tags =
9
+ format(
10
+ config.active['cmd_docker_image_tag_list_docker_images'],
11
+ docker_user: @docker_user,
12
+ docker_repo: @docker_repo
13
+ )
14
+
15
+ tags = (run cmd_docker_tags).split("\n")
16
+
17
+ VersionSorter.sort(tags)
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau docker image uppdate
4
+ module DockerImageUpdate
5
+ # Backend method for docker image update.
6
+ def docker_image_update
7
+ return false unless docker_check_daemon
8
+
9
+ cmd_docker_pull_latest = _docker_image_update_cmd_docker_pull_latest
10
+
11
+ cmd_docker_remove_dangling =
12
+ config.active['cmd_docker_image_update_docker_remove_dangling']
13
+
14
+ run_and_exit "#{cmd_docker_pull_latest} && #{cmd_docker_remove_dangling}"
15
+ end
16
+
17
+ private
18
+
19
+ # Prepare dpcker pull latest command.
20
+ def _docker_image_update_cmd_docker_pull_latest
21
+ format(
22
+ config.active['cmd_docker_image_update_docker_pull_latest'],
23
+ docker_user: @docker_user,
24
+ docker_repo: @docker_repo
25
+ )
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau git check bit
4
+ module GitCheckBit
5
+ # Backend method for git check bit.
6
+ # @return [Boolean] are we on the git bit branch?
7
+ def git_check_bit
8
+ log.debug 'Check if we are on the git bit branch'
9
+
10
+ return false unless git_check_workspace
11
+
12
+ branch = _git_check_bit_get_branch
13
+ log.debug "We are on git branch \"#{branch}\""
14
+
15
+ branch == config.active['git_bit_branch']
16
+ end
17
+
18
+ private
19
+
20
+ # Get git branch.
21
+ def _git_check_bit_get_branch
22
+ cmd_get_branch =
23
+ config.active['cmd_git_check_bit_get_git_branch']
24
+ (run cmd_get_branch).chomp.split('/')[-1]
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau git check clean
4
+ module GitCheckClean
5
+ # Backend method for git check clean.
6
+ # @return [Boolean] is git workspace clean?
7
+ def git_check_clean
8
+ log.debug 'Checking if git workspace is clean'
9
+
10
+ return false unless git_check_workspace
11
+
12
+ status_unstaged = _git_check_clean_get_status_unstaged
13
+ status_uncommitted = _git_check_clean_get_status_uncommitted
14
+ stdout_str_status = _git_check_clean_get_str_status
15
+
16
+ # only return true if neither unstaged nor uncommitted nor empty files
17
+ sum = status_unstaged.exitstatus +
18
+ status_uncommitted.exitstatus +
19
+ stdout_str_status.length
20
+
21
+ sum.zero?
22
+ end
23
+
24
+ private
25
+
26
+ # Get git status of unstaged changes.
27
+ def _git_check_clean_get_status_unstaged
28
+ cmd_git_unstaged =
29
+ config.active['cmd_git_check_clean_git_unstaged']
30
+ try cmd_git_unstaged
31
+ end
32
+
33
+ # Get git status of uncommitted changes.
34
+ def _git_check_clean_get_status_uncommitted
35
+ cmd_git_uncommitted =
36
+ config.active['cmd_git_check_clean_git_uncommitted']
37
+ try cmd_git_uncommitted
38
+ end
39
+
40
+ # Get git status result.
41
+ def _git_check_clean_get_str_status
42
+ cmd_git_status =
43
+ config.active['cmd_git_check_clean_git_status']
44
+ run cmd_git_status
45
+ end
46
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Takeltau
4
+ # takeltau git check
5
+ class GitCheck < SubCommandBase
6
+ include LoggingModule
7
+ include SystemModule
8
+ include ConfigModule
9
+ include GitCheckClean
10
+ include GitCheckBit
11
+ include GitCheckWorkspace
12
+
13
+ #
14
+ # git check bit
15
+ #
16
+ desc 'bit', 'Check if we are on the git bit branch'
17
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
18
+ Check if we are on the git bit branch
19
+ LONGDESC
20
+ # Check if we are on the git bit branch.
21
+ def bit
22
+ exit git_check_bit
23
+ end
24
+
25
+ #
26
+ # git check clean
27
+ #
28
+ desc 'clean', 'Check if the git workspace is clean'
29
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
30
+ Check if the git workspace is clean
31
+ LONGDESC
32
+ # Check if the git workspace is clean.
33
+ def clean
34
+ exit git_check_clean
35
+ end
36
+
37
+ #
38
+ # git check workspace
39
+ #
40
+ desc 'workspace', 'Check if a git workspace exists'
41
+ long_desc <<-LONGDESC.gsub("\n", "\x5")
42
+ Check if a git workspace exists
43
+ LONGDESC
44
+ # Check if a git workspace exists.
45
+ def workspace
46
+ exit git_check_workspace
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # takeltau git check workspace
4
+ module GitCheckWorkspace
5
+ # Backend method for git check workspace.
6
+ # @return [Boolean] is this a git workspace?
7
+ def git_check_workspace(dir = _git_check_workspace_get_dir)
8
+ log.debug "Check if \"#{dir}\" is a git workspace"
9
+ status_repo = _git_check_workspace_get_status_repo(dir)
10
+ unless status_repo.exitstatus.zero?
11
+ log.debug "No git workspace found in \"#{dir}\""
12
+ return false
13
+ end
14
+ true
15
+ end
16
+
17
+ private
18
+
19
+ # Get git repository status.
20
+ def _git_check_workspace_get_status_repo(dir)
21
+ cmd_git_repo = format(
22
+ config.active['cmd_git_check_workspace_git_repo'],
23
+ dir: dir
24
+ )
25
+ try cmd_git_repo
26
+ end
27
+
28
+ # Get current working directory.
29
+ def _git_check_workspace_get_dir
30
+ cmd_pwd =
31
+ config.active['cmd_git_check_workspace_pwd']
32
+ (run cmd_pwd).chomp
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Takeltau
4
+ # takeltau git
5
+ class Git < SubCommandBase
6
+ desc 'check [COMMAND]', 'Check git state'
7
+ subcommand 'check', GitCheck
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Takeltau
4
+ # takeltau info
5
+ class Info < SubCommandBase
6
+ desc 'project [COMMAND]', 'Get project info'
7
+ subcommand 'project', InfoProject
8
+
9
+ desc 'status [COMMAND]', 'Get status info'
10
+ subcommand 'status', InfoStatus
11
+ end
12
+ end