cavalerie_web 1.0.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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Guardfile +77 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/cavalerie +5 -0
- data/cavalerie_web.gemspec +39 -0
- data/lib/cavalerie_web/checks/file_folder_check.rb +23 -0
- data/lib/cavalerie_web/checks/vagrant_check.rb +24 -0
- data/lib/cavalerie_web/cli/command.rb +37 -0
- data/lib/cavalerie_web/cli/subcommands/new.rb +13 -0
- data/lib/cavalerie_web/cli/subcommands/server.rb +23 -0
- data/lib/cavalerie_web/configs/VirtualHost.sample +8 -0
- data/lib/cavalerie_web/configs/apache_container_ip +1 -0
- data/lib/cavalerie_web/configs/config.rb +55 -0
- data/lib/cavalerie_web/configs/docker_configs.json +22 -0
- data/lib/cavalerie_web/configs/local-config.sample.php +15 -0
- data/lib/cavalerie_web/configs/mysql_container_ip +1 -0
- data/lib/cavalerie_web/configs/setup_status.default.json +13 -0
- data/lib/cavalerie_web/configs/setup_status.json +13 -0
- data/lib/cavalerie_web/errors/container_not_running_error.rb +2 -0
- data/lib/cavalerie_web/errors/logs_folder_not_found_error.rb +2 -0
- data/lib/cavalerie_web/errors/max_retries_reach_error.rb +2 -0
- data/lib/cavalerie_web/errors/required_folder_unavailable_error.rb +2 -0
- data/lib/cavalerie_web/errors/required_plugin_missing_error.rb +2 -0
- data/lib/cavalerie_web/errors/unable_to_access_hosts_file_on_windows_os_error.rb +2 -0
- data/lib/cavalerie_web/errors/unknown_docker_container_status_error.rb +2 -0
- data/lib/cavalerie_web/errors/vagrant_not_installed_error.rb +2 -0
- data/lib/cavalerie_web/errors/vagrant_vm_already_running_error.rb +2 -0
- data/lib/cavalerie_web/errors/vagrant_vm_not_running_error.rb +2 -0
- data/lib/cavalerie_web/errors/virtual_host_file_not_found_error.rb +2 -0
- data/lib/cavalerie_web/helpers/os_helper.rb +9 -0
- data/lib/cavalerie_web/helpers/vagrant_helper.rb +73 -0
- data/lib/cavalerie_web/managers/database_manager.rb +10 -0
- data/lib/cavalerie_web/managers/file_folder_manager.rb +99 -0
- data/lib/cavalerie_web/managers/sequence_manager.rb +97 -0
- data/lib/cavalerie_web/managers/site_manager.rb +37 -0
- data/lib/cavalerie_web/managers/vagrant_manager.rb +66 -0
- data/lib/cavalerie_web/sequences/base_sequence.rb +9 -0
- data/lib/cavalerie_web/sequences/cavalerie_destroy_sequence.rb +12 -0
- data/lib/cavalerie_web/sequences/cavalerie_init_sequence.rb +71 -0
- data/lib/cavalerie_web/sequences/cavalerie_refresh_sequence.rb +21 -0
- data/lib/cavalerie_web/sequences/cavalerie_status_sequence.rb +107 -0
- data/lib/cavalerie_web/sequences/cavalerie_up_sequence.rb +24 -0
- data/lib/cavalerie_web/sequences/ensure_setup_is_correct_sequence.rb +77 -0
- data/lib/cavalerie_web/ui/banner.rb +16 -0
- data/lib/cavalerie_web/ui/message.rb +23 -0
- data/lib/cavalerie_web.rb +37 -0
- data/lib/vagrant/DockerHost.Vagrantfile +31 -0
- data/lib/vagrant/Vagrantfile +74 -0
- data/lib/vagrant/scripts/new_website.rb +54 -0
- metadata +283 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module CavalerieWeb
|
4
|
+
|
5
|
+
class FileFolderManager
|
6
|
+
|
7
|
+
def self.create_folder_if_not_exist path
|
8
|
+
unless File.directory? path
|
9
|
+
FileUtils.mkdir_p path
|
10
|
+
puts Message.warning "Folder didn't exist and was created: #{path}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create_virtualhost_file_if_not_exist site
|
15
|
+
virtualhost_file_sample = "#{$configs_path}/VirtualHost.sample"
|
16
|
+
virtualhost_file = "#{site[:path]}/VirtualHost"
|
17
|
+
|
18
|
+
unless File.exist? virtualhost_file
|
19
|
+
FileUtils.cp virtualhost_file_sample, virtualhost_file
|
20
|
+
file_content = File.read virtualhost_file
|
21
|
+
file_content.gsub! "_site_name_here_", site[:name]
|
22
|
+
|
23
|
+
puts Message.notice "New #{site[:name]}'s VirtualHost file created."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.update_sites_virtualhosts_file
|
28
|
+
virtualhost_file = "#{$configs_path}/sites_virtualhosts"
|
29
|
+
File.open(virtualhost_file, 'w') do |file|
|
30
|
+
SiteManager.get_all_sites.each do |site|
|
31
|
+
file.write File.read(site[:path] + "/VirtualHost") + "\n\n"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts Message.notice "Apache virtualhosts updated."
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.update_hosts_file
|
39
|
+
# Display warning message on Windows since we can't yet update hosts file on Windows
|
40
|
+
if OSHelper.is_windows?
|
41
|
+
puts Message.warning "Windows OS detected. Unable to auto-update hosts file. Please update manually."
|
42
|
+
else
|
43
|
+
clean_up_hosts_file
|
44
|
+
SiteManager.get_all_sites.each do |site|
|
45
|
+
ghost_command "add #{site[:name]}.dev"
|
46
|
+
end
|
47
|
+
puts Message.notice "Hosts file updated."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.create_local_config_file_if_not_exist site
|
52
|
+
local_config_file_sample = "#{$configs_path}/local-config.sample.php"
|
53
|
+
local_config_file = "#{site[:path]}/local-config.php"
|
54
|
+
|
55
|
+
unless File.exist? local_config_file
|
56
|
+
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
|
60
|
+
|
61
|
+
puts Message.notice "New #{site[:name]}'s local-config.php file created."
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
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
|
73
|
+
|
74
|
+
create_local_config_file_if_not_exist site
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.clean_up_hosts_file
|
79
|
+
ghost_command "bust"
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.get_hosts_list
|
83
|
+
begin
|
84
|
+
raise UnableToAccessHostsFileOnWindowsOSError if OSHelper.is_windows?
|
85
|
+
ghost_command "list"
|
86
|
+
rescue UnableToAccessHostsFileOnWindowsOSError
|
87
|
+
puts Message.error "Windows OS detected. Unable to access hosts file."
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def self.ghost_command command
|
94
|
+
`sudo ghost #{command}`
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class SequenceManager
|
4
|
+
|
5
|
+
def self.start_sequence sequence_name, max_retries=1
|
6
|
+
Dir.chdir $gem_path
|
7
|
+
|
8
|
+
klass = Object.const_get(format_to_sequence_class(sequence_name))
|
9
|
+
human_sequence_name = format_for_human sequence_name
|
10
|
+
retry_counter = 0
|
11
|
+
sequence_ended = false
|
12
|
+
|
13
|
+
while !sequence_ended
|
14
|
+
begin
|
15
|
+
Dir.chdir $gem_path
|
16
|
+
|
17
|
+
if retry_counter == 0
|
18
|
+
puts Message.notice "Starting sequence \"#{human_sequence_name}\""
|
19
|
+
else
|
20
|
+
puts Message.notice "Restarting sequence \"#{human_sequence_name}\" (try: #{retry_counter + 1})"
|
21
|
+
end
|
22
|
+
|
23
|
+
klass.start
|
24
|
+
|
25
|
+
sequence_ended = true
|
26
|
+
|
27
|
+
rescue StandardError => error
|
28
|
+
begin
|
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"
|
31
|
+
|
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
|
34
|
+
|
35
|
+
puts Message.notice "Rescuing #{error.class} from sequence #{klass.to_s}"
|
36
|
+
|
37
|
+
klass.rescue error
|
38
|
+
next
|
39
|
+
|
40
|
+
rescue StandardError => error
|
41
|
+
Config.reset_setup_status
|
42
|
+
sequence_ended = true
|
43
|
+
abort Message.error "Failed to rescue: #{error.message}\n\nBacktrace:\n\n" + error.backtrace.join("\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.set_threads_timeout threads_array, timeout = 15
|
51
|
+
time = 0
|
52
|
+
|
53
|
+
while threads_array.count > 0
|
54
|
+
|
55
|
+
if time < timeout
|
56
|
+
sleep 1
|
57
|
+
time += 1
|
58
|
+
time_left = timeout - time
|
59
|
+
|
60
|
+
if time === 3
|
61
|
+
puts Message.warning "It's seems to take longer than usual..."
|
62
|
+
end
|
63
|
+
|
64
|
+
if time > 4 && time_left > 0
|
65
|
+
puts Message.warning "#{timeout - time} second(s) left before timeout"
|
66
|
+
end
|
67
|
+
|
68
|
+
threads_array.delete_if do |thread|
|
69
|
+
thread.status == false
|
70
|
+
end
|
71
|
+
|
72
|
+
else
|
73
|
+
puts Message.error "Timout. #{threads_array.count} thread(s) not finished in time.\n\nThreads: #{threads_array}"
|
74
|
+
|
75
|
+
threads_array.each do |thread|
|
76
|
+
thread.kill
|
77
|
+
end
|
78
|
+
threads_array.clear
|
79
|
+
|
80
|
+
abort
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def self.format_to_sequence_class sequence_name
|
88
|
+
"CavalerieWeb::" + sequence_name.to_s.downcase.split(/[_\ ]/).map { |word| word.capitalize }.join + "Sequence"
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.format_for_human sequence_name
|
92
|
+
sequence_name.to_s.gsub('_', ' ').capitalize
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class SiteManager
|
4
|
+
|
5
|
+
def self.get_all_sites
|
6
|
+
sites = []
|
7
|
+
|
8
|
+
site_paths = Dir.glob("#{get_sites_folder_path}/*").select { |f| File.directory? f }
|
9
|
+
site_paths.each do |path|
|
10
|
+
sites << { name: path.split("/").last, path: path }
|
11
|
+
end
|
12
|
+
|
13
|
+
sites
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ensure_sites_are_valid
|
17
|
+
sites = get_all_sites
|
18
|
+
puts Message.warning "#{sites.count} site(s) found in sites folder"
|
19
|
+
|
20
|
+
sites.each do |site|
|
21
|
+
FileFolderManager.create_folder_if_not_exist "#{site[:path]}/logs"
|
22
|
+
FileFolderManager.create_folder_if_not_exist "#{$shared_folder_path}/#{site[:name]}"
|
23
|
+
FileFolderManager.create_virtualhost_file_if_not_exist site
|
24
|
+
FileFolderManager.create_local_config_file_if_not_exist site
|
25
|
+
|
26
|
+
puts Message.success "Site \"#{site[:name]}\" is valid"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def self.get_sites_folder_path
|
32
|
+
$sites_folder_path
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class VagrantManager
|
4
|
+
|
5
|
+
def self.get_container_status container_name
|
6
|
+
status = VagrantHelper.status(container_name)
|
7
|
+
|
8
|
+
begin
|
9
|
+
case status
|
10
|
+
when /not created \(docker\)/
|
11
|
+
"not created"
|
12
|
+
when /running \(docker\)/
|
13
|
+
"running"
|
14
|
+
when /saved \(docker\)/
|
15
|
+
"saved"
|
16
|
+
when /preparing \(docker\)/
|
17
|
+
"preparing"
|
18
|
+
when /poweroff \(docker\)/
|
19
|
+
"poweroff"
|
20
|
+
when /stopped \(docker\)/
|
21
|
+
"stopped"
|
22
|
+
when /host state unknown \(docker\)/
|
23
|
+
"host state unknown"
|
24
|
+
else
|
25
|
+
raise UnknownDockerContainerStatusError, status
|
26
|
+
end
|
27
|
+
rescue UnknownDockerContainerStatusError => error
|
28
|
+
abort Message.error "The container #{container_name} is in an unknown state.\n\nVagrant status command output:\n\n#{error.message}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.ensure_containers_are_running
|
34
|
+
begin
|
35
|
+
Config.get_containers_names.each do |container_name|
|
36
|
+
raise ContainerNotRunningError, container_name unless get_container_status(container_name) == "running"
|
37
|
+
end
|
38
|
+
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."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.start_or_restart_containers
|
44
|
+
destroy_containers
|
45
|
+
start_containers
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.start_containers
|
49
|
+
Config.get_containers_names.each do |container_name|
|
50
|
+
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
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.destroy_containers
|
59
|
+
Config.get_containers_names.each do |container_name|
|
60
|
+
VagrantHelper.destroy_container container_name unless get_container_status(container_name) == "not created"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class CavalerieInitSequence < BaseSequence
|
4
|
+
|
5
|
+
def self.start
|
6
|
+
welcome_message
|
7
|
+
|
8
|
+
variables_to_export = []
|
9
|
+
|
10
|
+
Config.get_environment_variables.each_with_index do |environment_variable, index|
|
11
|
+
|
12
|
+
name = environment_variable[1][:name]
|
13
|
+
folder = environment_variable[1][:folder]
|
14
|
+
description = environment_variable[1][:description]
|
15
|
+
default_folder_path = "#{ENV['HOME']}/cavalerie/#{folder}"
|
16
|
+
|
17
|
+
puts "\n#{index + 1}. Which location for \"#{folder.colorize(:yellow)}\" folder? (default: #{default_folder_path})"
|
18
|
+
puts description
|
19
|
+
print "\n#{name}: "
|
20
|
+
path = $stdin.gets.chomp
|
21
|
+
puts "\n"
|
22
|
+
|
23
|
+
if path.empty?
|
24
|
+
variables_to_export << "export #{name}=#{default_folder_path}"
|
25
|
+
FileFolderManager.create_folder_if_not_exist default_folder_path
|
26
|
+
else
|
27
|
+
path.gsub!('~', ENV['HOME'])
|
28
|
+
variables_to_export << "export #{name}=#{path}"
|
29
|
+
FileFolderManager.create_folder_if_not_exist path
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
add_environment_variables_instructions variables_to_export
|
35
|
+
|
36
|
+
puts "\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.welcome_message
|
42
|
+
puts <<-EOF
|
43
|
+
|
44
|
+
Hello, and if it's your first run, welcome!
|
45
|
+
|
46
|
+
This gem is designed to help you improve your productivity when developping with Wordpress.
|
47
|
+
Your new development environment will be composed of:
|
48
|
+
|
49
|
+
√ Vagrant Linux virtual machine
|
50
|
+
√ Apache Docker container for your webserver
|
51
|
+
√ MySQL server Docker container for your database
|
52
|
+
|
53
|
+
Everything is almost done automatically, so you don't have to worry about configuration.
|
54
|
+
|
55
|
+
Let's begin:
|
56
|
+
|
57
|
+
EOF
|
58
|
+
end
|
59
|
+
|
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"
|
63
|
+
|
64
|
+
variables_to_export_array.each do |variables_to_export|
|
65
|
+
puts "\t#{variables_to_export}".colorize(:yellow)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class CavalerieRefreshSequence < BaseSequence
|
4
|
+
|
5
|
+
def self.start
|
6
|
+
SequenceManager.start_sequence :ensure_setup_is_correct, 2
|
7
|
+
VagrantManager.ensure_containers_are_running
|
8
|
+
|
9
|
+
# ------ Shared part with Cavalerie up sequence ------- #
|
10
|
+
# TODO: factorize that
|
11
|
+
SiteManager.ensure_sites_are_valid
|
12
|
+
FileFolderManager.update_sites_virtualhosts_file
|
13
|
+
FileFolderManager.update_hosts_file
|
14
|
+
FileFolderManager.update_local_config_files
|
15
|
+
DatabaseManager.create_sites_database_if_not_exist
|
16
|
+
# ------ Shared part with Cavalerie up sequence ------- #
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class CavalerieStatusSequence < BaseSequence
|
4
|
+
|
5
|
+
def self.start
|
6
|
+
|
7
|
+
SequenceManager.start_sequence :ensure_setup_is_correct, 2
|
8
|
+
|
9
|
+
docker_configs = Config.get_docker_configs
|
10
|
+
|
11
|
+
apache_status = colorize_status VagrantManager.get_container_status docker_configs["apache-server_container_name"]
|
12
|
+
mysql_status = colorize_status VagrantManager.get_container_status docker_configs["mysql-server_container_name"]
|
13
|
+
|
14
|
+
virtualhosts_content = get_virtualhosts_content
|
15
|
+
|
16
|
+
hosts_file_content = FileFolderManager.get_hosts_list
|
17
|
+
|
18
|
+
site_list_array = get_site_list hosts_file_content, virtualhosts_content
|
19
|
+
site_list = ""
|
20
|
+
|
21
|
+
site_list_array.each_with_index do |site, index|
|
22
|
+
site_list += "\t#{index + 1}. #{site[:name].colorize(:light_blue)}\n"
|
23
|
+
site_list += "\t\t\t- URL: #{site[:url]}\n"
|
24
|
+
site_list += "\t\t\t- Is in virtualhost? #{site[:virtualhost]}\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
print <<-EOF
|
28
|
+
|
29
|
+
------------------------------------------------------------------------------------------------------------------
|
30
|
+
| \t#{"SYSTEM STATUS SUMMARY".colorize(:yellow)} |
|
31
|
+
------------------------------------------------------------------------------------------------------------------
|
32
|
+
|
33
|
+
\tApache server
|
34
|
+
\t\t\t - Container status #{apache_status}
|
35
|
+
\t\t\t - Container name #{docker_configs["containers_names"][1]}
|
36
|
+
\t\t\t - Container IP #{docker_configs["apache-server_container_ip"]}
|
37
|
+
\t\t\t - Machine OS #{docker_configs["apache-server_os"]}
|
38
|
+
\t\t\t - Apache version #{docker_configs["apache-server_version"]}
|
39
|
+
|
40
|
+
\tMySQL server
|
41
|
+
\t\t\t - Container status #{mysql_status}
|
42
|
+
\t\t\t - Container name #{docker_configs["containers_names"][0]}
|
43
|
+
\t\t\t - Container IP #{docker_configs["mysql-server_container_ip"]}
|
44
|
+
\t\t\t - Machine OS #{docker_configs["mysql-server_os"]}
|
45
|
+
\t\t\t - MySQL version #{docker_configs["mysql-server_version"]}
|
46
|
+
\t\t\t - MySQL user / pass #{docker_configs["mysql-server_user"]} / #{docker_configs["mysql-server_user_password"]}
|
47
|
+
\t\t\t - MySQL root pass #{docker_configs["mysql-server_root_password"]}
|
48
|
+
|
49
|
+
\tFolders paths
|
50
|
+
\t\t\t - Sites #{$sites_folder_path}
|
51
|
+
\t\t\t - Shared #{$shared_folder_path}
|
52
|
+
\t\t\t - MySQL #{$mysql_folder_path}
|
53
|
+
\t\t\t - Export #{$export_folder_path}
|
54
|
+
|
55
|
+
\tSites in sites folder
|
56
|
+
|
57
|
+
#{site_list}
|
58
|
+
------------------------------------------------------------------------------------------------------------------
|
59
|
+
| \t#{"MORE DETAILS".colorize(:yellow)} |
|
60
|
+
------------------------------------------------------------------------------------------------------------------
|
61
|
+
|
62
|
+
Apache virtualhosts file content
|
63
|
+
|
64
|
+
#{virtualhosts_content}
|
65
|
+
|
66
|
+
------------------------------------------------------------------------------------------------------------------
|
67
|
+
|
68
|
+
EOF
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def self.colorize_status status
|
74
|
+
case status
|
75
|
+
when "running"
|
76
|
+
status.colorize(:green)
|
77
|
+
when "not created"
|
78
|
+
status.colorize(:red)
|
79
|
+
else
|
80
|
+
status.colorize(:yellow)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.get_virtualhosts_content
|
85
|
+
virtualhost_file = "#{$configs_path}/sites_virtualhosts"
|
86
|
+
if File.exist? virtualhost_file
|
87
|
+
"\n#{File.read(virtualhost_file)}"
|
88
|
+
else
|
89
|
+
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'"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.get_site_list hosts_file_content, virtualhosts_content
|
94
|
+
site_list = []
|
95
|
+
|
96
|
+
SiteManager.get_all_sites.each_with_index do |site, index|
|
97
|
+
site_url = hosts_file_content.include?(site[:name]) ? "http://#{site[:name]}.dev".colorize(:green) : "Not found in Hosts file".colorize(:red)
|
98
|
+
site_in_virtualhost = virtualhosts_content.include?(site[:name]) ? "Yes".colorize(:green) : "No".colorize(:red)
|
99
|
+
|
100
|
+
site_list << { name: site[:name], url: site_url, virtualhost: site_in_virtualhost }
|
101
|
+
end
|
102
|
+
site_list
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class CavalerieUpSequence < BaseSequence
|
4
|
+
|
5
|
+
def self.start
|
6
|
+
SequenceManager.start_sequence :ensure_setup_is_correct, 2
|
7
|
+
|
8
|
+
# ------ Shared part with Cavalerie refresh sequence ------- #
|
9
|
+
# TODO: factorize that
|
10
|
+
SiteManager.ensure_sites_are_valid
|
11
|
+
FileFolderManager.update_sites_virtualhosts_file
|
12
|
+
FileFolderManager.update_hosts_file
|
13
|
+
FileFolderManager.update_local_config_files
|
14
|
+
# ------ Shared part with Cavalerie refresh sequence ------- #
|
15
|
+
|
16
|
+
VagrantManager.start_or_restart_containers
|
17
|
+
VagrantManager.ensure_containers_are_running
|
18
|
+
|
19
|
+
DatabaseManager.create_sites_database_if_not_exist
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class EnsureSetupIsCorrectSequence < BaseSequence
|
4
|
+
|
5
|
+
def self.start
|
6
|
+
threads = []
|
7
|
+
|
8
|
+
setup_status = Config.get_setup_status
|
9
|
+
|
10
|
+
if setup_status["is_vagrant_installed?"] != true
|
11
|
+
threads << Thread.new { ensure_vagrant_is_installed }
|
12
|
+
end
|
13
|
+
|
14
|
+
if setup_status["are_required_plugins_installed?"] != true
|
15
|
+
threads << Thread.new { ensure_required_plugins_are_installed }
|
16
|
+
end
|
17
|
+
|
18
|
+
threads << Thread.new { ensure_environment_variables_are_set }
|
19
|
+
threads << Thread.new { ensure_required_folders_are_available }
|
20
|
+
|
21
|
+
SequenceManager.set_threads_timeout threads
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.rescue error
|
25
|
+
case error.class.to_s
|
26
|
+
|
27
|
+
when "RequiredPluginMissingError"
|
28
|
+
missing_plugins = eval(error.message)
|
29
|
+
missing_plugins.each do |plugin_name|
|
30
|
+
puts Message.warning "Plugin \"#{plugin_name.capitalize}\" is not installed. Installing..."
|
31
|
+
VagrantHelper.plugin_install plugin_name
|
32
|
+
end
|
33
|
+
when "RequiredFolderUnavailableError"
|
34
|
+
missing_folders_paths = eval(error.message)
|
35
|
+
puts Message.warning error_message = "#{missing_folders_paths.count} required folder(s) are missing"
|
36
|
+
missing_folders_paths.each { |folder_path| FileFolderManager.create_folder_if_not_exist folder_path }
|
37
|
+
else
|
38
|
+
raise error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.ensure_vagrant_is_installed
|
45
|
+
begin
|
46
|
+
raise VagrantNotInstalledError unless VagrantCheck.is_vagrant_installed?
|
47
|
+
rescue VagrantNotInstalledError
|
48
|
+
abort Message.error "Vagrant isn't installed. Please visit https://www.vagrantup.com for installation details."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.ensure_required_plugins_are_installed
|
53
|
+
if missing_plugins = VagrantCheck.is_a_required_plugin_missing?
|
54
|
+
raise RequiredPluginMissingError, missing_plugins
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.ensure_environment_variables_are_set
|
59
|
+
unset_environment_variables = []
|
60
|
+
Config.get_environment_variables.each do |environment_variable|
|
61
|
+
unset_environment_variables << environment_variable[1][:name] unless ENV[environment_variable[1][:name]]
|
62
|
+
end
|
63
|
+
|
64
|
+
if unset_environment_variables.count > 0
|
65
|
+
abort Message.error "#{unset_environment_variables.count} environment variable(s) are unset. Please run \"cavalerie init\" to resolve this problem."
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.ensure_required_folders_are_available
|
70
|
+
if missing_folders_paths = FileFolderCheck.is_a_required_folder_unavailable?
|
71
|
+
raise RequiredFolderUnavailableError, missing_folders_paths
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CavalerieWeb::Banner
|
2
|
+
|
3
|
+
def self.cavalerie
|
4
|
+
|
5
|
+
banner = <<-EOF
|
6
|
+
|
7
|
+
_ _ ___ ___ ___ _ ___ ___ ___ ___
|
8
|
+
| | /_\\ / __| /_\\ \\ / /_\\ | | | __| _ \\_ _| __|
|
9
|
+
| |__ / _ \\ | (__ / _ \\ V / _ \\| |__| _|| /| || _|
|
10
|
+
|____/_/ \\_\\ \\___/_/ \\_\\_/_/ \\_\\____|___|_|_\\___|___|
|
11
|
+
EOF
|
12
|
+
|
13
|
+
puts banner.colorize(:light_blue)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CavalerieWeb
|
2
|
+
|
3
|
+
class Message
|
4
|
+
|
5
|
+
def self.success message
|
6
|
+
"[ √ ] #{message}".colorize(:green)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.error message
|
10
|
+
"[ X ] #{message}".colorize(:red)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.warning message
|
14
|
+
"[ ! ] #{message}".colorize(:yellow)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.notice message
|
18
|
+
"#{'[ - ]'.colorize(:cyan)} #{message}"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|