metastrano 0.2.0 → 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.
- data/lib/helpers.rb +7 -0
- data/lib/metastrano.rb +36 -2
- data/lib/recipes/apache.rb +2 -11
- data/lib/recipes/db.rb +3 -25
- data/lib/recipes/git.rb +25 -3
- data/lib/recipes/setup.rb +17 -0
- data/lib/recipes/symlink.rb +0 -8
- data/lib/templates/apache.conf.erb +7 -0
- data/lib/templates/database.yml.erb +13 -0
- data/lib/templates/gitignore +5 -0
- metadata +7 -2
data/lib/helpers.rb
ADDED
data/lib/metastrano.rb
CHANGED
@@ -1,8 +1,42 @@
|
|
1
1
|
require 'capistrano'
|
2
2
|
require 'capistrano/cli'
|
3
3
|
|
4
|
-
Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).each { |f| load f }
|
5
|
-
|
6
4
|
Capistrano::Configuration.instance(:must_exist).load do
|
5
|
+
|
6
|
+
# basic setup stuff
|
7
7
|
set :config_files, 'database.yml' unless exists?(:config_files)
|
8
|
+
set :environment, 'production' unless exists?(:environment)
|
9
|
+
set :repo_path, '/home/git' unless exists?(:repo_path)
|
10
|
+
set :ruby_path, '/opt/ruby-enterprise-1.8.7-2009.10/bin/'
|
11
|
+
set :user, 'capistrano' unless exists?(:user)
|
12
|
+
|
13
|
+
# version control
|
14
|
+
set :scm, :git
|
15
|
+
set :scm_username, :git
|
16
|
+
|
17
|
+
def metastrano_load_template_file(file_name)
|
18
|
+
local_file = "config/metastrano/#{file_name}"
|
19
|
+
file_path = File.exists?(local_file) ? local_file : MetaStrano.path + "/templates/#{file_name}"
|
20
|
+
File.open(file_path, 'r').read
|
21
|
+
end
|
22
|
+
|
23
|
+
def metastrano_load_erb_file(file_name)
|
24
|
+
erb_template = ERB.new(metastrano_load_template_file("#{file_name}"))
|
25
|
+
erb_template.result(binding)
|
26
|
+
end
|
27
|
+
|
28
|
+
def prepare_for_db_command
|
29
|
+
set :db_name, "#{application}_#{environment}" unless exists?(:db_name)
|
30
|
+
set(:db_admin_user) { Capistrano::CLI.ui.ask "Username with priviledged database access (to create db):" } unless exists?(:db_admin_user)
|
31
|
+
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" } unless exists?(:db_user)
|
32
|
+
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" } unless exists?(:db_pass)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).each { |f| load f }
|
37
|
+
|
38
|
+
module MetaStrano
|
39
|
+
def self.path
|
40
|
+
File.dirname(__FILE__)
|
41
|
+
end
|
8
42
|
end
|
data/lib/recipes/apache.rb
CHANGED
@@ -14,17 +14,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
14
14
|
desc "Creates the .conf file in the shared config directory, and creates a symlink to /etc/httpd/conf.d/application.conf"
|
15
15
|
task :create_vhost do
|
16
16
|
set(:server_name) { Capistrano::CLI.ui.ask "Enter ServerName" } unless exists?(:server_name)
|
17
|
-
|
18
|
-
|
19
|
-
<VirtualHost *:80>
|
20
|
-
ServerName #{server_name}
|
21
|
-
DocumentRoot #{current_path}/public
|
22
|
-
|
23
|
-
CustomLog #{shared_path}/log/access.log combined
|
24
|
-
ErrorLog #{shared_path}/log/error.log
|
25
|
-
</VirtualHost>
|
26
|
-
EOF
|
27
|
-
|
17
|
+
vhost = metastrano_load_erb_file('apache.conf.erb')
|
18
|
+
|
28
19
|
# uploads the above vhost file onto the server
|
29
20
|
put vhost.result, "#{shared_path}/config/#{application}.conf"
|
30
21
|
|
data/lib/recipes/db.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
1
|
Capistrano::Configuration.instance(:must_exist).load do
|
4
2
|
namespace :db do
|
5
3
|
|
@@ -45,22 +43,10 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
45
43
|
task :create_yaml do
|
46
44
|
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" } unless exists?(:db_user)
|
47
45
|
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" } unless exists?(:db_pass)
|
48
|
-
|
49
|
-
db_config = ERB.new <<-EOF
|
50
|
-
base: &base
|
51
|
-
adapter: mysql
|
52
|
-
username: #{db_user}
|
53
|
-
password: #{db_pass}
|
54
|
-
|
55
|
-
#{environment}:
|
56
|
-
database: #{application}_#{environment}
|
57
|
-
<<: *base
|
58
|
-
|
59
|
-
test:
|
60
|
-
database: #{application}_test
|
61
|
-
<<: *base
|
62
|
-
EOF
|
46
|
+
# create the shared config folder if it doesn't already exist
|
63
47
|
run "mkdir -p #{shared_path}/config"
|
48
|
+
db_config = metastrano_load_erb_file('database.yml.erb')
|
49
|
+
# uploads the database.yml config file
|
64
50
|
put db_config.result, "#{shared_path}/config/database.yml"
|
65
51
|
end
|
66
52
|
|
@@ -94,13 +80,5 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
94
80
|
run_locally "gunzip -c /tmp/#{filename} | mysql -u #{local_settings['username']} #{local_settings['password']} #{local_settings['database']} && rm -f gunzip #{filename} && rm -f tmp/database.yml"
|
95
81
|
end
|
96
82
|
end
|
97
|
-
|
98
|
-
def prepare_for_db_command
|
99
|
-
set :db_name, "#{application}_#{environment}" unless exists?(:db_name)
|
100
|
-
set(:db_admin_user) { Capistrano::CLI.ui.ask "Username with priviledged database access (to create db):" } unless exists?(:db_admin_user)
|
101
|
-
set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" } unless exists?(:db_user)
|
102
|
-
set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" } unless exists?(:db_pass)
|
103
|
-
end
|
104
|
-
|
105
83
|
end
|
106
84
|
end
|
data/lib/recipes/git.rb
CHANGED
@@ -3,11 +3,33 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
3
3
|
#----------------------------------------------------------------
|
4
4
|
# git
|
5
5
|
#----------------------------------------------------------------
|
6
|
-
|
6
|
+
|
7
7
|
namespace :git do
|
8
|
+
desc "Creates a local git repo"
|
9
|
+
task :init do
|
10
|
+
# write the ignore files
|
11
|
+
run_locally "sudo touch tmp/.gitignore log/.gitignore vendor/.gitignore"
|
12
|
+
File.open('.gitignore', 'w') {|f| f.write(metastrano_load_template_file('gitignore')) }
|
13
|
+
# init the git repo
|
14
|
+
run_locally "git init"
|
15
|
+
run_locally "git add . "
|
16
|
+
run_locally "git commit -a -m 'Initial Commit'"
|
17
|
+
run_locally "git remote add origin git@#{domain}:#{application}.git"
|
18
|
+
run_locally "git push origin master"
|
19
|
+
end
|
20
|
+
|
8
21
|
desc "Creates a remote git repo"
|
9
|
-
task :
|
10
|
-
|
22
|
+
task :init_remote do
|
23
|
+
set(:repo_path) { Capistrano::CLI.ui.ask "Enter location of remote git repos" } unless exists?(:repo_path)
|
24
|
+
sudo "mkdir -p #{repo_path}/#{application}.git"
|
25
|
+
sudo "git --bare --git-dir=#{repo_path}/#{application}.git init"
|
26
|
+
sudo "chown #{scm}:#{scm} -R #{repo_path}/#{application}.git"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Creates the remote git repo, then initializes the local repo and performs the first commit"
|
30
|
+
task :setup do
|
31
|
+
init_remote
|
32
|
+
init
|
11
33
|
end
|
12
34
|
end
|
13
35
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
|
3
|
+
#----------------------------------------------------------------
|
4
|
+
# Setup
|
5
|
+
#----------------------------------------------------------------
|
6
|
+
|
7
|
+
namespace :setup do
|
8
|
+
desc "Copies the database.yml file, the apache.conf file, and the gitignore files to config/metastrano/files"
|
9
|
+
task :copy_templates do
|
10
|
+
run_locally "mkdir config/metastrano"
|
11
|
+
run_locally "cp #{MetaStrano.path}/templates/apache.conf.erb config/metastrano/apache.conf.erb"
|
12
|
+
run_locally "cp #{MetaStrano.path}/templates/database.yml.erb config/metastrano/database.yml.erb"
|
13
|
+
run_locally "cp #{MetaStrano.path}/templates/gitignore.erb config/metastrano/gitignore.erb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/recipes/symlink.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metastrano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Paul Narowski
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-20 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -57,13 +57,18 @@ files:
|
|
57
57
|
- LICENSE
|
58
58
|
- README.rdoc
|
59
59
|
- Rakefile
|
60
|
+
- lib/helpers.rb
|
60
61
|
- lib/metastrano.rb
|
61
62
|
- lib/recipes/apache.rb
|
62
63
|
- lib/recipes/db.rb
|
63
64
|
- lib/recipes/deploy.rb
|
64
65
|
- lib/recipes/git.rb
|
65
66
|
- lib/recipes/rake.rb
|
67
|
+
- lib/recipes/setup.rb
|
66
68
|
- lib/recipes/symlink.rb
|
69
|
+
- lib/templates/apache.conf.erb
|
70
|
+
- lib/templates/database.yml.erb
|
71
|
+
- lib/templates/gitignore
|
67
72
|
- test/helper.rb
|
68
73
|
- test/test_metastrano.rb
|
69
74
|
has_rdoc: true
|