picobox 0.1.7 → 0.2.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/.gitignore +1 -1
- data/README.md +1 -1
- data/lib/picobox.rb +9 -4
- data/lib/picobox/box.rb +2 -2
- data/lib/picobox/boxes/manifest.rb +1 -1
- data/lib/picobox/cli.rb +62 -10
- data/lib/picobox/commands/add_box.rb +6 -2
- data/lib/picobox/commands/add_service.rb +6 -2
- data/lib/picobox/commands/build_service.rb +8 -1
- data/lib/picobox/commands/download_docker.rb +23 -5
- data/lib/picobox/commands/finish_install.rb +6 -0
- data/lib/picobox/commands/finish_uninstall.rb +5 -0
- data/lib/picobox/commands/get_root_permission.rb +14 -0
- data/lib/picobox/commands/initialize_project.rb +6 -4
- data/lib/picobox/commands/install_docker.rb +31 -5
- data/lib/picobox/commands/list_boxes.rb +4 -4
- data/lib/picobox/commands/list_services.rb +4 -4
- data/lib/picobox/commands/reload_shell.rb +15 -0
- data/lib/picobox/commands/remove_service.rb +6 -2
- data/lib/picobox/commands/remove_setup_shell.rb +6 -4
- data/lib/picobox/commands/restart.rb +8 -7
- data/lib/picobox/commands/setup_shell.rb +7 -4
- data/lib/picobox/commands/{open_shell.rb → ssh_instance.rb} +8 -4
- data/lib/picobox/commands/start.rb +6 -5
- data/lib/picobox/commands/start_install.rb +5 -0
- data/lib/picobox/commands/start_uninstall.rb +5 -4
- data/lib/picobox/commands/stop.rb +6 -5
- data/lib/picobox/constants.rb +14 -1
- data/lib/picobox/errors/picobox_error.rb +1 -0
- data/lib/picobox/handlers/stdout_handler.rb +40 -16
- data/lib/picobox/os/abstract.rb +4 -4
- data/lib/picobox/os/current_os.rb +1 -0
- data/lib/picobox/os/distro.rb +32 -0
- data/lib/picobox/os/linux.rb +14 -0
- data/lib/picobox/project.rb +2 -2
- data/lib/picobox/service.rb +4 -4
- data/lib/picobox/services/manifest.rb +1 -1
- data/lib/picobox/shell/dot_bashrc.rb +9 -0
- data/lib/picobox/shell/dot_profile.rb +1 -34
- data/lib/picobox/shell/dot_zshrc.rb +1 -34
- data/lib/picobox/shell/startup_script.rb +40 -1
- data/lib/picobox/system.rb +13 -8
- data/lib/picobox/utils/output.rb +5 -0
- data/lib/picobox/utils/spinner.rb +27 -0
- data/lib/picobox/utils/visitor_by_os.rb +6 -3
- data/picobox.gemspec +4 -2
- metadata +42 -9
@@ -2,8 +2,6 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class InitializeProject < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
publish_event :project_initialize_start
|
8
6
|
|
9
7
|
create_project_config_dir
|
@@ -12,9 +10,13 @@ module Picobox
|
|
12
10
|
publish_event :project_initialize_complete
|
13
11
|
end
|
14
12
|
|
15
|
-
private
|
16
|
-
attr_reader :os
|
17
13
|
|
14
|
+
def visit_linux subject
|
15
|
+
visit_darwin subject
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
18
20
|
def create_project_config_dir
|
19
21
|
# for now just empty dir, but eventualy add flags with ini files 'ie enabled, etc'
|
20
22
|
# https://github.com/albfan/bash-ini-parser
|
@@ -2,7 +2,7 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class InstallDocker < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
unless
|
5
|
+
unless os.docker_installed?
|
6
6
|
commands = [
|
7
7
|
"/usr/bin/hdiutil attach -noidme -nobrowse -quiet #{subject.os.docker_installer}",
|
8
8
|
"cp -R /Volumes/Docker/Docker.app /Applications",
|
@@ -10,18 +10,44 @@ module Picobox
|
|
10
10
|
"/usr/bin/hdiutil unmount -quiet /Volumes/Docker"
|
11
11
|
]
|
12
12
|
|
13
|
-
publish_event :install_docker_start
|
13
|
+
publish_event :install_docker_start
|
14
14
|
|
15
15
|
commands.each do |command|
|
16
16
|
system(command)
|
17
|
-
publish_event :install_docker_progress
|
18
17
|
end
|
19
18
|
|
20
19
|
publish_event :install_docker_complete
|
21
20
|
else
|
22
|
-
publish_event :docker_present,
|
21
|
+
publish_event :docker_present, os.docker_version?
|
23
22
|
end
|
24
23
|
end
|
24
|
+
|
25
|
+
|
26
|
+
def visit_linux subject
|
27
|
+
unless os.docker_installed?
|
28
|
+
commands = [
|
29
|
+
"curl -fsSL get.docker.com -o get-docker.sh",
|
30
|
+
"sh get-docker.sh #{Picobox.output}",
|
31
|
+
"rm get-docker.sh",
|
32
|
+
"#{os.su} 'usermod -aG docker #{os.user}'"
|
33
|
+
]
|
34
|
+
|
35
|
+
|
36
|
+
publish_event :install_docker_start
|
37
|
+
|
38
|
+
commands.each do |command|
|
39
|
+
system(command)
|
40
|
+
end
|
41
|
+
|
42
|
+
publish_event :add_post_install_message, "If you would like to use Docker as a non-root user\nyou will have to log out and back in for this to take effect!"
|
43
|
+
|
44
|
+
publish_event :install_docker_complete
|
45
|
+
|
46
|
+
else
|
47
|
+
publish_event :docker_present, os.docker_version?
|
48
|
+
end
|
49
|
+
end
|
25
50
|
end
|
26
51
|
end
|
27
|
-
end
|
52
|
+
end
|
53
|
+
|
@@ -2,15 +2,15 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class ListBoxes < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
boxes = Boxes::Manifest.new(os).list
|
8
6
|
|
9
7
|
publish_event :list_boxes, boxes
|
10
8
|
end
|
9
|
+
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
def visit_linux subject
|
12
|
+
visit_darwin subject
|
13
|
+
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -2,15 +2,15 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class ListServices < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
services = Services::Manifest.new(os).list
|
8
6
|
|
9
7
|
publish_event :list_services, services
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
|
11
|
+
def visit_linux subject
|
12
|
+
visit_darwin subject
|
13
|
+
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Picobox
|
2
|
+
module Commands
|
3
|
+
class ReloadShell < Picobox::Utils::VisitorByOs
|
4
|
+
def visit_darwin subject
|
5
|
+
publish_event :reload_shell
|
6
|
+
Utils::Shell.new(Os::CurrentOs.get).reload
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def visit_linux subject
|
11
|
+
visit_darwin subject
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -6,7 +6,6 @@ module Picobox
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def visit_darwin subject
|
9
|
-
@os = subject.os
|
10
9
|
publish_event :remove_service_start, type
|
11
10
|
|
12
11
|
raise Errors::ProjectNotInitialized unless project_initialized?
|
@@ -16,8 +15,13 @@ module Picobox
|
|
16
15
|
publish_event :remove_service_completed, type
|
17
16
|
end
|
18
17
|
|
18
|
+
|
19
|
+
def visit_linux subject
|
20
|
+
visit_darwin subject
|
21
|
+
end
|
22
|
+
|
19
23
|
private
|
20
|
-
attr_reader :
|
24
|
+
attr_reader :type
|
21
25
|
|
22
26
|
def project_initialized?() Utils::Project.new(os).project_initialized? end
|
23
27
|
end
|
@@ -2,8 +2,6 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class RemoveSetupShell < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
publish_event :remove_shell_setup_start
|
8
6
|
|
9
7
|
delete_config_directory
|
@@ -12,9 +10,13 @@ module Picobox
|
|
12
10
|
publish_event :remove_shell_setup_complete
|
13
11
|
end
|
14
12
|
|
15
|
-
private
|
16
|
-
attr_reader :os
|
17
13
|
|
14
|
+
def visit_linux subject
|
15
|
+
visit_darwin subject
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
18
20
|
def delete_config_directory
|
19
21
|
TTY::File.remove_file os.config_dir, force: true
|
20
22
|
end
|
@@ -2,19 +2,20 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class Restart < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
if project_running?
|
8
|
-
|
9
|
-
|
6
|
+
System.new(Os::CurrentOs.get).stop
|
7
|
+
System.new(Os::CurrentOs.get).start
|
10
8
|
else
|
11
|
-
|
9
|
+
System.new(Os::CurrentOs.get).start
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
|
-
private
|
16
|
-
attr_reader :os
|
17
13
|
|
14
|
+
def visit_linux subject
|
15
|
+
visit_darwin subject
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
18
19
|
def project_running?() Utils::Project.new(os).running? end
|
19
20
|
end
|
20
21
|
end
|
@@ -2,18 +2,21 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class SetupShell < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
publish_event :shell_setup_start
|
8
6
|
|
9
|
-
start_up_script = Shell::StartupScript.get(
|
7
|
+
start_up_script = Shell::StartupScript.get(os)
|
10
8
|
|
11
|
-
TTY::File.create_dir
|
9
|
+
TTY::File.create_dir os.config_dir
|
12
10
|
|
13
11
|
start_up_script.install_extensions
|
14
12
|
|
15
13
|
publish_event :shell_setup_complete
|
16
14
|
end
|
15
|
+
|
16
|
+
|
17
|
+
def visit_linux subject
|
18
|
+
visit_darwin subject
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module Picobox
|
2
2
|
module Commands
|
3
|
-
class
|
3
|
+
class SshInstance < Picobox::Utils::VisitorByOs
|
4
4
|
def initialize(service)
|
5
5
|
@service = service
|
6
6
|
end
|
7
7
|
|
8
8
|
def visit_darwin subject
|
9
|
-
@os = subject.os
|
10
|
-
|
11
9
|
publish_event :opening_shell, service
|
12
10
|
|
13
11
|
raise Errors::ProjectNotInitialized unless project_initialized?
|
@@ -16,8 +14,14 @@ module Picobox
|
|
16
14
|
system "bash", "-c", "docker-compose exec #{service} bash"
|
17
15
|
end
|
18
16
|
|
17
|
+
|
18
|
+
def visit_linux subject
|
19
|
+
visit_darwin subject
|
20
|
+
end
|
21
|
+
|
22
|
+
|
19
23
|
private
|
20
|
-
attr_reader :service
|
24
|
+
attr_reader :service
|
21
25
|
|
22
26
|
def project_initialized?() Utils::Project.new(os).project_initialized? end
|
23
27
|
def project_running?() Utils::Project.new(os).running? end
|
@@ -2,19 +2,20 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class Start < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
publish_event :starting
|
8
6
|
|
9
7
|
raise Errors::ProjectNotInitialized unless project_initialized?
|
10
8
|
|
11
|
-
system(
|
9
|
+
system("docker-compose up -d #{Picobox.output}") unless project_running?
|
12
10
|
publish_event :started
|
13
11
|
end
|
14
12
|
|
15
|
-
private
|
16
|
-
attr_reader :os
|
17
13
|
|
14
|
+
def visit_linux subject
|
15
|
+
visit_darwin subject
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
18
19
|
def project_initialized?() Utils::Project.new(os).project_initialized? end
|
19
20
|
def project_running?() Utils::Project.new(os).running? end
|
20
21
|
end
|
@@ -2,16 +2,17 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class StartUninstall < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
raise Errors::PicoboxNotInstalled unless picobox_installed?
|
8
6
|
|
9
7
|
publish_event :uninstall_started
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
|
11
|
+
def visit_linux subject
|
12
|
+
visit_darwin subject
|
13
|
+
end
|
14
14
|
|
15
|
+
private
|
15
16
|
def picobox_installed?
|
16
17
|
File.exist? os.config_dir
|
17
18
|
end
|
@@ -2,21 +2,22 @@ module Picobox
|
|
2
2
|
module Commands
|
3
3
|
class Stop < Picobox::Utils::VisitorByOs
|
4
4
|
def visit_darwin subject
|
5
|
-
@os = subject.os
|
6
|
-
|
7
5
|
publish_event :stopping
|
8
6
|
|
9
7
|
raise Errors::ProjectNotInitialized unless project_initialized?
|
10
8
|
|
11
|
-
system(
|
9
|
+
system("docker-compose down #{Picobox.output}") if project_running?
|
12
10
|
|
13
11
|
|
14
12
|
publish_event :stopped
|
15
13
|
end
|
16
14
|
|
17
|
-
private
|
18
|
-
attr_reader :os
|
19
15
|
|
16
|
+
def visit_linux subject
|
17
|
+
visit_darwin subject
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
20
21
|
def project_initialized?() Utils::Project.new(os).project_initialized? end
|
21
22
|
def project_running?() Utils::Project.new(os).running? end
|
22
23
|
end
|
data/lib/picobox/constants.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
module Picobox
|
2
2
|
# names for files / directories
|
3
|
-
VERSION = '0.
|
3
|
+
VERSION = '0.2.0'
|
4
4
|
HOMEPAGE = 'https://github.com/surzycki/picobox'
|
5
5
|
CONFIG_DIR = '.picobox'
|
6
6
|
PROJECT_INI = 'project.ini'
|
7
7
|
SHELL_EXTENSIONS = 'shell_extensions'
|
8
8
|
|
9
|
+
|
9
10
|
module_function
|
10
11
|
def root() File.expand_path('../../..', __FILE__) end
|
11
12
|
def template_dir() "#{Picobox.root}/lib/picobox/templates" end
|
12
13
|
def box_packages_dir() "#{Picobox.root}/lib/picobox/boxes/packages" end
|
13
14
|
def service_packages_dir() "#{Picobox.root}/lib/picobox/services/packages" end
|
15
|
+
|
16
|
+
def output() @output end
|
17
|
+
def verbose?() @verbose end
|
18
|
+
|
19
|
+
def set_verbosity(value)
|
20
|
+
@verbose = value
|
21
|
+
if @verbose
|
22
|
+
@output = '2>&1'
|
23
|
+
else
|
24
|
+
@output = '> /dev/null 2>&1'
|
25
|
+
end
|
26
|
+
end
|
14
27
|
end
|
@@ -14,17 +14,21 @@ module Picobox
|
|
14
14
|
display_line '-------------------------------'
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
19
|
-
display_line 'You should reload open shells to pick up shell changes'
|
20
|
-
display_line ''
|
21
|
-
display_status 'opening', 'new shell'
|
22
|
-
display_line ''
|
17
|
+
def add_post_install_message(message)
|
18
|
+
@post_install_messages = (@post_install_messages || Array.new).push message
|
23
19
|
end
|
24
20
|
|
21
|
+
def post_install_messages
|
22
|
+
display_line ''
|
23
|
+
|
24
|
+
@post_install_messages.each do |message|
|
25
|
+
display_line message
|
26
|
+
display_line ''
|
27
|
+
end
|
28
|
+
end
|
25
29
|
|
26
30
|
def docker_present(version)
|
27
|
-
display_info("#{version.
|
31
|
+
display_info("#{version.capitalize} present", :green)
|
28
32
|
end
|
29
33
|
|
30
34
|
def download_docker_start(size)
|
@@ -32,24 +36,29 @@ module Picobox
|
|
32
36
|
Utils::ProgressBar.new(size)
|
33
37
|
end
|
34
38
|
|
35
|
-
def
|
39
|
+
def download_progress(progress)
|
36
40
|
Utils::ProgressBar.step(progress)
|
37
41
|
end
|
38
42
|
|
39
43
|
def download_docker_complete()
|
40
|
-
display_info('
|
44
|
+
display_info('Preparing to install Docker', :green)
|
41
45
|
end
|
42
46
|
|
43
|
-
def
|
44
|
-
display_info('
|
47
|
+
def download_docker_compose_start(size)
|
48
|
+
display_info('Downloading Docker Compose', :green)
|
45
49
|
Utils::ProgressBar.new(size)
|
46
50
|
end
|
47
51
|
|
48
|
-
def
|
49
|
-
|
52
|
+
def download_docker_compose_complete()
|
53
|
+
display_info('Preparing to install Docker Compose', :green)
|
54
|
+
end
|
55
|
+
|
56
|
+
def install_docker_start()
|
57
|
+
Utils::Spinner.new('Installing Docker')
|
50
58
|
end
|
51
59
|
|
52
60
|
def install_docker_complete()
|
61
|
+
Utils::Spinner.stop
|
53
62
|
display_info('Installed Docker', :green)
|
54
63
|
end
|
55
64
|
|
@@ -57,6 +66,11 @@ module Picobox
|
|
57
66
|
display_info('Setting up Shell', :green)
|
58
67
|
end
|
59
68
|
|
69
|
+
def reload_shell
|
70
|
+
display_status 'opening', 'new shell'
|
71
|
+
display_line ''
|
72
|
+
end
|
73
|
+
|
60
74
|
def remove_shell_setup_start
|
61
75
|
display_info('Removing shell extentions', :green)
|
62
76
|
end
|
@@ -84,6 +98,15 @@ module Picobox
|
|
84
98
|
display_info("Adding #{type} box", :green)
|
85
99
|
end
|
86
100
|
|
101
|
+
def build_service_start(service)
|
102
|
+
Utils::Spinner.new("Building Service #{service} (5-10min)")
|
103
|
+
end
|
104
|
+
|
105
|
+
def build_service_stop
|
106
|
+
Utils::Spinner.stop
|
107
|
+
display_info("Service built", :green)
|
108
|
+
end
|
109
|
+
|
87
110
|
def list_boxes(boxes)
|
88
111
|
display_info("Available boxes:", :green)
|
89
112
|
|
@@ -108,7 +131,6 @@ module Picobox
|
|
108
131
|
display_info("Service #{type} added", :green)
|
109
132
|
end
|
110
133
|
|
111
|
-
|
112
134
|
def remove_service_start(type)
|
113
135
|
display_info("Removing #{type} service", :green)
|
114
136
|
end
|
@@ -118,18 +140,20 @@ module Picobox
|
|
118
140
|
end
|
119
141
|
|
120
142
|
def stopping
|
121
|
-
|
143
|
+
Utils::Spinner.new('Picobox stopping')
|
122
144
|
end
|
123
145
|
|
124
146
|
def stopped
|
147
|
+
Utils::Spinner.stop
|
125
148
|
display_info("Picobox stopped!", :green)
|
126
149
|
end
|
127
150
|
|
128
151
|
def starting
|
129
|
-
|
152
|
+
Utils::Spinner.new('Picobox starting')
|
130
153
|
end
|
131
154
|
|
132
155
|
def started
|
156
|
+
Utils::Spinner.stop
|
133
157
|
display_info("Picobox started!", :green)
|
134
158
|
end
|
135
159
|
|