metastrano 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/helpers.rb ADDED
@@ -0,0 +1,7 @@
1
+ def config_path
2
+ "#{current_release}/config/"
3
+ end
4
+
5
+ def shared_config_path
6
+ "#{shared_path}/config/"
7
+ end
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
@@ -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
- vhost = ERB.new <<-EOF
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 :create_repo, :roles => :app, :except => { :no_release => true } do
10
- sudo "mkdir /home/git/#{application}.git && cd /home/git/#{application}.git && git --bare init"
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
@@ -41,12 +41,4 @@ Capistrano::Configuration.instance(:must_exist).load do
41
41
  end if config_files
42
42
  end
43
43
  end
44
-
45
- def config_path
46
- "#{current_release}/config/"
47
- end
48
-
49
- def shared_config_path
50
- "#{shared_path}/config/"
51
- end
52
44
  end
@@ -0,0 +1,7 @@
1
+ <VirtualHost *:80>
2
+ ServerName <%= server_name %>
3
+ DocumentRoot <%= current_path %>/public
4
+
5
+ CustomLog <%= shared_path %>/log/access.log combined
6
+ ErrorLog <%= shared_path %>/log/error.log
7
+ </VirtualHost>
@@ -0,0 +1,13 @@
1
+ base: &base
2
+ adapter: mysql
3
+ username: <%= db_user %>
4
+ password: <%= db_pass %>
5
+
6
+ production:
7
+ database: <%= application %>_production
8
+ <<: *base
9
+
10
+ test:
11
+ database: <%= application %>_test
12
+ <<: *base
13
+ EOF
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ log/*.log
3
+ tmp/**/*
4
+ config/database.yml
5
+ db/*.sqlite3
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.2.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-19 00:00:00 -05:00
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