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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/README.md +1 -1
  4. data/lib/picobox.rb +9 -4
  5. data/lib/picobox/box.rb +2 -2
  6. data/lib/picobox/boxes/manifest.rb +1 -1
  7. data/lib/picobox/cli.rb +62 -10
  8. data/lib/picobox/commands/add_box.rb +6 -2
  9. data/lib/picobox/commands/add_service.rb +6 -2
  10. data/lib/picobox/commands/build_service.rb +8 -1
  11. data/lib/picobox/commands/download_docker.rb +23 -5
  12. data/lib/picobox/commands/finish_install.rb +6 -0
  13. data/lib/picobox/commands/finish_uninstall.rb +5 -0
  14. data/lib/picobox/commands/get_root_permission.rb +14 -0
  15. data/lib/picobox/commands/initialize_project.rb +6 -4
  16. data/lib/picobox/commands/install_docker.rb +31 -5
  17. data/lib/picobox/commands/list_boxes.rb +4 -4
  18. data/lib/picobox/commands/list_services.rb +4 -4
  19. data/lib/picobox/commands/reload_shell.rb +15 -0
  20. data/lib/picobox/commands/remove_service.rb +6 -2
  21. data/lib/picobox/commands/remove_setup_shell.rb +6 -4
  22. data/lib/picobox/commands/restart.rb +8 -7
  23. data/lib/picobox/commands/setup_shell.rb +7 -4
  24. data/lib/picobox/commands/{open_shell.rb → ssh_instance.rb} +8 -4
  25. data/lib/picobox/commands/start.rb +6 -5
  26. data/lib/picobox/commands/start_install.rb +5 -0
  27. data/lib/picobox/commands/start_uninstall.rb +5 -4
  28. data/lib/picobox/commands/stop.rb +6 -5
  29. data/lib/picobox/constants.rb +14 -1
  30. data/lib/picobox/errors/picobox_error.rb +1 -0
  31. data/lib/picobox/handlers/stdout_handler.rb +40 -16
  32. data/lib/picobox/os/abstract.rb +4 -4
  33. data/lib/picobox/os/current_os.rb +1 -0
  34. data/lib/picobox/os/distro.rb +32 -0
  35. data/lib/picobox/os/linux.rb +14 -0
  36. data/lib/picobox/project.rb +2 -2
  37. data/lib/picobox/service.rb +4 -4
  38. data/lib/picobox/services/manifest.rb +1 -1
  39. data/lib/picobox/shell/dot_bashrc.rb +9 -0
  40. data/lib/picobox/shell/dot_profile.rb +1 -34
  41. data/lib/picobox/shell/dot_zshrc.rb +1 -34
  42. data/lib/picobox/shell/startup_script.rb +40 -1
  43. data/lib/picobox/system.rb +13 -8
  44. data/lib/picobox/utils/output.rb +5 -0
  45. data/lib/picobox/utils/spinner.rb +27 -0
  46. data/lib/picobox/utils/visitor_by_os.rb +6 -3
  47. data/picobox.gemspec +4 -2
  48. metadata +42 -9
@@ -0,0 +1,14 @@
1
+ module Picobox
2
+ module Commands
3
+ class GetRootPermission < Picobox::Utils::VisitorByOs
4
+ def visit_darwin subject
5
+
6
+ end
7
+
8
+
9
+ def visit_linux subject
10
+ system "#{os.su} 'echo 1 > /dev/null'"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -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 subject.os.docker_installed?
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, commands.length
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, subject.os.docker_version?
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
- private
13
- attr_reader :os
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
- private
13
- attr_reader :os
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 :os, :type
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
- Picobox::CLI.new.stop
9
- Picobox::CLI.new.start
6
+ System.new(Os::CurrentOs.get).stop
7
+ System.new(Os::CurrentOs.get).start
10
8
  else
11
- Picobox::CLI.new.start
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(@os)
7
+ start_up_script = Shell::StartupScript.get(os)
10
8
 
11
- TTY::File.create_dir @os.config_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 OpenShell < Picobox::Utils::VisitorByOs
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, :os
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('docker-compose up -d 2>/dev/null') unless project_running?
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
@@ -4,6 +4,11 @@ module Picobox
4
4
  def visit_darwin subject
5
5
  publish_event :install_started
6
6
  end
7
+
8
+
9
+ def visit_linux subject
10
+ publish_event :install_started
11
+ end
7
12
  end
8
13
  end
9
14
  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
- private
13
- attr_reader :os
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('docker-compose down 2>/dev/null') if project_running?
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
@@ -1,14 +1,27 @@
1
1
  module Picobox
2
2
  # names for files / directories
3
- VERSION = '0.1.7'
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
@@ -11,5 +11,6 @@ module Picobox
11
11
  class UnsupportedOsError < PicoboxError; end
12
12
  class FileNotFoundError < PicoboxError; end
13
13
  class PicoboxNotInstalled < PicoboxError; end
14
+ class DistroNotSupported < PicoboxError; end
14
15
  end
15
16
  end
@@ -14,17 +14,21 @@ module Picobox
14
14
  display_line '-------------------------------'
15
15
  end
16
16
 
17
- def post_install_messages
18
- display_line ''
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.strip} present", :green)
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 download_docker_progress(progress)
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('[green]Preparing to install Docker[/]')
44
+ display_info('Preparing to install Docker', :green)
41
45
  end
42
46
 
43
- def install_docker_start(size)
44
- display_info('Installing Docker', :green)
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 install_docker_progress
49
- Utils::ProgressBar.increment
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
- display_info("Picobox stopping...", :green)
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
- display_info("Picobox starting...", :green)
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