picobox 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -8,6 +8,7 @@ module Picobox
8
8
  def config_dir() "#{home_dir}/#{Picobox::CONFIG_DIR}" end
9
9
 
10
10
  def shell_extensions() "#{config_dir}/#{Picobox::SHELL_EXTENSIONS}" end
11
+ def user_shell() "#{ENV['SHELL']}" end
11
12
 
12
13
  # download and install
13
14
  def docker_filename() end
@@ -15,14 +16,13 @@ module Picobox
15
16
  def docker_installer() end
16
17
  def docker_installed?() end
17
18
 
18
- def docker_version?() `docker --version` end
19
- def user_shell() "#{ENV['SHELL']}" end
20
-
19
+ def docker_version?() `docker --version`.strip end
20
+ def docker_compose_version?() `docker-compose --version`.strip end
21
+
21
22
  def to_s() raise ::NotImplementedError, 'must override to_s' end
22
23
 
23
24
  def project_root() Utils::Project.new(self).root end
24
25
  def reload_shell() system("exec #{user_shell} -l") end
25
-
26
26
  end
27
27
  end
28
28
  end
@@ -6,6 +6,7 @@ module Picobox
6
6
  os = TTY::Platform.new.os
7
7
  case os
8
8
  when 'darwin' then Darwin
9
+ when 'linux' then Linux
9
10
  else UnsupportedOs end
10
11
  end
11
12
  end
@@ -0,0 +1,32 @@
1
+ module Picobox
2
+ module Os
3
+ class Distro
4
+ class << self
5
+ def distro
6
+ case `lsb_release -ids`.strip
7
+ when /(Ubuntu)/
8
+ :ubuntu
9
+ when /(Debian)/
10
+ :debian
11
+ when /(Fedora)/
12
+ :fedora
13
+ else
14
+ :unknown
15
+ end
16
+ end
17
+
18
+ def su(os)
19
+ su ||= if os.user == 'root'
20
+ 'sh -c'
21
+ elsif TTY::Which.exist?('sudo')
22
+ 'sudo -E sh -c'
23
+ elsif TTY::Which.exist?('su')
24
+ 'su -c'
25
+ else
26
+ raise StandardError, "Error: this installer needs the ability to run commands as root.\n We are unable to find either 'sudo' or 'su' available to make this happen."
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,6 +3,20 @@ module Picobox
3
3
  class Linux < Abstract
4
4
  class << self
5
5
  def to_s() :linux end
6
+
7
+ def docker_installed?() TTY::Which.exist?('docker') end
8
+ def docker_compose_installed?() TTY::Which.exist?('docker-compose') end
9
+
10
+ def docker_compose_url() "https://github.com/docker/compose/releases/download/1.16.1/docker-compose-Linux-#{self.arch}" end
11
+ def docker_compose() "/usr/local/bin/docker-compose" end
12
+
13
+ def user() "#{ENV['USER']}" end
14
+
15
+ def release() `lsb_release -cs`.strip end
16
+ def kernel() `uname -r`.strip end
17
+ def arch() `uname -m`.strip end
18
+ def distro() Os::Distro.distro end
19
+ def su() Os::Distro.su(self) end
6
20
  end
7
21
  end
8
22
  end
@@ -1,7 +1,7 @@
1
1
  module Picobox
2
2
  class Project
3
3
  include Utils::Visitable
4
- include Utils::Output
4
+ include Utils::Output
5
5
 
6
6
  attr_reader :os
7
7
 
@@ -11,7 +11,7 @@ module Picobox
11
11
 
12
12
  def init
13
13
  accept(Commands::InitializeProject.new)
14
- rescue Exception => e
14
+ rescue StandardError => e
15
15
  display_info(e, :red)
16
16
  exit 1
17
17
  end
@@ -11,7 +11,7 @@ module Picobox
11
11
 
12
12
  def build(service=nil)
13
13
  accept(Commands::BuildService.new(service))
14
- rescue Exception => e
14
+ rescue StandardError => e
15
15
  display_info(e, :red)
16
16
  exit 1
17
17
  end
@@ -28,7 +28,7 @@ module Picobox
28
28
  rescue Picobox::Errors::FileNotFoundError => e
29
29
  display_file_not_found e.message
30
30
  exit 1
31
- rescue Exception => e
31
+ rescue StandardError => e
32
32
  display_info(e, :red)
33
33
  exit 1
34
34
  end
@@ -48,7 +48,7 @@ module Picobox
48
48
  rescue Picobox::Errors::FileNotFoundError => e
49
49
  display_file_not_found e.message
50
50
  exit
51
- rescue Exception => e
51
+ rescue StandardError => e
52
52
  display_info(e, :red)
53
53
  exit 1
54
54
  end
@@ -56,7 +56,7 @@ module Picobox
56
56
 
57
57
  def list()
58
58
  accept(Commands::ListServices.new)
59
- rescue Exception => e
59
+ rescue StandardError => e
60
60
  display_info(e, :red)
61
61
  exit 1
62
62
  end
@@ -7,7 +7,7 @@ module Picobox
7
7
 
8
8
  def list
9
9
  result = Dir.glob("#{Picobox.service_packages_dir}/*").select {|f| File.directory? f}
10
- result.map {|r| strip_path(r) }
10
+ result.map {|r| strip_path(r) }.sort!
11
11
  end
12
12
 
13
13
 
@@ -0,0 +1,9 @@
1
+ module Picobox
2
+ module Shell
3
+ class DotBashRC < StartupScript
4
+ def filename
5
+ "#{os.home_dir}/.bashrc"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,42 +1,9 @@
1
1
  module Picobox
2
2
  module Shell
3
- class DotProfile
4
- attr_reader :os
5
-
6
- def initialize(os)
7
- @os = os
8
- end
9
-
10
- def install_extensions
11
- source = "#{Picobox.template_dir}/shell_extensions.bash"
12
- dest = os.shell_extensions
13
-
14
- TTY::File.copy_file source, dest
15
-
16
- TTY::File.append_to_file(
17
- filename,
18
- "\n#{extension}\n"
19
- )
20
- end
21
-
22
- def uninstall_extensions
23
- TTY::File.gsub_file filename, /#{Regexp.escape(extension)}/ do
24
- "# picobox removed #{Time.now}"
25
- end
26
- end
27
-
3
+ class DotProfile < StartupScript
28
4
  def filename
29
5
  "#{os.home_dir}/.profile"
30
6
  end
31
-
32
- private
33
- def source_file
34
- "~/#{Picobox::CONFIG_DIR}/#{Picobox::SHELL_EXTENSIONS}"
35
- end
36
-
37
- def extension
38
- "# added by picobox\nsource #{source_file}"
39
- end
40
7
  end
41
8
  end
42
9
  end
@@ -1,42 +1,9 @@
1
1
  module Picobox
2
2
  module Shell
3
- class DotZshrc
4
- attr_reader :os
5
-
6
- def initialize(os)
7
- @os = os
8
- end
9
-
10
- def install_extensions
11
- source = "#{Picobox.template_dir}/shell_extensions.bash"
12
- dest = os.shell_extensions
13
-
14
- TTY::File.copy_file source, dest
15
-
16
- TTY::File.append_to_file(
17
- filename,
18
- "\n#{extension}\n"
19
- )
20
- end
21
-
22
- def uninstall_extensions
23
- TTY::File.gsub_file filename, /#{Regexp.escape(extension)}/ do
24
- "# picobox removed #{Time.now}"
25
- end
26
- end
27
-
3
+ class DotZshRC < StartupScript
28
4
  def filename
29
5
  "#{os.home_dir}/.zshrc"
30
6
  end
31
-
32
- private
33
- def source_file
34
- "~/#{Picobox::CONFIG_DIR}/#{Picobox::SHELL_EXTENSIONS}"
35
- end
36
-
37
- def extension
38
- "# added by picobox\nsource #{source_file}"
39
- end
40
7
  end
41
8
  end
42
9
  end
@@ -7,12 +7,51 @@ module Picobox
7
7
  when '/bin/bash:darwin'
8
8
  Shell::DotProfile.new(os)
9
9
  when '/bin/zsh:darwin'
10
- Shell::DotZshrc.new(os)
10
+ Shell::DotZshRC.new(os)
11
+ when '/bin/bash:linux'
12
+ Shell::DotBashRC.new(os)
11
13
  else
12
14
  raise Errors::ShellNotSupported, "#{os.user_shell}:#{os.to_s}"
13
15
  end
14
16
  end
15
17
  end
18
+
19
+ attr_reader :os
20
+
21
+ def initialize(os)
22
+ @os = os
23
+ end
24
+
25
+ def install_extensions
26
+ source = "#{Picobox.template_dir}/shell_extensions.bash"
27
+ dest = os.shell_extensions
28
+
29
+ TTY::File.copy_file source, dest
30
+
31
+ TTY::File.append_to_file(
32
+ filename,
33
+ "\n#{extension}\n"
34
+ )
35
+ end
36
+
37
+ def uninstall_extensions
38
+ TTY::File.gsub_file filename, /#{Regexp.escape(extension)}/ do
39
+ "# picobox removed #{Time.now}"
40
+ end
41
+ end
42
+
43
+ def filename
44
+ raise ::NotImplementedError, 'must filename'
45
+ end
46
+
47
+ private
48
+ def source_file
49
+ "~/#{Picobox::CONFIG_DIR}/#{Picobox::SHELL_EXTENSIONS}"
50
+ end
51
+
52
+ def extension
53
+ "# added by picobox\nsource #{source_file}"
54
+ end
16
55
  end
17
56
  end
18
57
  end
@@ -11,14 +11,19 @@ module Picobox
11
11
 
12
12
  def install
13
13
  accept(Commands::StartInstall.new)
14
+ accept(Commands::GetRootPermission.new)
14
15
  accept(Commands::DownloadDocker.new)
15
16
  accept(Commands::InstallDocker.new)
16
17
  accept(Commands::SetupShell.new)
17
18
  accept(Commands::FinishInstall.new)
19
+ accept(Commands::ReloadShell.new)
18
20
  rescue Errors::ShellNotSupported => e
19
21
  display_shell_not_supported e.message
20
22
  exit 1
21
- rescue Exception => e
23
+ rescue Errors::DistroNotSupported => e
24
+ display_distro_not_supported
25
+ exit 1
26
+ rescue StandardError => e
22
27
  display_info(e, :red)
23
28
  exit 1
24
29
  end
@@ -31,7 +36,7 @@ module Picobox
31
36
  rescue Errors::PicoboxNotInstalled
32
37
  display_picobox_not_installed
33
38
  exit 1
34
- rescue Exception => e
39
+ rescue StandardError => e
35
40
  display_info(e, :red)
36
41
  exit 1
37
42
  end
@@ -42,7 +47,7 @@ module Picobox
42
47
  rescue Errors::ProjectNotInitialized
43
48
  display_project_not_initialized
44
49
  exit 1
45
- rescue Exception => e
50
+ rescue StandardError => e
46
51
  display_info(e, :red)
47
52
  exit 1
48
53
  end
@@ -53,7 +58,7 @@ module Picobox
53
58
  rescue Errors::ProjectNotInitialized
54
59
  display_project_not_initialized
55
60
  exit 1
56
- rescue Exception => e
61
+ rescue StandardError => e
57
62
  display_info(e, :red)
58
63
  exit 1
59
64
  end
@@ -61,21 +66,21 @@ module Picobox
61
66
 
62
67
  def restart
63
68
  accept(Commands::Restart.new)
64
- rescue Exception => e
69
+ rescue StandardError => e
65
70
  display_info(e, :red)
66
71
  exit 1
67
72
  end
68
73
 
69
74
 
70
- def open_shell(service)
71
- accept(Commands::OpenShell.new(service))
75
+ def ssh(service)
76
+ accept(Commands::SshInstance.new(service))
72
77
  rescue Errors::SystemDownError
73
78
  display_system_down
74
79
  exit 1
75
80
  rescue Errors::ProjectNotInitialized
76
81
  display_project_not_initialized
77
82
  exit 1
78
- rescue Exception => e
83
+ rescue StandardError => e
79
84
  display_info(e, :red)
80
85
  exit 1
81
86
  end
@@ -60,6 +60,11 @@ module Picobox
60
60
  display_info "Picobox not installed!", :red
61
61
  end
62
62
 
63
+
64
+ def display_distro_not_supported
65
+ display_info('distro is not yet supported :(', :red)
66
+ end
67
+
63
68
  private
64
69
  def thor
65
70
  @thor ||= Thor::Shell::Color.new
@@ -0,0 +1,27 @@
1
+ module Picobox
2
+ module Utils
3
+ class Spinner
4
+ class << self
5
+ def new(message)
6
+ pastel = Pastel.new
7
+ format = " #{message} [:spinner]"
8
+
9
+ @spinner = TTY::Spinner.new(pastel.green(format),
10
+ hide_cursor: true,
11
+ clear: true
12
+ )
13
+
14
+ Picobox.verbose? ? puts(format) : spinner.auto_spin
15
+ end
16
+
17
+
18
+ def stop()
19
+ spinner.stop
20
+ end
21
+
22
+ private
23
+ attr_accessor :spinner
24
+ end
25
+ end
26
+ end
27
+ end
@@ -4,7 +4,8 @@ module Picobox
4
4
  include Utils::DomainEventPublisher
5
5
 
6
6
  def visit subject
7
- method_name = "visit_#{subject.os.to_s}".intern
7
+ @os = subject.os
8
+ method_name = "visit_#{os.to_s}".intern
8
9
  send(method_name, subject )
9
10
  end
10
11
 
@@ -21,9 +22,11 @@ module Picobox
21
22
  end
22
23
 
23
24
  def visit_unsupported subject
24
- os = TTY::Platform.new.os
25
- raise Errors::UnsupportedOsError, "#{os} is not yet supported :("
25
+ raise Errors::UnsupportedOsError, "#{TTY::Platform.new.os} is not yet supported :("
26
26
  end
27
+
28
+ protected
29
+ attr_reader :os
27
30
  end
28
31
  end
29
32
  end