cavalerie_web 1.1.3 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3230d2cf9a2a56319d1bc32662833f0a11f815e0
4
- data.tar.gz: aa09dada506905f3a4d6be6bb3de1e84c7641704
3
+ metadata.gz: f2a80f6338fc2036caff35880f8b477d3cdb17b0
4
+ data.tar.gz: 4c52cd45a3a1414cd855312d4c95595f54f0b907
5
5
  SHA512:
6
- metadata.gz: 941075929046b0325e44e2cc825ba1ca6cbe0b7c721253724b7bd8ea1a0405c68fe3516e80ef5da9922880ce68da781e062f53569c3b9c95f9fb533b101812d6
7
- data.tar.gz: c332daafaa5b89a09b7acea3b43ecc7fad67326fc1708b07351270a3e0f92b760d679bfc7152d91bfcc0fb94879198cc8b1ce33e1db9f06854b8081350f7695b
6
+ metadata.gz: 59cb5cbd10b1613bf80f8adfbded08f8972881e0e884e452e37968f7dbb2bcdcb75d04c0fe860b4df15b17326a7677dce9fdc7cbb4fa3cbe9dc59c794077cedf
7
+ data.tar.gz: d4eee108be25fc5ecc44fc9b5f2a86bf57f38dead2521276d34dfee3675a481332cdd18a7caba1e282b70477c85cd60965abdced5da8f863a0aa13b0e590a872
data/README.md CHANGED
@@ -76,6 +76,14 @@ $ sudo yum install mysql-devel
76
76
  $ brew install mysql
77
77
  ```
78
78
 
79
+ #### Vagrant
80
+
81
+ Visit [this page to install Vagrant](http://www.vagrantup.com/downloads) on your system.
82
+
83
+ #### VirtualBox
84
+
85
+ Visit [this page to install VirtualBox](https://www.virtualbox.org/wiki/Downloads) on your system.
86
+
79
87
  ### 2. Gem installation
80
88
 
81
89
  In your Terminal, run the following commands:
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "cavalerie_web"
7
- spec.version = "1.1.3"
7
+ spec.version = "1.1.6"
8
8
  spec.authors = ["Arnaud Lenglet"]
9
9
  spec.email = ["arlenglet@gmail.com"]
10
10
 
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "rspec", '~> 3.2'
37
37
  spec.add_development_dependency "guard", '~> 2.12'
38
38
  spec.add_development_dependency "guard-rspec", '~> 4.5'
39
- spec.add_development_dependency "codeclimate-test-reporter"
39
+ spec.add_development_dependency "codeclimate-test-reporter", '~> 0.4'
40
40
  end
data/lib/cavalerie_web.rb CHANGED
@@ -25,17 +25,6 @@ module CavalerieWeb
25
25
  Dir.chdir $gem_path
26
26
  end
27
27
 
28
- # Initialization
29
- def self.initialize_system
30
- $sites_folder_path = ENV[Config.get_environment_variables[:sites][:name]]
31
- $shared_folder_path = ENV[Config.get_environment_variables[:shared][:name]]
32
- $mysql_folder_path = ENV[Config.get_environment_variables[:mysql][:name]]
33
- $export_folder_path = ENV[Config.get_environment_variables[:export][:name]]
34
- $credentials_folder_path = $shared_folder_path + "/_credentials"
35
- $samples_folder_path = $shared_folder_path + "/_samples"
36
- $db_dumps_folder_path = $shared_folder_path + "/_db_dumps"
37
- end
38
-
39
28
  run_on_startup
40
29
 
41
30
  end
@@ -30,26 +30,11 @@ Use of NFS mount is discouraged since it could lead to stability issue
30
30
  ["sites", "shared", "mysql", "credentials", "samples", "db_dumps", "export"]
31
31
  end
32
32
 
33
- def self.get_containers_names
34
- get_docker_configs["containers_names"]
35
- end
36
-
37
33
  def self.get_docker_configs
38
34
  docker_configs_file = File.read "#{$configs_path}/docker_configs.json"
39
35
  parsed = JSON.parse docker_configs_file
40
36
  end
41
37
 
42
- def self.get_setup_status
43
- setup_status_file = File.read "#{$configs_path}/setup_status.json"
44
- parsed = JSON.parse setup_status_file
45
- end
46
-
47
- def self.reset_setup_status
48
- setup_status_file_default = "#{$configs_path}/setup_status.default.json"
49
- setup_status_file = "#{$configs_path}/setup_status.json"
50
- FileUtils.cp setup_status_file_default, setup_status_file
51
- end
52
-
53
38
  end
54
39
 
55
40
  end
@@ -11,12 +11,12 @@
11
11
  "mysql-server_root_password": "cavalerie",
12
12
  "mysql-server_os": "Ubuntu 4.8.2-19",
13
13
  "mysql-server_version": "MySQL Community Server 5.6.24",
14
- "mysql-server_post_start_script": false,
15
14
 
16
15
  "apache-server_container_ip": "",
17
- "apache-server_os": "Debian",
16
+ "apache-server_os": "Debian (Wheezy)",
18
17
  "apache-server_version": "Apache/2.2.22",
19
- "apache-server_post_start_script": false,
20
18
 
21
- "phpmyadmin_post_start_script": false
19
+ "phpmyadmin_container_ip": "",
20
+ "phpmyadmin_os": "Ubuntu",
21
+ "phpmyadmin_version": "4.0.10deb1"
22
22
  }
@@ -9,5 +9,6 @@
9
9
 
10
10
  {
11
11
  "is_vagrant_installed?": false,
12
+ "is_virtualbox_installed?": false,
12
13
  "are_required_plugins_installed?": false
13
14
  }
@@ -9,5 +9,6 @@
9
9
 
10
10
  {
11
11
  "is_vagrant_installed?": false,
12
+ "is_virtualbox_installed?": false,
12
13
  "are_required_plugins_installed?": false
13
14
  }
@@ -0,0 +1,2 @@
1
+ class VirtualBoxNotInstalledError < StandardError
2
+ end
@@ -5,6 +5,7 @@ module CavalerieWeb
5
5
  class VagrantHelper
6
6
 
7
7
  def self.start_container container_name
8
+ puts "\n"
8
9
  puts Message.notice "Starting container \"#{container_name}\""
9
10
  long_vagrant_command "vagrant up #{container_name}"
10
11
  end
@@ -36,9 +37,7 @@ module CavalerieWeb
36
37
 
37
38
  def self.move_to_vagrant_folder
38
39
  vagrant_directory_path = "#{$gem_path}/lib/vagrant"
39
- if Dir.pwd != vagrant_directory_path
40
- Dir.chdir vagrant_directory_path
41
- end
40
+ Dir.chdir vagrant_directory_path
42
41
  end
43
42
 
44
43
  def self.vagrant_command command
@@ -20,11 +20,32 @@ module CavalerieWeb
20
20
  file_content = File.read virtualhost_file
21
21
  file_content.gsub! "_site_name_here_", site[:name]
22
22
 
23
- puts Message.notice "New #{site[:name]}'s VirtualHost file created."
23
+ File.open(virtualhost_file, 'w') { |file| file << file_content }
24
+
25
+ puts Message.notice "#{site[:name]}: VirtualHost file created."
26
+ end
27
+ end
28
+
29
+ def self.delete_virtualhost_file_if_invalid site
30
+ virtualhost_file = "#{site[:path]}/VirtualHost"
31
+ virtualhost_file_content = File.read virtualhost_file
32
+
33
+ unless virtualhost_file_content.include? site[:name]
34
+ File.delete virtualhost_file
35
+ puts Message.warning "#{site[:name]}: VirtualHost file was invalid and has been deleted."
36
+ end
37
+ end
38
+
39
+ def self.get_global_virtualhosts_file
40
+ virtualhost_file = "#{$configs_path}/sites_virtualhosts"
41
+ if File.exist? virtualhost_file
42
+ "\n#{File.read(virtualhost_file)}"
43
+ else
44
+ Message.warning "Apache virtualhosts file doesn't exist yet.\nDon't worry too much: it will be automatically\ncreated when you'll run 'cavalerie up'"
24
45
  end
25
46
  end
26
47
 
27
- def self.update_sites_virtualhosts_file
48
+ def self.update_global_virtualhosts_file
28
49
  virtualhost_file = "#{$configs_path}/sites_virtualhosts"
29
50
  File.open(virtualhost_file, 'w') do |file|
30
51
  SiteManager.get_all_sites.each do |site|
@@ -53,25 +74,27 @@ module CavalerieWeb
53
74
  local_config_file = "#{site[:path]}/local-config.php"
54
75
 
55
76
  unless File.exist? local_config_file
77
+ docker_configs = Config.get_docker_configs
56
78
  FileUtils.cp local_config_file_sample, local_config_file
57
- file_content = File.read local_config_file
58
- file_content.gsub! "_db_name_here_", site[:name]
59
- file_content.gsub! "_db_host_here_", ENV["DB_PORT_3306_TCP_ADDR"].to_s
79
+ local_config_file_content = File.read local_config_file
80
+
81
+ local_config_file_content.gsub! "_db_name_here_", "#{site[:name]}-dev"
82
+ local_config_file_content.gsub! "_db_host_here_", docker_configs["mysql-server_container_ip"]
83
+
84
+ File.open(local_config_file, 'w') { |file| file << local_config_file_content }
60
85
 
61
86
  puts Message.notice "New #{site[:name]}'s local-config.php file created."
62
87
  end
63
88
  end
64
89
 
65
- def self.update_local_config_files
66
- SiteManager.get_all_sites.each do |site|
67
- local_config_file = "#{site[:path]}/local-config.php"
68
-
69
- if File.exist? local_config_file
70
- File.delete local_config_file
71
- puts Message.notice "Previous #{site[:name]}'s local-config.php file deleted."
72
- end
90
+ def self.delete_local_config_file_if_invalid site
91
+ local_config_file = "#{site[:path]}/local-config.php"
92
+ local_config_file_content = File.read local_config_file
93
+ docker_configs = Config.get_docker_configs
73
94
 
74
- create_local_config_file_if_not_exist site
95
+ unless local_config_file_content.include?(site[:name]) && local_config_file_content.include?(docker_configs["mysql-server_container_ip"])
96
+ File.delete local_config_file
97
+ puts Message.warning "#{site[:name]}: local-config.php file was invalid and has been deleted."
75
98
  end
76
99
  end
77
100
 
@@ -24,23 +24,23 @@ module CavalerieWeb
24
24
 
25
25
  sequence_ended = true
26
26
 
27
- rescue StandardError => error
27
+ rescue StandardError => initial_error
28
28
  begin
29
29
 
30
- puts Message.warning "Error #{error.class}: #{error.message}\n\nCurrent path: #{Dir.pwd}\n\nBacktrace:\n\n" + error.backtrace.join("\n") + "\n\n"
30
+ puts Message.warning "Warning: #{initial_error.class}: #{initial_error.message}\n\nCurrent path: #{Dir.pwd}\n\nBacktrace:\n\n" + initial_error.backtrace.join("\n") + "\n\n"
31
31
 
32
32
  retry_counter += 1
33
- raise MaxRetriesReachError, "Sequence \"#{human_sequence_name}\" restarted #{max_retries} time(s) but never completed successfully" unless retry_counter < max_retries
33
+ raise MaxRetriesReachError, "Sequence \"#{human_sequence_name}\" restarted #{max_retries} time(s) but never completed successfully. Initial error was:\n\n\t#{initial_error.class}: #{initial_error.message}" unless retry_counter < max_retries
34
34
 
35
- puts Message.notice "Rescuing #{error.class} from sequence #{klass.to_s}"
35
+ puts Message.notice "Rescuing #{initial_error.class} from sequence #{klass.to_s}"
36
36
 
37
- klass.rescue error
37
+ klass.rescue initial_error
38
38
  next
39
39
 
40
40
  rescue StandardError => error
41
- Config.reset_setup_status
41
+ SetupManager.reset_setup_status
42
42
  sequence_ended = true
43
- abort Message.error "Failed to rescue: #{error.message}\n\nBacktrace:\n\n" + error.backtrace.join("\n")
43
+ abort Message.error "Failed to rescue error. #{error.message}\n\nBacktrace:\n\n" + error.backtrace.join("\n")
44
44
  end
45
45
 
46
46
  end
@@ -0,0 +1,123 @@
1
+ module CavalerieWeb
2
+
3
+ class SetupManager
4
+
5
+ # Initialization
6
+ def self.initialize_system
7
+ $sites_folder_path = ENV[Config.get_environment_variables[:sites][:name]]
8
+ $shared_folder_path = ENV[Config.get_environment_variables[:shared][:name]]
9
+ $mysql_folder_path = ENV[Config.get_environment_variables[:mysql][:name]]
10
+ $export_folder_path = ENV[Config.get_environment_variables[:export][:name]]
11
+ $credentials_folder_path = $shared_folder_path + "/_credentials"
12
+ $samples_folder_path = $shared_folder_path + "/_samples"
13
+ $db_dumps_folder_path = $shared_folder_path + "/_db_dumps"
14
+ end
15
+
16
+ def self.ask_for_root_privileges
17
+ run_sudo_command "echo 'Root access granted'"
18
+ end
19
+
20
+ def self.ensure_vagrant_is_installed
21
+ begin
22
+ raise VagrantNotInstalledError unless is_vagrant_installed?
23
+ update_setup_status "is_vagrant_installed?", true
24
+ rescue VagrantNotInstalledError
25
+ abort Message.error "Vagrant isn't installed. Please visit https://www.vagrantup.com for installation details."
26
+ end
27
+ end
28
+
29
+ def self.ensure_virtualbox_is_installed
30
+ begin
31
+ raise VirtualBoxNotInstalledError unless is_virtualbox_installed?
32
+ update_setup_status "is_virtualbox_installed?", true
33
+ rescue VirtualBoxNotInstalledError
34
+ abort Message.error "VirtualBox isn't installed. Please visit https://www.virtualbox.org/wiki/Downloads for installation details."
35
+ end
36
+ end
37
+
38
+ def self.ensure_required_plugins_are_installed
39
+ if missing_plugins = is_a_required_plugin_missing?
40
+ raise RequiredPluginMissingError, missing_plugins
41
+ else
42
+ update_setup_status "are_required_plugins_installed?", true
43
+ end
44
+ end
45
+
46
+ def self.ensure_environment_variables_are_set
47
+ unset_environment_variables = []
48
+ Config.get_environment_variables.each do |environment_variable|
49
+ unset_environment_variables << environment_variable[1][:name] unless ENV[environment_variable[1][:name]]
50
+ end
51
+
52
+ if unset_environment_variables.count > 0
53
+ abort Message.error "#{unset_environment_variables.count} environment variable(s) are unset. Please run \"cavalerie init\" to resolve this problem."
54
+ end
55
+ end
56
+
57
+ def self.ensure_required_folders_are_available
58
+ if missing_folders_paths = is_a_required_folder_unavailable?
59
+ raise RequiredFolderUnavailableError, missing_folders_paths
60
+ end
61
+ end
62
+
63
+ def self.get_setup_status
64
+ setup_status_file = File.read "#{$configs_path}/setup_status.json"
65
+ parsed = JSON.parse setup_status_file
66
+ end
67
+
68
+ def self.update_setup_status setup_status, value
69
+ setup_status_file = File.read "#{$configs_path}/setup_status.json"
70
+ parsed = JSON.parse setup_status_file
71
+ parsed[setup_status.to_s] = value
72
+ File.open("#{$configs_path}/setup_status.json", 'w') { |file| file << parsed.to_json }
73
+ end
74
+
75
+ def self.reset_setup_status
76
+ setup_status_file_default = "#{$configs_path}/setup_status.default.json"
77
+ setup_status_file = "#{$configs_path}/setup_status.json"
78
+ FileUtils.cp setup_status_file_default, setup_status_file
79
+ end
80
+
81
+ private
82
+
83
+ def self.is_vagrant_installed?
84
+ !File.which("vagrant").nil?
85
+ end
86
+
87
+ def self.is_virtualbox_installed?
88
+ !File.which("virtualbox").nil?
89
+ end
90
+
91
+ def self.is_a_required_plugin_missing?
92
+ missing_plugins = []
93
+
94
+ installed_plugins = VagrantHelper.plugin_list
95
+ Config.get_required_plugins_list.each do |plugin|
96
+ missing_plugins << plugin unless installed_plugins.include? plugin
97
+ end
98
+
99
+ missing_plugins unless missing_plugins.empty?
100
+ end
101
+
102
+ def self.is_a_required_folder_unavailable?
103
+ unavailable_folders = []
104
+
105
+ Config.get_required_folders_list.each do |folder_name|
106
+ folder_path = get_folder_path folder_name
107
+ unavailable_folders << folder_path unless File.directory? folder_path
108
+ end
109
+
110
+ unavailable_folders unless unavailable_folders.empty?
111
+ end
112
+
113
+ def self.get_folder_path folder_name
114
+ eval("$#{folder_name}_folder_path")
115
+ end
116
+
117
+ def self.run_sudo_command command
118
+ `sudo #{command}`
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -7,7 +7,14 @@ module CavalerieWeb
7
7
 
8
8
  site_paths = Dir.glob("#{get_sites_folder_path}/*").select { |f| File.directory? f }
9
9
  site_paths.each do |path|
10
- sites << { name: path.split("/").last, path: path }
10
+ site_name = path.split("/").last.downcase
11
+
12
+ sites << {
13
+ name: site_name,
14
+ path: path,
15
+ is_in_hosts_list: is_site_in_hosts_list?(site_name),
16
+ is_in_global_virtualhosts_file: is_site_in_global_virtualhosts_file?(site_name)
17
+ }
11
18
  end
12
19
 
13
20
  sites
@@ -20,13 +27,25 @@ module CavalerieWeb
20
27
  sites.each do |site|
21
28
  FileFolderManager.create_folder_if_not_exist "#{site[:path]}/logs"
22
29
  FileFolderManager.create_folder_if_not_exist "#{$shared_folder_path}/#{site[:name]}"
30
+ FileFolderManager.delete_virtualhost_file_if_invalid site
23
31
  FileFolderManager.create_virtualhost_file_if_not_exist site
32
+ FileFolderManager.delete_local_config_file_if_invalid site
24
33
  FileFolderManager.create_local_config_file_if_not_exist site
25
34
 
26
35
  puts Message.success "Site \"#{site[:name]}\" is valid"
27
36
  end
28
37
  end
29
38
 
39
+ def self.is_site_in_hosts_list? site_name
40
+ hosts_list = FileFolderManager.get_hosts_list
41
+ true if hosts_list.include? site_name
42
+ end
43
+
44
+ def self.is_site_in_global_virtualhosts_file? site_name
45
+ global_virtualhosts_file = FileFolderManager.get_global_virtualhosts_file
46
+ true if global_virtualhosts_file.include? site_name
47
+ end
48
+
30
49
  private
31
50
  def self.get_sites_folder_path
32
51
  $sites_folder_path
@@ -1,3 +1,5 @@
1
+ require 'ptools'
2
+
1
3
  module CavalerieWeb
2
4
 
3
5
  class VagrantManager
@@ -32,11 +34,23 @@ module CavalerieWeb
32
34
 
33
35
  def self.ensure_containers_are_running
34
36
  begin
35
- Config.get_containers_names.each do |container_name|
36
- raise ContainerNotRunningError, container_name unless get_container_status(container_name) == "running"
37
+ VagrantManager.get_containers_names.each do |container_name|
38
+ container_status = get_container_status container_name
39
+
40
+ timer = 0
41
+ max_timer = 30
42
+ while container_status == "preparing" && timer < max_timer
43
+ puts Message.notice "\"#{container_name}\" container is preparing. Waiting 2 seconds. (Current time: #{timer}s)"
44
+ sleep 2
45
+ timer += 2
46
+ container_status = get_container_status container_name
47
+ end
48
+
49
+ raise ContainerNotRunningError, { container_name: container_name, container_status: container_status } unless container_status == "running"
37
50
  end
38
51
  rescue ContainerNotRunningError => error
39
- abort Message.error "Container \"#{error.message}\" isn't running. Are you sure you have already run the command \"cavalerie up\"?\n\nIf the problem persists, this often means there is already another Vagrant virtual machine running in VirtualBox.\nPlease find and delete any virtual machine named \"Vagrant-Dockerhost\" in VirtualBox, and run \"cavalerie up\" again."
52
+ error_params = eval error.message
53
+ abort Message.error "Container \"#{error_params[:container_name]}\" isn't running.\n\n\t\"#{error_params[:container_name]}\" container status: #{error_params[:container_status]}\n\nAre you sure you have already run the command \"cavalerie up\"?\nIf the problem persists, this often means there is already another Vagrant virtual machine running in VirtualBox.\nPlease find and delete any virtual machine named \"Vagrant-Dockerhost\" in VirtualBox, and run \"cavalerie up\" again."
40
54
  end
41
55
  end
42
56
 
@@ -46,21 +60,61 @@ module CavalerieWeb
46
60
  end
47
61
 
48
62
  def self.start_containers
49
- Config.get_containers_names.each do |container_name|
63
+ VagrantManager.get_containers_names.each do |container_name|
50
64
  VagrantHelper.start_container container_name
51
-
52
- if Config.get_docker_configs["#{container_name}_post_start_script"]
53
- VagrantHelper.run_script container_name, "/scripts/post_start.rb"
54
- end
55
65
  end
56
66
  end
57
67
 
58
68
  def self.destroy_containers
59
- Config.get_containers_names.each do |container_name|
69
+ VagrantManager.get_containers_names.each do |container_name|
60
70
  VagrantHelper.destroy_container container_name unless get_container_status(container_name) == "not created"
61
71
  end
62
72
  end
63
73
 
74
+ def self.restart_container container_name
75
+ VagrantHelper.destroy_container container_name
76
+ VagrantHelper.start_container container_name
77
+ end
78
+
79
+ def self.get_containers_names
80
+ Config.get_docker_configs["containers_names"]
81
+ end
82
+
83
+ def self.get_container_info container_name
84
+ docker_configs = Config.get_docker_configs
85
+
86
+ container_info = {
87
+ ip: docker_configs["#{container_name}_container_ip"],
88
+ os: docker_configs["#{container_name}_os"],
89
+ version: docker_configs["#{container_name}_version"],
90
+ status: get_container_status(container_name),
91
+ others: get_container_other_info(container_name)
92
+ }
93
+ end
94
+
95
+ def self.get_all_containers_info
96
+ all_containers_info = {}
97
+ Config.get_docker_configs["containers_names"].each do |container_name|
98
+ all_containers_info[container_name] = VagrantManager.get_container_info container_name
99
+ end
100
+ all_containers_info
101
+ end
102
+
103
+ def self.get_container_other_info container_name
104
+ docker_configs = Config.get_docker_configs
105
+ others = {}
106
+
107
+ docker_configs.each do |docker_config_key, docker_config_value|
108
+ if docker_config_key.to_s.include? container_name
109
+ already_registered_config = ["#{container_name}_container_ip", "#{container_name}_os", "#{container_name}_version"]
110
+ is_an_other_key = already_registered_config.none? { |config| docker_config_key == config }
111
+ others[docker_config_key] = docker_config_value if is_an_other_key
112
+ end
113
+ end
114
+
115
+ others
116
+ end
117
+
64
118
  end
65
119
 
66
120
  end
@@ -4,7 +4,6 @@ module CavalerieWeb
4
4
 
5
5
  def self.start
6
6
  SequenceManager.start_sequence :ensure_setup_is_correct, 2
7
- CavalerieWeb.initialize_system
8
7
 
9
8
  VagrantManager.destroy_containers
10
9
  end
@@ -58,12 +58,15 @@ Let's begin:
58
58
  end
59
59
 
60
60
  def self.add_environment_variables_instructions variables_to_export_array
61
- puts "ONE MORE STEP!".colorize(:green)
62
- puts "\nTo complete the setup, please add the following variables to your shell profile\n(for example: ~/.bashrc for bash, ~/.zshrc for ZSH)\n\n"
61
+ puts "--------------------------------\nONE MORE STEP!".colorize(:green)
62
+ puts "\nTo complete the setup, please #{'add the following variables'.colorize(:green)} to your shell config\n(for example: ~/.bashrc for bash, ~/.zshrc for ZSH)\n\n"
63
63
 
64
64
  variables_to_export_array.each do |variables_to_export|
65
65
  puts "\t#{variables_to_export}".colorize(:yellow)
66
66
  end
67
+
68
+ puts "\nWhen it's done, #{'reload'.colorize(:green)} your shell (open another one or source your shell config file)."
69
+ puts "\n#{'/!\ CAUTION /!\\'.colorize(:red)}\nThe \"cavalerie up\" command #{'won\'t work'.colorize(:red)} until you add the variables to your shell config file."
67
70
  end
68
71
 
69
72
  end
@@ -3,18 +3,21 @@ module CavalerieWeb
3
3
  class CavalerieRefreshSequence < BaseSequence
4
4
 
5
5
  def self.start
6
+ SetupManager.ask_for_root_privileges
6
7
  SequenceManager.start_sequence :ensure_setup_is_correct, 2
7
- CavalerieWeb.initialize_system
8
8
  VagrantManager.ensure_containers_are_running
9
9
 
10
10
  # ------ Shared part with Cavalerie up sequence ------- #
11
11
  # TODO: factorize that
12
12
  SiteManager.ensure_sites_are_valid
13
- FileFolderManager.update_sites_virtualhosts_file
13
+ FileFolderManager.update_global_virtualhosts_file
14
14
  FileFolderManager.update_hosts_file
15
- FileFolderManager.update_local_config_files
16
- DatabaseManager.create_sites_database_if_not_exist
17
15
  # ------ Shared part with Cavalerie up sequence ------- #
16
+
17
+ DatabaseManager.create_sites_database_if_not_exist
18
+
19
+ VagrantManager.restart_container "apache-server"
20
+ VagrantManager.ensure_containers_are_running
18
21
  end
19
22
 
20
23
  end
@@ -3,70 +3,41 @@ module CavalerieWeb
3
3
  class CavalerieStatusSequence < BaseSequence
4
4
 
5
5
  def self.start
6
-
6
+ SetupManager.ask_for_root_privileges
7
7
  SequenceManager.start_sequence :ensure_setup_is_correct, 2
8
- CavalerieWeb.initialize_system
9
-
10
- docker_configs = Config.get_docker_configs
11
-
12
- apache_status = colorize_status VagrantManager.get_container_status docker_configs["apache-server_container_name"]
13
- mysql_status = colorize_status VagrantManager.get_container_status docker_configs["mysql-server_container_name"]
14
8
 
15
- virtualhosts_content = get_virtualhosts_content
9
+ puts Message.notice "Gathering informations: please wait..."
16
10
 
17
- hosts_file_content = FileFolderManager.get_hosts_list
18
-
19
- site_list_array = get_site_list hosts_file_content, virtualhosts_content
20
- site_list = ""
21
-
22
- site_list_array.each_with_index do |site, index|
23
- site_list += "\t#{index + 1}. #{site[:name].colorize(:light_blue)}\n"
24
- site_list += "\t\t\t- URL: #{site[:url]}\n"
25
- site_list += "\t\t\t- Is in virtualhost? #{site[:virtualhost]}\n\n"
26
- end
27
-
28
- print <<-EOF
29
-
30
- ------------------------------------------------------------------------------------------------------------------
31
- | \t#{"SYSTEM STATUS SUMMARY".colorize(:yellow)} |
32
- ------------------------------------------------------------------------------------------------------------------
11
+ docker_configs = Config.get_docker_configs
12
+ containers_names = docker_configs["containers_names"]
13
+ global_virtualhosts_file = FileFolderManager.get_global_virtualhosts_file
14
+ sites = SiteManager.get_all_sites
33
15
 
34
- \tApache server
35
- \t\t\t - Container status #{apache_status}
36
- \t\t\t - Container name #{docker_configs["containers_names"][1]}
37
- \t\t\t - Container IP #{docker_configs["apache-server_container_ip"]}
38
- \t\t\t - Machine OS #{docker_configs["apache-server_os"]}
39
- \t\t\t - Apache version #{docker_configs["apache-server_version"]}
16
+ puts "\n -----------------------------------------------------------------------------------------------"
17
+ printf "|\t %-100s %s\n", "DOCKER CONTAINERS STATUS".colorize(:yellow), "|"
18
+ puts " -----------------------------------------------------------------------------------------------"
40
19
 
41
- \tMySQL server
42
- \t\t\t - Container status #{mysql_status}
43
- \t\t\t - Container name #{docker_configs["containers_names"][0]}
44
- \t\t\t - Container IP #{docker_configs["mysql-server_container_ip"]}
45
- \t\t\t - Machine OS #{docker_configs["mysql-server_os"]}
46
- \t\t\t - MySQL version #{docker_configs["mysql-server_version"]}
47
- \t\t\t - MySQL user / pass #{docker_configs["mysql-server_user"]} / #{docker_configs["mysql-server_user_password"]}
48
- \t\t\t - MySQL root pass #{docker_configs["mysql-server_root_password"]}
20
+ display_containers_section containers_names
49
21
 
50
- \tFolders paths
51
- \t\t\t - Sites #{$sites_folder_path}
52
- \t\t\t - Shared #{$shared_folder_path}
53
- \t\t\t - MySQL #{$mysql_folder_path}
54
- \t\t\t - Export #{$export_folder_path}
22
+ puts "\n -----------------------------------------------------------------------------------------------"
23
+ printf "|\t %-100s %s\n", "SITES AVAILABLE".colorize(:light_blue), "|"
24
+ puts " -----------------------------------------------------------------------------------------------"
55
25
 
56
- \tSites in sites folder
26
+ display_sites_section sites
57
27
 
58
- #{site_list}
59
- ------------------------------------------------------------------------------------------------------------------
60
- | \t#{"MORE DETAILS".colorize(:yellow)} |
61
- ------------------------------------------------------------------------------------------------------------------
28
+ puts "\n -----------------------------------------------------------------------------------------------"
29
+ printf "|\t %-100s %s\n", "FOLDERS REGISTERED".colorize(:light_blue), "|"
30
+ puts " -----------------------------------------------------------------------------------------------"
62
31
 
63
- Apache virtualhosts file content
32
+ display_folders_section
64
33
 
65
- #{virtualhosts_content}
34
+ puts "\n -----------------------------------------------------------------------------------------------"
35
+ printf "|\t %-100s %s\n", "APACHE VIRTUALHOSTS".colorize(:light_blue), "|"
36
+ puts " -----------------------------------------------------------------------------------------------"
66
37
 
67
- ------------------------------------------------------------------------------------------------------------------
38
+ global_virtualhosts_file
68
39
 
69
- EOF
40
+ puts "\n------------------------------------------------------------------------------------------------------------------\n\n"
70
41
  end
71
42
 
72
43
  private
@@ -82,25 +53,45 @@ module CavalerieWeb
82
53
  end
83
54
  end
84
55
 
85
- def self.get_virtualhosts_content
86
- virtualhost_file = "#{$configs_path}/sites_virtualhosts"
87
- if File.exist? virtualhost_file
88
- "\n#{File.read(virtualhost_file)}"
89
- else
90
- Message.warning "Apache virtualhosts file doesn't exist yet.\nDon't worry too much: it will be automatically\ncreated when you'll run 'cavalerie up'"
56
+ def self.display_containers_section containers_names
57
+ all_containers_info = VagrantManager.get_all_containers_info
58
+
59
+ containers_names.each do |container_name|
60
+
61
+ puts "\n"
62
+ puts "\t#{container_name.colorize(:yellow)}"
63
+
64
+ all_containers_info[container_name].each do |info_key, info_value|
65
+ # TODO: find a way to test the following "if" section
66
+ if info_key === :status
67
+ printf "\t\t - %-30s %s\n", info_key, colorize_status(info_value)
68
+ elsif info_key != :others
69
+ printf "\t\t - %-30s %s\n", info_key, info_value
70
+ else
71
+ info_value.each do |other_key, other_value|
72
+ printf "\t\t - %-30s %s\n", other_key, other_value
73
+ end
74
+ end
75
+ end
91
76
  end
92
77
  end
93
78
 
94
- def self.get_site_list hosts_file_content, virtualhosts_content
95
- site_list = []
96
-
97
- SiteManager.get_all_sites.each_with_index do |site, index|
98
- site_url = hosts_file_content.include?(site[:name]) ? "http://#{site[:name]}.dev".colorize(:green) : "Not found in Hosts file".colorize(:red)
99
- site_in_virtualhost = virtualhosts_content.include?(site[:name]) ? "Yes".colorize(:green) : "No".colorize(:red)
79
+ def self.display_folders_section
80
+ puts "\n"
81
+ printf "\t%-20s %s\n", "Sites", $sites_folder_path
82
+ printf "\t%-20s %s\n", "Shared", $shared_folder_path
83
+ printf "\t%-20s %s\n", "MySQL", $mysql_folder_path
84
+ printf "\t%-20s %s\n", "Export", $export_folder_path
85
+ end
100
86
 
101
- site_list << { name: site[:name], url: site_url, virtualhost: site_in_virtualhost }
87
+ def self.display_sites_section sites
88
+ sites.each do |site|
89
+ puts "\n"
90
+ printf "\t#{site[:name].colorize(:light_blue)}\n"
91
+ printf "\t\t- %-20s %s\n", "URL:", "http://#{site[:name]}.dev:8080"
92
+ printf "\t\t- %-20s %s\n", "In virtualhost?", site[:is_in_global_virtualhosts_file]
93
+ printf "\t\t- %-20s %s\n", "Is in hosts file?", site[:is_in_hosts_list]
102
94
  end
103
- site_list
104
95
  end
105
96
 
106
97
  end
@@ -3,21 +3,23 @@ module CavalerieWeb
3
3
  class CavalerieUpSequence < BaseSequence
4
4
 
5
5
  def self.start
6
+ SetupManager.ask_for_root_privileges
6
7
  SequenceManager.start_sequence :ensure_setup_is_correct, 2
7
- CavalerieWeb.initialize_system
8
8
 
9
9
  # ------ Shared part with Cavalerie refresh sequence ------- #
10
10
  # TODO: factorize that
11
11
  SiteManager.ensure_sites_are_valid
12
- FileFolderManager.update_sites_virtualhosts_file
12
+ FileFolderManager.update_global_virtualhosts_file
13
13
  FileFolderManager.update_hosts_file
14
- FileFolderManager.update_local_config_files
15
14
  # ------ Shared part with Cavalerie refresh sequence ------- #
16
15
 
17
16
  VagrantManager.start_or_restart_containers
18
17
  VagrantManager.ensure_containers_are_running
19
18
 
20
19
  DatabaseManager.create_sites_database_if_not_exist
20
+
21
+ puts "\n"
22
+ puts Message.success "Everything is awesome! (https://youtu.be/cCKONHUigVk)\n Happy coding! :)\n"
21
23
  end
22
24
 
23
25
  end
@@ -5,22 +5,28 @@ module CavalerieWeb
5
5
  def self.start
6
6
  threads = []
7
7
 
8
- CavalerieWeb.initialize_system
8
+ SetupManager.initialize_system
9
9
 
10
- setup_status = Config.get_setup_status
10
+ setup_status = SetupManager.get_setup_status
11
11
 
12
12
  if setup_status["is_vagrant_installed?"] != true
13
- threads << Thread.new { ensure_vagrant_is_installed }
13
+ threads << Thread.new { SetupManager.ensure_vagrant_is_installed }
14
+ end
15
+
16
+ if setup_status["is_virtualbox_installed?"] != true
17
+ threads << Thread.new { SetupManager.ensure_virtualbox_is_installed }
14
18
  end
15
19
 
16
20
  if setup_status["are_required_plugins_installed?"] != true
17
- threads << Thread.new { ensure_required_plugins_are_installed }
21
+ threads << Thread.new { SetupManager.ensure_required_plugins_are_installed }
18
22
  end
19
23
 
20
- threads << Thread.new { ensure_environment_variables_are_set }
21
- threads << Thread.new { ensure_required_folders_are_available }
24
+ threads << Thread.new { SetupManager.ensure_environment_variables_are_set }
25
+ threads << Thread.new { SetupManager.ensure_required_folders_are_available }
22
26
 
23
27
  SequenceManager.set_threads_timeout threads
28
+
29
+ puts Message.success "Setup is correct."
24
30
  end
25
31
 
26
32
  def self.rescue error
@@ -32,6 +38,7 @@ module CavalerieWeb
32
38
  puts Message.warning "Plugin \"#{plugin_name.capitalize}\" is not installed. Installing..."
33
39
  VagrantHelper.plugin_install plugin_name
34
40
  end
41
+
35
42
  when "RequiredFolderUnavailableError"
36
43
  missing_folders_paths = eval(error.message)
37
44
  puts Message.warning error_message = "#{missing_folders_paths.count} required folder(s) are missing"
@@ -41,39 +48,6 @@ module CavalerieWeb
41
48
  end
42
49
  end
43
50
 
44
- private
45
-
46
- def self.ensure_vagrant_is_installed
47
- begin
48
- raise VagrantNotInstalledError unless VagrantCheck.is_vagrant_installed?
49
- rescue VagrantNotInstalledError
50
- abort Message.error "Vagrant isn't installed. Please visit https://www.vagrantup.com for installation details."
51
- end
52
- end
53
-
54
- def self.ensure_required_plugins_are_installed
55
- if missing_plugins = VagrantCheck.is_a_required_plugin_missing?
56
- raise RequiredPluginMissingError, missing_plugins
57
- end
58
- end
59
-
60
- def self.ensure_environment_variables_are_set
61
- unset_environment_variables = []
62
- Config.get_environment_variables.each do |environment_variable|
63
- unset_environment_variables << environment_variable[1][:name] unless ENV[environment_variable[1][:name]]
64
- end
65
-
66
- if unset_environment_variables.count > 0
67
- abort Message.error "#{unset_environment_variables.count} environment variable(s) are unset. Please run \"cavalerie init\" to resolve this problem."
68
- end
69
- end
70
-
71
- def self.ensure_required_folders_are_available
72
- if missing_folders_paths = FileFolderCheck.is_a_required_folder_unavailable?
73
- raise RequiredFolderUnavailableError, missing_folders_paths
74
- end
75
- end
76
-
77
51
  end
78
52
 
79
53
  end
@@ -53,6 +53,7 @@ Vagrant.configure("2") do |config|
53
53
  d.name = "#{apache_container_name}"
54
54
  d.link("#{mysql_container_name}:db")
55
55
  d.volumes = ["/cavalerie/sites:/cavalerie/sites", "/cavalerie/shared:/cavalerie/shared", "/cavalerie/configs:/cavalerie/configs"]
56
+ d.cmd = ["/scripts/setup.rb"]
56
57
  d.remains_running = true
57
58
  d.vagrant_machine = "#{DOCKER_HOST_NAME}"
58
59
  d.vagrant_vagrantfile = "#{DOCKER_HOST_VAGRANTFILE}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cavalerie_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lenglet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -196,16 +196,16 @@ dependencies:
196
196
  name: codeclimate-test-reporter
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '0'
201
+ version: '0.4'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ">="
206
+ - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: '0.4'
209
209
  description: Contain everything your need to create and manage websites
210
210
  email:
211
211
  - arlenglet@gmail.com
@@ -227,17 +227,13 @@ files:
227
227
  - bin/cavalerie
228
228
  - cavalerie_web.gemspec
229
229
  - lib/cavalerie_web.rb
230
- - lib/cavalerie_web/checks/file_folder_check.rb
231
- - lib/cavalerie_web/checks/vagrant_check.rb
232
230
  - lib/cavalerie_web/cli/command.rb
233
231
  - lib/cavalerie_web/cli/subcommands/new.rb
234
232
  - lib/cavalerie_web/cli/subcommands/server.rb
235
233
  - lib/cavalerie_web/configs/VirtualHost.sample
236
- - lib/cavalerie_web/configs/apache_container_ip
237
234
  - lib/cavalerie_web/configs/config.rb
238
235
  - lib/cavalerie_web/configs/docker_configs.json
239
236
  - lib/cavalerie_web/configs/local-config.sample.php
240
- - lib/cavalerie_web/configs/mysql_container_ip
241
237
  - lib/cavalerie_web/configs/setup_status.default.json
242
238
  - lib/cavalerie_web/configs/setup_status.json
243
239
  - lib/cavalerie_web/errors/container_not_running_error.rb
@@ -250,12 +246,14 @@ files:
250
246
  - lib/cavalerie_web/errors/vagrant_not_installed_error.rb
251
247
  - lib/cavalerie_web/errors/vagrant_vm_already_running_error.rb
252
248
  - lib/cavalerie_web/errors/vagrant_vm_not_running_error.rb
249
+ - lib/cavalerie_web/errors/virtual_box_not_installed_error.rb
253
250
  - lib/cavalerie_web/errors/virtual_host_file_not_found_error.rb
254
251
  - lib/cavalerie_web/helpers/os_helper.rb
255
252
  - lib/cavalerie_web/helpers/vagrant_helper.rb
256
253
  - lib/cavalerie_web/managers/database_manager.rb
257
254
  - lib/cavalerie_web/managers/file_folder_manager.rb
258
255
  - lib/cavalerie_web/managers/sequence_manager.rb
256
+ - lib/cavalerie_web/managers/setup_manager.rb
259
257
  - lib/cavalerie_web/managers/site_manager.rb
260
258
  - lib/cavalerie_web/managers/vagrant_manager.rb
261
259
  - lib/cavalerie_web/sequences/base_sequence.rb
@@ -1,23 +0,0 @@
1
- module CavalerieWeb
2
-
3
- class FileFolderCheck
4
-
5
- def self.is_a_required_folder_unavailable?
6
- unavailable_folders = []
7
-
8
- Config.get_required_folders_list.each do |folder_name|
9
- folder_path = get_folder_path folder_name
10
- unavailable_folders << folder_path unless File.directory? folder_path
11
- end
12
-
13
- unavailable_folders unless unavailable_folders.empty?
14
- end
15
-
16
- private
17
- def self.get_folder_path folder_name
18
- eval("$#{folder_name}_folder_path")
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,24 +0,0 @@
1
- require 'ptools'
2
-
3
- module CavalerieWeb
4
-
5
- class VagrantCheck
6
-
7
- def self.is_vagrant_installed?
8
- !File.which("vagrant").nil?
9
- end
10
-
11
- def self.is_a_required_plugin_missing?
12
- missing_plugins = []
13
-
14
- installed_plugins = VagrantHelper.plugin_list
15
- Config.get_required_plugins_list.each do |plugin|
16
- missing_plugins << plugin unless installed_plugins.include? plugin
17
- end
18
-
19
- missing_plugins unless missing_plugins.empty?
20
- end
21
-
22
- end
23
-
24
- end
@@ -1 +0,0 @@
1
- 172.17.0.5
@@ -1 +0,0 @@
1
- 172.17.0.1