takeltau 0.34.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +674 -0
- data/README.md +235 -0
- data/bin/tau +6 -0
- data/lib/Thorfile +3 -0
- data/lib/takeltau.rb +257 -0
- data/lib/takeltau/bit/check/cli.rb +23 -0
- data/lib/takeltau/bit/check/workspace.rb +37 -0
- data/lib/takeltau/bit/cli.rb +18 -0
- data/lib/takeltau/bit/clipboard/cli.rb +73 -0
- data/lib/takeltau/bit/clipboard/copy.rb +142 -0
- data/lib/takeltau/bit/clipboard/lib.rb +143 -0
- data/lib/takeltau/bit/clipboard/paste.rb +60 -0
- data/lib/takeltau/bit/clipboard/pull.rb +37 -0
- data/lib/takeltau/bit/clipboard/push.rb +37 -0
- data/lib/takeltau/bit/require/cli.rb +57 -0
- data/lib/takeltau/bit/require/export.rb +34 -0
- data/lib/takeltau/bit/require/import.rb +133 -0
- data/lib/takeltau/bit/require/lib.rb +19 -0
- data/lib/takeltau/bit/scope/add.rb +55 -0
- data/lib/takeltau/bit/scope/cli.rb +74 -0
- data/lib/takeltau/bit/scope/list.rb +41 -0
- data/lib/takeltau/bit/scope/new.rb +44 -0
- data/lib/takeltau/bit/scope/ssh.rb +13 -0
- data/lib/takeltau/completion/cli.rb +24 -0
- data/lib/takeltau/default.yml +95 -0
- data/lib/takeltau/docker/check/cli.rb +23 -0
- data/lib/takeltau/docker/check/daemon.rb +27 -0
- data/lib/takeltau/docker/cli.rb +15 -0
- data/lib/takeltau/docker/container/check/cli.rb +57 -0
- data/lib/takeltau/docker/container/check/existing.rb +32 -0
- data/lib/takeltau/docker/container/check/network.rb +32 -0
- data/lib/takeltau/docker/container/check/orphaned.rb +32 -0
- data/lib/takeltau/docker/container/clean.rb +40 -0
- data/lib/takeltau/docker/container/cli.rb +118 -0
- data/lib/takeltau/docker/container/command.rb +38 -0
- data/lib/takeltau/docker/container/daemon.rb +17 -0
- data/lib/takeltau/docker/container/lib.rb +181 -0
- data/lib/takeltau/docker/container/login.rb +58 -0
- data/lib/takeltau/docker/container/prune.rb +31 -0
- data/lib/takeltau/docker/image/cli.rb +39 -0
- data/lib/takeltau/docker/image/tag/check.rb +42 -0
- data/lib/takeltau/docker/image/tag/cli.rb +68 -0
- data/lib/takeltau/docker/image/tag/latest.rb +24 -0
- data/lib/takeltau/docker/image/tag/list.rb +19 -0
- data/lib/takeltau/docker/image/update.rb +27 -0
- data/lib/takeltau/git/check/bit.rb +26 -0
- data/lib/takeltau/git/check/clean.rb +46 -0
- data/lib/takeltau/git/check/cli.rb +49 -0
- data/lib/takeltau/git/check/workspace.rb +34 -0
- data/lib/takeltau/git/cli.rb +9 -0
- data/lib/takeltau/info/cli.rb +12 -0
- data/lib/takeltau/info/project/cli.rb +69 -0
- data/lib/takeltau/info/status/bar.rb +112 -0
- data/lib/takeltau/info/status/cli.rb +107 -0
- data/lib/takeltau/info/status/git.rb +47 -0
- data/lib/takeltau/info/status/gopass.rb +37 -0
- data/lib/takeltau/info/status/gpg.rb +39 -0
- data/lib/takeltau/info/status/lib.rb +46 -0
- data/lib/takeltau/info/status/ssh.rb +46 -0
- data/lib/takeltau/init/cli.rb +12 -0
- data/lib/takeltau/init/lib.rb +86 -0
- data/lib/takeltau/init/packer/cli.rb +82 -0
- data/lib/takeltau/init/packer/docker.rb +64 -0
- data/lib/takeltau/init/packer/templates/ansiblelint.tt +3 -0
- data/lib/takeltau/init/packer/templates/bitrequireyml.tt +13 -0
- data/lib/takeltau/init/packer/templates/groupvarsprojectyml.tt +2 -0
- data/lib/takeltau/init/packer/templates/playbooksiteyml.tt +6 -0
- data/lib/takeltau/init/packer/templates/projectyml.tt +19 -0
- data/lib/takeltau/init/takelage/cli.rb +70 -0
- data/lib/takeltau/init/takelage/rake.rb +61 -0
- data/lib/takeltau/init/takelage/templates/bitrequireyml.tt +5 -0
- data/lib/takeltau/init/takelage/templates/projectyml.tt +3 -0
- data/lib/takeltau/init/templates/Rakefile.tt +3 -0
- data/lib/takeltau/init/templates/gitignore.tt +16 -0
- data/lib/takeltau/lib/config.rb +130 -0
- data/lib/takeltau/lib/logging.rb +49 -0
- data/lib/takeltau/lib/project.rb +72 -0
- data/lib/takeltau/lib/subcmd.rb +18 -0
- data/lib/takeltau/lib/system.rb +194 -0
- data/lib/takeltau/mutagen/check/cli.rb +40 -0
- data/lib/takeltau/mutagen/check/daemon.rb +76 -0
- data/lib/takeltau/mutagen/cli.rb +12 -0
- data/lib/takeltau/mutagen/socket/check.rb +33 -0
- data/lib/takeltau/mutagen/socket/cli.rb +103 -0
- data/lib/takeltau/mutagen/socket/create.rb +47 -0
- data/lib/takeltau/mutagen/socket/list.rb +33 -0
- data/lib/takeltau/mutagen/socket/terminate.rb +32 -0
- data/lib/takeltau/mutagen/socket/tidy.rb +21 -0
- data/lib/takeltau/self/cli.rb +43 -0
- data/lib/takeltau/self/config/cli.rb +82 -0
- data/lib/takeltau/self/list.rb +35 -0
- data/lib/takeltau/version +1 -0
- metadata +319 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau bit scope list
|
4
|
+
module BitScopeList
|
5
|
+
# Backend method for bit scope list.
|
6
|
+
# @return [String] list of bit scopes
|
7
|
+
def bit_scope_list
|
8
|
+
log.debug 'Listing bit remote scopes'
|
9
|
+
|
10
|
+
return false unless configured? %w[bit_ssh bit_remote]
|
11
|
+
|
12
|
+
# get ssh command from active config.
|
13
|
+
cmd_bit_ssh =
|
14
|
+
config.active['bit_ssh']
|
15
|
+
|
16
|
+
root = config.active['bit_root']
|
17
|
+
|
18
|
+
cmd_bit_scope_list = _bit_scope_list_cmd root
|
19
|
+
|
20
|
+
# run ssh command with scope list command.
|
21
|
+
scope_list = run "#{cmd_bit_ssh} '#{cmd_bit_scope_list}'"
|
22
|
+
|
23
|
+
# remove bit remote root directory from results
|
24
|
+
scope_list.gsub!(%r{#{root}/*}, '')
|
25
|
+
|
26
|
+
# remove /scope.json from results
|
27
|
+
scope_list.gsub!(%r{/scope.json}, '')
|
28
|
+
|
29
|
+
scope_list
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Prepare bit scope list command.
|
35
|
+
def _bit_scope_list_cmd(root)
|
36
|
+
format(
|
37
|
+
config.active['cmd_bit_scope_list_find_scopes'],
|
38
|
+
root: root
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau bit scope new
|
4
|
+
module BitScopeNew
|
5
|
+
# Backend method for bit scope new.
|
6
|
+
# @return [Int] status of new command
|
7
|
+
def bit_scope_new(scope)
|
8
|
+
log.debug "Creating new bit remote scope \"#{scope}\""
|
9
|
+
|
10
|
+
return false unless configured? %w[bit_ssh bit_remote]
|
11
|
+
|
12
|
+
return false if _bit_scope_new_scope_exists? scope
|
13
|
+
|
14
|
+
cmd_bit_ssh = config.active['bit_ssh']
|
15
|
+
|
16
|
+
cmd_bit_scope_new = _bit_scope_new_cmd scope
|
17
|
+
|
18
|
+
run "#{cmd_bit_ssh} '#{cmd_bit_scope_new}'"
|
19
|
+
|
20
|
+
log.info "Created new bit remote scope \"#{scope}\""
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Check if bit scope already exists.
|
26
|
+
def _bit_scope_new_scope_exists?(scope)
|
27
|
+
scope_list = bit_scope_list
|
28
|
+
return false unless scope_list.include? scope
|
29
|
+
|
30
|
+
log.error "The remote bit scope \"#{scope}\" already exists"
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
# Prepare bit scope new command.
|
35
|
+
def _bit_scope_new_cmd(scope)
|
36
|
+
root = config.active['bit_root']
|
37
|
+
|
38
|
+
format(
|
39
|
+
config.active['cmd_bit_scope_new_bit_init'],
|
40
|
+
scope: scope,
|
41
|
+
root: root
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau bit scope ssh
|
4
|
+
module BitScopeSSH
|
5
|
+
# Backend method for bit scope ssh.
|
6
|
+
def bit_scope_ssh
|
7
|
+
log.debug 'Logging in to bit remote server'
|
8
|
+
|
9
|
+
return false unless configured? %w[bit_ssh]
|
10
|
+
|
11
|
+
run_and_exit config.active['bit_ssh']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Takeltau
|
4
|
+
# takeltau completion
|
5
|
+
class Completion < SubCommandBase
|
6
|
+
include LoggingModule
|
7
|
+
|
8
|
+
desc 'bash', 'Print bash completion code'
|
9
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
10
|
+
Print bash completion code
|
11
|
+
This command will print bash code which can be parsed to enable auto-completion for the takelage cli.
|
12
|
+
Add this to your bash startup files:
|
13
|
+
|
14
|
+
source <(tau completion bash)
|
15
|
+
LONGDESC
|
16
|
+
# Print bash completion code.
|
17
|
+
def bash
|
18
|
+
completion_bash = Takeltau::CLI.new.bash_fylla
|
19
|
+
exit false if completion_bash == false
|
20
|
+
say completion_bash
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
---
|
2
|
+
bit_dev_user: 'takelage'
|
3
|
+
bit_remote: ''
|
4
|
+
bit_require_file: 'bitrequire.yml'
|
5
|
+
bit_root: '/bit'
|
6
|
+
bit_ssh: ''
|
7
|
+
cmd_bit: 'bit'
|
8
|
+
cmd_bit_check_workspace_bit_list: 'bit status'
|
9
|
+
cmd_bit_check_workspace_pwd: 'pwd'
|
10
|
+
cmd_bit_clipboard_lib_bit_status: 'bit status'
|
11
|
+
cmd_bit_clipboard_copy_bit_list_scope: 'bit list --skip-update --json %{scope}'
|
12
|
+
cmd_bit_clipboard_copy_bit_list_remotes: 'bit remote --skip-update'
|
13
|
+
cmd_bit_clipboard_copy_bit_add_dir: 'bit add --skip-update --id %{id} --main %{dir}/README.bit %{dir}'
|
14
|
+
cmd_bit_clipboard_copy_bit_tag_id: 'bit tag --skip-update --skip-tests %{id}'
|
15
|
+
cmd_bit_clipboard_copy_bit_export_to_scope: 'bit export --skip-update %{scope}'
|
16
|
+
cmd_bit_clipboard_git_add: 'git add %{file}'
|
17
|
+
cmd_bit_clipboard_git_commit: 'git commit --message="%{message}"'
|
18
|
+
cmd_bit_clipboard_git_pull: 'git pull origin %{main}'
|
19
|
+
cmd_bit_clipboard_git_push: 'git push origin %{main}'
|
20
|
+
cmd_bit_clipboard_paste_bit_list_scope: 'bit list --skip-update --json %{scope}'
|
21
|
+
cmd_bit_clipboard_paste_bit_import_cid: 'bit import --ignore-package-json --ignore-dist --skip-update --path %{dir} %{cid}'
|
22
|
+
cmd_bit_clipboard_pull_bit_import_all: 'bit import --ignore-package-json --ignore-dist --skip-update'
|
23
|
+
cmd_bit_clipboard_pull_bit_checkout_all: 'bit checkout --ignore-package-json --ignore-dist --skip-update --skip-npm-install --all latest'
|
24
|
+
cmd_bit_clipboard_push_bit_tag_all: 'bit tag --skip-update --skip-tests --all'
|
25
|
+
cmd_bit_clipboard_push_bit_export_all: 'bit export --skip-update --all'
|
26
|
+
cmd_bit_clipboard_export_bit_list: 'bit list --skip-update --json %{scope}'
|
27
|
+
cmd_bit_require_lib_bit_list: 'bit list --skip-update --json'
|
28
|
+
cmd_bit_require_lib_bit_list_ids: 'bit list --skip-update --json --ids'
|
29
|
+
cmd_bit_scope_add_scope: 'bit remote add %{remote}/%{scope}'
|
30
|
+
cmd_bit_scope_list_find_scopes: 'find -L %{root} -name scope.json'
|
31
|
+
cmd_bit_scope_new_bit_init: 'mkdir -p %{root}/%{scope} && cd %{root}/%{scope} && bit init --bare'
|
32
|
+
cmd_bit_scope_remove_scope: 'rm --force --recursive %{root}/%{scope}'
|
33
|
+
cmd_docker: 'docker'
|
34
|
+
cmd_docker_check_daemon_docker_info: 'docker info'
|
35
|
+
cmd_docker_container_check_existing_docker_ps: 'docker ps --filter name=^%{container}$ --quiet'
|
36
|
+
cmd_docker_container_check_network_docker_network: 'docker network ls --quiet --filter name=^%{network}$'
|
37
|
+
cmd_docker_container_check_orphaned_docker_exec: 'docker exec --interactive %{container} ps a'
|
38
|
+
cmd_docker_container_create: 'docker run --detach --env TAKELAGE_PROJECT_BASE_DIR=%{workdir} --env TZ=%{timezone} --hostname %{container} --name %{container} --network %{container} --rm --shm-size %{shmsize} --tty --volume %{dockersock}:/var/run/docker.sock --volume %{homedir}:/hostdir --volume %{workdir}:/project %{volume_dev} --workdir /project %{docker_run_options} %{image} %{entrypoint} --gid %{gid} --home %{homedir} --uid %{uid} --username %{username} --extra=%{extra} %{entrypoint_options}'
|
39
|
+
cmd_docker_container_create_network: 'docker network create %{network}'
|
40
|
+
cmd_docker_container_enter_container: 'docker exec --interactive --tty %{container} %{loginpoint} --username %{username}'
|
41
|
+
cmd_docker_container_get_container_name: 'docker ps --filter id=%{container} --format "{{.Names}}"'
|
42
|
+
cmd_docker_container_get_containers: 'docker ps --all --filter name=^%{docker_repo}_ --quiet'
|
43
|
+
cmd_docker_container_remove_network: 'docker network rm %{network}'
|
44
|
+
cmd_docker_container_docker_exec: 'docker exec %{container} su %{username} -c "LANG=en_US.UTF-8 %{command}"'
|
45
|
+
cmd_docker_container_stop_container: 'docker stop %{container}'
|
46
|
+
cmd_docker_image_tag_check_docker_images: 'docker images --quiet %{image}'
|
47
|
+
cmd_docker_image_tag_list_docker_images: 'docker images %{docker_user}\/%{docker_repo} --format "{{.Tag}}"'
|
48
|
+
cmd_docker_image_update_docker_pull_latest: 'docker pull %{docker_user}/%{docker_repo}:latest'
|
49
|
+
cmd_docker_image_update_docker_remove_dangling: 'docker image prune --force'
|
50
|
+
cmd_git: 'git'
|
51
|
+
cmd_git_check_clean_git_unstaged: 'git diff --exit-code'
|
52
|
+
cmd_git_check_clean_git_uncommitted: 'git diff --cached --exit-code'
|
53
|
+
cmd_git_check_clean_git_status: 'git status --porcelain'
|
54
|
+
cmd_git_check_bit_get_git_branch: 'git symbolic-ref HEAD'
|
55
|
+
cmd_git_check_workspace_git_repo: 'git -C %{dir} rev-parse'
|
56
|
+
cmd_git_check_workspace_pwd: 'pwd'
|
57
|
+
cmd_info_status_lib_git_name: 'git -C %{root} config user.name'
|
58
|
+
cmd_info_status_lib_git_email: 'git -C %{root} config user.email'
|
59
|
+
cmd_info_status_lib_git_signingkey: 'git -C %{root} config user.signingKey'
|
60
|
+
cmd_info_status_lib_git_key_available: 'gpg --list-key %{key}'
|
61
|
+
cmd_info_status_gopass_root_store: 'gopass config | grep "path" | cut -d " " -f 2'
|
62
|
+
cmd_info_status_gpg_agent: 'gpg-connect-agent /bye'
|
63
|
+
cmd_info_status_gpg_keys: 'gpg --list-keys'
|
64
|
+
cmd_info_status_ssh_keys: 'ssh-add -l'
|
65
|
+
cmd_info_status_ssh_socket: 'gpgconf --list-dirs agent-ssh-socket'
|
66
|
+
cmd_init_lib_bit_init: 'bit init'
|
67
|
+
cmd_init_lib_git_init: 'git init && git checkout -b main'
|
68
|
+
cmd_init_lib_git_add_all: 'git add --all'
|
69
|
+
cmd_init_lib_git_commit_initial: 'git commit -m "Initial commit"'
|
70
|
+
cmd_mutagen: 'mutagen'
|
71
|
+
cmd_mutagen_check_daemon_host_connection: 'mutagen forward list --label-selector="%{hostlabel}"'
|
72
|
+
cmd_mutagen_check_daemon_version: 'mutagen version'
|
73
|
+
cmd_mutagen_forward_socket_create: 'mutagen forward create --name=%{socketname} --label=%{hostlabel} --label=%{takellabel} docker://%{username}@%{container}:unix:%{containersock} unix:%{hostsock}'
|
74
|
+
cmd_mutagen_forward_socket_check: 'mutagen forward list %{socketname}'
|
75
|
+
cmd_mutagen_forward_socket_terminate: 'mutagen forward terminate %{socketname}'
|
76
|
+
cmd_mutagen_forward_socket_remove: 'rm -f ~/.mutagen/daemon/*'
|
77
|
+
cmd_mutagen_forward_socket_list: 'mutagen forward list --label-selector="%{takellabel}"'
|
78
|
+
docker_debug: 'ansible/roles/takel-takelage/files/takelscripts'
|
79
|
+
docker_entrypoint_extra: '.config/gcloud'
|
80
|
+
docker_entrypoint_options: ''
|
81
|
+
docker_registry: 'https://registry.hub.docker.com'
|
82
|
+
docker_repo: 'takelage'
|
83
|
+
docker_run_options: '--env GOOGLE_APPLICATION_CREDENTIALS=/hostdir/.google/default.json'
|
84
|
+
docker_shm_size: '512M'
|
85
|
+
docker_tag: 'latest'
|
86
|
+
docker_user: 'takelwerk'
|
87
|
+
git_bit_branch: 'main'
|
88
|
+
info_project_main: 'project.yml'
|
89
|
+
info_project_private: 'private/project.yml'
|
90
|
+
init_bit_require_import: 'true'
|
91
|
+
login_wait_for_sockets: '0'
|
92
|
+
mutagen_socket_path_mutagen: '~/.mutagen/daemon/daemon.sock'
|
93
|
+
mutagen_socket_path_gpg: '~/.gnupg/S.gpg-agent'
|
94
|
+
mutagen_socket_path_ssh: '~/.gnupg/S.gpg-agent.ssh'
|
95
|
+
mutagen_socket_takelage_label: 'type=takelage'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Takeltau
|
4
|
+
# takeltau docker check
|
5
|
+
class DockerCheck < SubCommandBase
|
6
|
+
include LoggingModule
|
7
|
+
include SystemModule
|
8
|
+
include ConfigModule
|
9
|
+
include DockerCheckDaemon
|
10
|
+
|
11
|
+
#
|
12
|
+
# docker check daemon
|
13
|
+
#
|
14
|
+
desc 'daemon', 'Check if docker daemon is running'
|
15
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
16
|
+
Check if docker daemon is running
|
17
|
+
LONGDESC
|
18
|
+
# Check if docker daemon is running.
|
19
|
+
def daemon
|
20
|
+
exit docker_check_daemon
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau docker check daemon
|
4
|
+
module DockerCheckDaemon
|
5
|
+
# Backend method for docker check daemon.
|
6
|
+
# @return [Boolean] is the docker daemon running?
|
7
|
+
# rubocop:disable Metrics/MethodLength
|
8
|
+
def docker_check_daemon
|
9
|
+
return true if @docker_daemon_running
|
10
|
+
|
11
|
+
return false unless command_available_else_error? config.active['cmd_docker']
|
12
|
+
|
13
|
+
log.debug 'Check if the docker daemon is running'
|
14
|
+
|
15
|
+
status = try config.active['cmd_docker_check_daemon_docker_info']
|
16
|
+
|
17
|
+
unless status.exitstatus.zero?
|
18
|
+
log.error 'The docker daemon is not running'
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
|
22
|
+
log.debug 'The docker daemon is running'
|
23
|
+
@docker_daemon_running = true
|
24
|
+
true
|
25
|
+
end
|
26
|
+
# rubocop:enable Metrics/MethodLength
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Takeltau
|
4
|
+
# takeltau docker
|
5
|
+
class Docker < SubCommandBase
|
6
|
+
desc 'check [COMMAND]', 'Check docker'
|
7
|
+
subcommand 'check', DockerCheck
|
8
|
+
|
9
|
+
desc 'container [COMMAND]', 'Handle docker container'
|
10
|
+
subcommand 'container', DockerContainer
|
11
|
+
|
12
|
+
desc 'image [COMMAND]', 'Handle docker images'
|
13
|
+
subcommand 'image', DockerImage
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Takeltau
|
4
|
+
# takeltau docker container check
|
5
|
+
class DockerContainerCheck < SubCommandBase
|
6
|
+
include LoggingModule
|
7
|
+
include SystemModule
|
8
|
+
include ConfigModule
|
9
|
+
include DockerCheckDaemon
|
10
|
+
include DockerContainerCheckExisting
|
11
|
+
include DockerContainerCheckNetwork
|
12
|
+
include DockerContainerCheckOrphaned
|
13
|
+
|
14
|
+
#
|
15
|
+
# docker container check existing
|
16
|
+
#
|
17
|
+
desc 'existing [CONTAINER]', 'Check if docker [CONTAINER] is existing'
|
18
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
19
|
+
Check if docker container is existing
|
20
|
+
This check looks for a container with a given name.
|
21
|
+
If such a container is existing the result is true else false.
|
22
|
+
LONGDESC
|
23
|
+
# Check if docker container is existing.
|
24
|
+
def existing(container)
|
25
|
+
exit docker_container_check_existing container
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# docker container check network
|
30
|
+
#
|
31
|
+
desc 'network [NETWORK]', 'Check if docker [NETWORK] is existing'
|
32
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
33
|
+
Check if docker network is existing
|
34
|
+
This check looks for a network with a given name.
|
35
|
+
If such a network is existing the result is true else false.
|
36
|
+
LONGDESC
|
37
|
+
# Check if docker network is existing.
|
38
|
+
def network(network)
|
39
|
+
exit docker_container_check_network network
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# docker container check orphaned
|
44
|
+
#
|
45
|
+
desc 'orphaned [CONTAINER]', 'Check if docker [CONTAINER] is orphaned'
|
46
|
+
long_desc <<-LONGDESC.gsub("\n", "\x5")
|
47
|
+
Check if docker container is orphaned
|
48
|
+
This check looks for a process which is started
|
49
|
+
when you log in to an takelage docker container.
|
50
|
+
If such a process is found the result is true else false.
|
51
|
+
LONGDESC
|
52
|
+
# Check if docker container is orphaned.
|
53
|
+
def orphaned(container)
|
54
|
+
exit docker_container_check_orphaned container
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau docker container check existing
|
4
|
+
module DockerContainerCheckExisting
|
5
|
+
# Backend method for docker container check existing.
|
6
|
+
# @return [Boolean] is container existing?
|
7
|
+
def docker_container_check_existing(container)
|
8
|
+
log.debug "Checking if container \"#{container}\" is existing"
|
9
|
+
|
10
|
+
return false unless docker_check_daemon
|
11
|
+
|
12
|
+
stdout_str = run _docker_container_cmd_check_existing container
|
13
|
+
|
14
|
+
if stdout_str.to_s.chomp.empty?
|
15
|
+
log.debug "Container \"#{container}\" is not existing"
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
19
|
+
log.debug "Container \"#{container}\" is existing"
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Format command to check if docker container exists.
|
26
|
+
def _docker_container_cmd_check_existing(container)
|
27
|
+
format(
|
28
|
+
config.active['cmd_docker_container_check_existing_docker_ps'],
|
29
|
+
container: container
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau docker container check network
|
4
|
+
module DockerContainerCheckNetwork
|
5
|
+
# Backend method for docker container check network.
|
6
|
+
# @return [Boolean] is network existing?
|
7
|
+
def docker_container_check_network(network)
|
8
|
+
log.debug "Checking if network \"#{network}\" is existing"
|
9
|
+
|
10
|
+
return false unless docker_check_daemon
|
11
|
+
|
12
|
+
stdout_str = run _docker_container_cmd_check_network network
|
13
|
+
|
14
|
+
if stdout_str.to_s.chomp.empty?
|
15
|
+
log.debug "Network \"#{network}\" is not existing"
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
19
|
+
log.debug "Network \"#{network}\" is existing"
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Prepare command to check if docker network exists.
|
26
|
+
def _docker_container_cmd_check_network(network)
|
27
|
+
format(
|
28
|
+
config.active['cmd_docker_container_check_network_docker_network'],
|
29
|
+
network: network
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# takeltau docker container check orphaned
|
4
|
+
module DockerContainerCheckOrphaned
|
5
|
+
# Backend method for docker container check orphaned.
|
6
|
+
# @return [Boolean] is container orphaned?
|
7
|
+
def docker_container_check_orphaned(container)
|
8
|
+
log.debug "Check if container \"#{container}\" is orphaned"
|
9
|
+
|
10
|
+
return false unless docker_check_daemon
|
11
|
+
|
12
|
+
stdout_str = run _docker_container_cmd_check_orphaned container
|
13
|
+
|
14
|
+
if stdout_str.include? '/loginpoint.py'
|
15
|
+
log.debug "Container \"#{container}\" isn't orphaned"
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
19
|
+
log.debug "Container \"#{container}\" is orphaned"
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Format command to check if docker container is orphaned.
|
26
|
+
def _docker_container_cmd_check_orphaned(container)
|
27
|
+
format(
|
28
|
+
config.active['cmd_docker_container_check_orphaned_docker_exec'],
|
29
|
+
container: container
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|