speedy 0.1.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.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib speedy]) )
4
+
5
+
6
+ # Run the Speedy
7
+ Speedy::Main.run! ARGV
8
+
@@ -0,0 +1,47 @@
1
+ module Speedy
2
+
3
+ # :stopdoc:
4
+ VERSION = '0.1.0'
5
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
+ # :startdoc:
8
+
9
+ # Returns the version string for the library.
10
+ #
11
+ def self.version
12
+ VERSION
13
+ end
14
+
15
+ # Returns the library path for the module. If any arguments are given,
16
+ # they will be joined to the end of the libray path using
17
+ # <tt>File.join</tt>.
18
+ #
19
+ def self.libpath( *args )
20
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
21
+ end
22
+
23
+ # Returns the lpath for the module. If any arguments are given,
24
+ # they will be joined to the end of the path using
25
+ # <tt>File.join</tt>.
26
+ #
27
+ def self.path( *args )
28
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
29
+ end
30
+
31
+ # Utility method used to require all files ending in .rb that lie in the
32
+ # directory below this file that has the same name as the filename passed
33
+ # in. Optionally, a specific _directory_ name can be passed in such that
34
+ # the _filename_ does not have to be equivalent to the directory.
35
+ #
36
+ def self.require_all_libs_relative_to( fname, dir = nil )
37
+ dir ||= ::File.basename(fname, '.*')
38
+ search_me = ::File.expand_path(
39
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
40
+
41
+ Dir.glob(search_me).sort.each {|rb| require rb}
42
+ end
43
+
44
+ end # module Speedy
45
+
46
+ Speedy.require_all_libs_relative_to(__FILE__)
47
+
@@ -0,0 +1,29 @@
1
+ module Speedy
2
+
3
+ class Deploy
4
+
5
+ require 'rbconfig'
6
+
7
+ attr_accessor :platform
8
+
9
+ @platform = Config::CONFIG['host_os']
10
+
11
+ def self.deploy!
12
+ if @platform.match('linux')
13
+ Speedy::LinuxDeployment.new
14
+ elsif @platform.match('darwin')
15
+ puts "-" * 65
16
+ puts "Wohooo it's a Mac."
17
+ puts "This version (0.1.0) only supports for Linux."
18
+ puts "-" * 65
19
+ else
20
+ puts "Sorry, Speedy dosen't support to your Operating System!"
21
+ end
22
+
23
+ end
24
+
25
+
26
+ end # Deploy
27
+
28
+ end # Speedy
29
+
@@ -0,0 +1,134 @@
1
+ module Speedy
2
+
3
+ class LinuxDeployment
4
+
5
+ @@site_avaliable_dir_path = File.join('/' 'etc', 'apache2', 'sites-available')
6
+ HOSTS_FILE_PATH = '/etc/hosts'
7
+
8
+ attr_accessor :app_name, :touch_file
9
+
10
+
11
+ def initialize(args=[])
12
+ do_action(ARGV[0])
13
+ end
14
+
15
+ def do_action(action)
16
+ case action
17
+ when 'deploy'
18
+ deploy(ARGV[1])
19
+ when 'config-passenger'
20
+ config_passenger
21
+ when '-h'
22
+ display_help
23
+ when '--help'
24
+ display_help
25
+ else
26
+ puts "Not a valid command. Please type 'speedy -h' to view all avaliable commands."
27
+ end
28
+ end # do_action
29
+
30
+ def deploy(args)
31
+ construc_app_name(args)
32
+ create_virtual_host
33
+ add_hosts_entry
34
+ enable_site
35
+ conclusion
36
+ end
37
+
38
+ # Preform Apache-Passenger clean configuration for Linux
39
+ def config_passenger
40
+ Speedy::PassengerConfig.run!
41
+ end
42
+
43
+ # Display all available commands and options
44
+ def display_help
45
+ puts "# sudo speedy config-passenger"
46
+ puts "# sudo speedy deploy"
47
+ puts "# sudo speedy deploy <custom_name>.local"
48
+ end
49
+
50
+ # Create virtual host for default name unless the user provide a name
51
+ def create_virtual_host
52
+ apache_touch_file = construct_apache_touch_file
53
+ virtual_host_exists?(apache_touch_file)
54
+ document_root = construct_document_root
55
+ File.open( apache_touch_file, 'w') do |file|
56
+ file.puts "<VirtualHost *:80>\n"
57
+ file.puts "\tServerName #{@app_name}\n"
58
+ file.puts "\tRailsEnv development\n"
59
+ file.puts "\tDocumentRoot #{document_root}\n"
60
+ file.puts "</VirtualHost>"
61
+ end
62
+ puts "\n\nVirtual Host for #{@app_name} created.\n"
63
+ end
64
+
65
+
66
+ # Construct app name
67
+ def construc_app_name(args)
68
+ # If name doesn't provided by user set the default name
69
+ if args.nil?
70
+ @app_name = Dir.pwd.split('/').pop + ".local"
71
+ else
72
+ @app_name = args
73
+ end
74
+ end
75
+
76
+ # Construct the application public folder path
77
+ def construct_document_root
78
+ return Dir.pwd + "/public"
79
+ end
80
+
81
+
82
+ # Contruct the apache touch file removing '.'
83
+ def construct_apache_touch_file
84
+ if @app_name.empty?
85
+ @touch_file = "no_file"
86
+ else
87
+ @touch_file = @app_name.include?('.') ? @app_name.split(".").shift : @app_name
88
+ end
89
+ return File.join(@@site_avaliable_dir_path, touch_file)
90
+ end
91
+
92
+ # Check whether a virtual host exists in the same name
93
+ def virtual_host_exists?(host)
94
+ if File.exists?(host)
95
+ separator
96
+ puts "Sorry, but a virtual host in the same name already exist!"
97
+ puts "Please try with a diffrent name."
98
+ puts "[Hint: speedy new_name.local ]"
99
+ separator
100
+ exit!
101
+ end
102
+ end
103
+
104
+ # Add the application name to /etc/hosts file
105
+ def add_hosts_entry
106
+ File.open(HOSTS_FILE_PATH, 'a') do |file|
107
+ file.puts "127.0.0.1\t#{@app_name}"
108
+ end
109
+ end
110
+
111
+ # Run Apache command to enable the site
112
+ def enable_site
113
+ separator
114
+ system "sudo a2ensite #{@touch_file}"
115
+ separator
116
+ sleep(1)
117
+ system "sudo /etc/init.d/apache2 restart"
118
+ end
119
+
120
+ # Display final success message
121
+ def conclusion
122
+ separator
123
+ puts "#{@app_name} successfully deployed! URL: http://#{app_name}"
124
+ puts "\n\n"
125
+ end
126
+
127
+ def separator
128
+ puts "-" * 65
129
+ end
130
+
131
+ end # LinuxDeployment
132
+
133
+ end # Speedy
134
+
@@ -0,0 +1,8 @@
1
+ module Speedy
2
+
3
+ class MacDeployment
4
+
5
+ end
6
+
7
+ end
8
+
@@ -0,0 +1,14 @@
1
+ module Speedy
2
+
3
+ class Main
4
+
5
+ def self.run!(args=[])
6
+ Speedy::Deploy.deploy!
7
+ end
8
+
9
+
10
+
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,23 @@
1
+ module Speedy
2
+
3
+ class PassengerConfig
4
+
5
+ def self.run!
6
+ if File.exists?('/etc/apache2/passenger_speedy.conf')
7
+ system 'sudo touch /etc/apache2/passenger_speedy.conf'
8
+ system 'sudo vi /etc/apache2/passenger_speedy.conf'
9
+ else
10
+ system 'sudo touch /etc/apache2/passenger_speedy.conf'
11
+ system 'sudo vi /etc/apache2/passenger_speedy.conf'
12
+ File.open('/etc/apache2/apache2.conf', 'a') do |file|
13
+ file.puts "\n# Include passenger configuration file"
14
+ file.puts "Include passenger_speedy.conf"
15
+ end
16
+ end # if
17
+ system 'sudo /etc/init.d/apache2 restart'
18
+ end
19
+
20
+ end # PassengerConfig
21
+
22
+ end # Speedy
23
+
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: speedy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mohamed Aslam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-05 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: aslam@weblivestudio.com
18
+ executables:
19
+ - speedy
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/speedy/deploy.rb
26
+ - lib/speedy/linux_deployment.rb
27
+ - lib/speedy/mac_deployment.rb
28
+ - lib/speedy/main.rb
29
+ - lib/speedy/passenger_config.rb
30
+ - lib/speedy.rb
31
+ - bin/speedy
32
+ has_rdoc: true
33
+ homepage: http://speedy.mohamedaslam.com
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Speedy is a Rapid Rails deplyement utility for ModRails
60
+ test_files: []
61
+