yyyc514-dwell 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,115 @@
1
+ DWELL - a cap recipe to setup a full Rails stack on Ubuntu
2
+ ============================================================================
3
+
4
+
5
+ Install Capistrano2 (if you don't already have it) then build and install this gem:
6
+
7
+ $ sudo gem install capistrano
8
+ $ gem build dwell.gemspec
9
+ $ sudo gem install dwell-0.2.gem
10
+
11
+
12
+ ### Typical Usage
13
+
14
+ 1. Capify your Rails directory
15
+ 2. Initialize dwell inside your Rails directory (you'll want to overwrite deploy.rb)
16
+ 3. Edit your deploy.rb: configure you applications name, domain, repository, server details, etc
17
+ 4. Bootstrap your server
18
+ 5. Install the Dwell stack and any optional packages
19
+ 6. Setup your rails app and apache vhost then deploy cold
20
+
21
+ Or all said and done:
22
+
23
+ $ capify .
24
+ $ dwell init .
25
+ $ cap dwell:server:bootstrap
26
+ $ cap dwell:install
27
+ $ cap dwell:rails:setup_and_deploy_cold
28
+
29
+
30
+ The Dwell Stack - dwell:install
31
+ -----------------------------
32
+
33
+ 1. Updates Ubuntu sources and distro
34
+ 2. Installs Apache2
35
+ 3. Installs MySQL5
36
+ 4. Installs Subversion and Git
37
+ 5. Installs Ruby, RubyGems, Rails and Merb
38
+ 6. Installs Passenger module for Apache2
39
+ 7. Installs any optional packages listed in `:dwell_optional_installs`
40
+
41
+
42
+ ### Optional Packages
43
+
44
+ You can specify optional packages to be installed during `dwell:install` in your deploy.rb file:
45
+
46
+ set :dwell_optional_installs, [:postfix, :imagemagick, :php]
47
+
48
+ Optional packages include:
49
+
50
+ - postfix
51
+ - mercurial
52
+ - tinydns
53
+ - php (sets up php via fastcig)
54
+ - imagemagick (binary, gem, and mini-magick gem)
55
+ - sqlite (binary and gem)
56
+
57
+
58
+ Bootstrapping
59
+ -------------
60
+
61
+ ### dwell:server:bootstrap
62
+
63
+ 1. Creates a user account for `:user` (default 'deploy') in the admin group
64
+ 2. Gives the admin group sudo rights if they haven't already
65
+ 3. Copies authorized SSH keys to the remote host (such as your own public key)
66
+ 5. Disables SSH logins for the root account since we'll be using deploy and sudo
67
+
68
+ Authorized keys should be placed in the file (:user is the name of your deploy user):
69
+
70
+ config/dwell/authorized_keys/:user
71
+
72
+
73
+ ### dwell:linode:bootstrap
74
+
75
+ 1. Does a `dwell:server:bootstrap` as show above
76
+ 2. Uses the DHCP IP assignment to configure a static IP and disable DHCP
77
+ 3. Sets up the hostname of the box from what was passed in HOSTS
78
+
79
+ You MUST pass the host (singular) in HOSTS to bootstrap a Linode as the bootstrap needs to know the hostname to properly configure the box.
80
+
81
+ HOSTS="my.new.box.com" cap dwell:linode:bootstrap
82
+
83
+
84
+ Rails Notes - dwell:rails
85
+ --------------------------
86
+
87
+ ### dwell:rails:setup\_and\_deploy\_cold
88
+
89
+ 1. Does a traditional `cap:setup`
90
+ 2. Copies deploy keys (if found) to the remote host (needed for git, etc)
91
+ 3. Creates a mysql database with the authentication info in your database.yml
92
+ 4. Sets up an apache vhost and SSL keys (if you're using SSL)
93
+ 5. Deploys your code
94
+ 6. Installs any necessary app gems with `rake gems:install`
95
+ 7. Runs migrations
96
+ 8. Reloads Apache which should fire up your app
97
+
98
+ Optional deploy keys (public and private) should be placed in `deploy_keys`:
99
+
100
+ config/dwell/deploy_keys/:user.pub
101
+ config/dwell/deploy_keys/:user
102
+
103
+
104
+ Apache Notes - dwell:apache
105
+ ---------------------------
106
+
107
+ SSL certificates (if found) will be copied and installed during `setup_and_deploy_cold`. You can also do this manually with `cap dwell:apache:copy_certs`. These same certs will referenced automatically in your apache configs if you have set `:apache_ssl_enabled` in your deploy.rb.
108
+
109
+ SSL certificates should be saved locally:
110
+
111
+ config/dwell/ssl/ca/*.crt
112
+ config/dwell/ssl/*.crt
113
+ config/dwell/ssl/*.key
114
+
115
+ Any keys inside `ssl/ca` are assumed to be a Certificate Authority and are added to your Apache config with `SSLCACertificateFile`.
data/bin/dwell CHANGED
@@ -1,3 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'rubigen'
2
4
 
3
- puts "coming soon"
5
+ if %w(-v --version).include? ARGV.first
6
+ puts "dwell version 0.2.1"
7
+ exit(0)
8
+ end
9
+
10
+ require 'rubigen/scripts/generate'
11
+ source=RubiGen::PathSource.new(:dwell, "#{File.dirname(__FILE__)}/../generators")
12
+ RubiGen::Base.append_sources(source)
13
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'dwell')
@@ -0,0 +1,80 @@
1
+ require 'rbconfig'
2
+
3
+ class DwellGenerator < RubiGen::Base
4
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
5
+ Config::CONFIG['ruby_install_name'])
6
+
7
+ default_options :shebang => DEFAULT_SHEBANG,
8
+ :an_option => 'some_default'
9
+
10
+ attr_reader :app_name, :module_name
11
+
12
+ def initialize(runtime_args, runtime_options = {})
13
+ super
14
+ usage if args.empty?
15
+ init = args.shift
16
+ if init!="init"
17
+ puts "ERROR: #{init} is not a supported command\n\n"
18
+ usage
19
+ exit(0)
20
+ end
21
+ @destination_root = args.shift || "."
22
+ end
23
+
24
+ def manifest
25
+ # Use /usr/bin/env if no special shebang was specified
26
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil :
27
+ options[:shebang] }
28
+ windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
29
+
30
+ record do |m|
31
+ # Root directory and all subdirectories.
32
+ # m.directory ''
33
+ BASEDIRS.each { |path| m.directory path }
34
+
35
+ # Root
36
+ # m.template_copy_each %w( Rakefile )
37
+ # m.file_copy_each %w( config/deploy.rb )
38
+ m.template "deploy.rb", "config/deploy.rb"
39
+ m.file "known_hosts/github", "config/dwell/known_hosts/github"
40
+
41
+ # Test helper
42
+ # m.template "test_helper.rb", "test/test_helper.rb"
43
+
44
+ # Scripts
45
+ # %w( generate ).each do |file|
46
+ # m.template "script/#{file}", "script/#{file}", script_options
47
+ # m.template "script/win_script.cmd", "script/#{file}.cmd",
48
+ # :assigns => { :filename => file } if windows
49
+ end
50
+
51
+ end
52
+
53
+ protected
54
+ def banner
55
+ <<-EOS
56
+ Creates a default deploy.rb and sets up the config/dwell directory tree.
57
+
58
+ Usage: #{File.basename $0} init [/path/to/rails/app] [options]
59
+ EOS
60
+ end
61
+
62
+ def add_options!(opts)
63
+ opts.separator ''
64
+ opts.separator "#{File.basename $0} options:"
65
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
66
+ end
67
+
68
+ # Installation skeleton. Intermediate directories are automatically
69
+ # created so don't sweat their absence here.
70
+ BASEDIRS = %w(
71
+ config
72
+ config/dwell
73
+ config/dwell/authorized_keys
74
+ config/dwell/authorized_keys/deploy
75
+ config/dwell/deploy_keys
76
+ config/dwell/known_hosts
77
+ config/dwell/ssl
78
+ config/dwell/ssl/ca
79
+ )
80
+ end
@@ -3,7 +3,10 @@ require 'dwell'
3
3
  # Application Details
4
4
  set :application, "myapp"
5
5
  set :domain, "myapp.com"
6
- set :repository, "svn://myapp.com/trunk"
6
+
7
+ # If you aren't using Subversion to manage your source code, specify your SCM below:
8
+ # set :scm, :git
9
+ set :repository, "set your repository location here"
7
10
 
8
11
  # Server-wide Details
9
12
  set :user, "deploy"
@@ -13,12 +16,8 @@ server "myserver.com", :app, :web, :db, :primary => true
13
16
  ## the user to use when creating new databases and such
14
17
  # set :mysql_admin, "root"
15
18
 
16
- ## hosts to automatically add to ssh known_hosts for your deploy user
17
- ## only github is currently supported
18
- # set :known_hosts, [:github]
19
-
20
19
  ## other dwell packages to install on this server
21
- # set :dwell_install, ["imagemagick"]
20
+ # set :dwell_optional_installs, ["imagemagick"]
22
21
 
23
22
  ## a specific rails version your app depends on, will be
24
23
  ## gem installed during dwell:install
data/lib/dwell/recipes.rb CHANGED
@@ -11,7 +11,7 @@ Capistrano::Configuration.instance(:must_exist).load do
11
11
 
12
12
  namespace :dwell do
13
13
 
14
- set :dwell_install, []
14
+ set :dwell_optional_installs, []
15
15
 
16
16
  desc "Install Rails Production Environment"
17
17
  task :install do
@@ -24,7 +24,7 @@ Capistrano::Configuration.instance(:must_exist).load do
24
24
  top.dwell.ruby_enterprise.install if which_ruby==:enterprise
25
25
  top.dwell.gems.install
26
26
  top.dwell.passenger.install
27
- dwell_install.each do |package_name|
27
+ dwell_optional_installs.each do |package_name|
28
28
  top.dwell.send(package_name).install
29
29
  end
30
30
  end
@@ -2,34 +2,53 @@ Capistrano::Configuration.instance(:must_exist).load do
2
2
  namespace :dwell do
3
3
  namespace :linode do
4
4
 
5
- task :create_deploy_user do
6
- dwell1.adduser deploy_user, :group => "admin"
7
- new_password = Capistrano::CLI.ui.ask("Enter password for #{deploy_user}:") { |q| q.echo = true }
8
- dwell1.invoke_with_input("passwd #{deploy_user}", /UNIX password/, new_password)
9
- end
10
-
11
- task :copy_ssh_key do
12
- dwell1.mkdir "/home/#{deploy_user}/.ssh", :mode => 0700, :owner => "#{deploy_user}.admin"
13
- put File.read("config/dwell/authorized_keys/#{deploy_user}"), "/home/#{deploy_user}/.ssh/authorized_keys", :mode => 0600
14
- sudo "chown #{deploy_user}.admin /home/#{deploy_user}/.ssh/authorized_keys"
15
- end
16
-
17
- task :disable_root_login do
18
- dwell1.config_gsub "/etc/ssh/sshd_config", /^PermitRootLogin (.*)$/,"PermitRootLogin no"
19
- sudo "/etc/init.d/ssh reload"
5
+ after "dwell:linode:bootstrap", "dwell:linode:setup_hostname"
6
+ after "dwell:linode:bootstrap", "dwell:linode:setup_static_ip"
7
+
8
+ desc "bootstrap a new linode server"
9
+ task :bootstrap do
10
+ hostname=ENV["HOSTS"]
11
+ if hostname =~ /\d+\.\d+\.\d+\.\d+/
12
+ puts "You used an IP, please use the hostname so can set /etc/hostname on the remote."
13
+ exit
14
+ end
15
+ if hostname.nil? or hostname.empty?
16
+ puts "You must specify HOSTS='hostname' to use the bootstrap command."
17
+ exit
18
+ end
19
+ top.dwell.server.bootstrap
20
20
  end
21
-
22
- desc "setup static ip address"
23
- task :setup_static_ip do
24
- ip,broadcast,mask,gateway=nil
21
+
22
+ def get_ip_info
25
23
  run "/sbin/ifconfig eth0" do |channel, stream, data|
26
24
  if data.match(/inet addr:([^ ]*) Bcast:([^ ]*) Mask:([^ ]*)/)
27
- ip, broadcast, mask = $1, $2, $3
25
+ return $1, $2, $3
28
26
  end
29
27
  end
28
+ end
29
+
30
+ def get_gateway
30
31
  run "ip route" do |channel, stream, data|
31
- gateway=$1 if data.match(/default via ([^ ]*) dev eth0/)
32
+ return $1 if data.match(/default via ([^ ]*) dev eth0/)
32
33
  end
34
+ end
35
+
36
+ ## TODO : make multi-server safe
37
+ task :setup_hostname do
38
+ hostname=ENV["HOSTS"]
39
+ sudo "echo #{hostname} > /tmp/hostname"
40
+ sudo "mv /tmp/hostname /etc/hostname"
41
+ sudo "chown root:root /etc/hostname"
42
+ host_line="#{get_ip_info.first} #{hostname.split(".").first} #{hostname}"
43
+ dwell1.append_to_file_if_missing("/etc/hosts",host_line)
44
+ sudo "hostname --file /etc/hostname"
45
+ end
46
+
47
+ ## TODO : make multi-server safe
48
+ desc "setup static ip address"
49
+ task :setup_static_ip do
50
+ ip,broadcast,mask=get_ip_info
51
+ gateway=get_gateway
33
52
 
34
53
  interface=<<-EOS
35
54
  iface eth0 inet static
@@ -44,32 +63,6 @@ gateway #{gateway}
44
63
  # kill the dhcp client
45
64
  sudo "pkill dhclient3"
46
65
  end
47
-
48
- desc "bootstrap linode box"
49
- task :bootstrap do
50
- set :deploy_user, user
51
- auth_keys="config/dwell/authorized_keys/#{deploy_user}"
52
- unless File.exist?(auth_keys)
53
- puts "\n Please place authorized SSH keys for #{deploy_user} in:"
54
- puts " #{auth_keys}\n\n"
55
- exit
56
- end
57
- set :user, "root"
58
- if ubuntu1.lsb_info[:distrib_codename]=="intrepid"
59
- # for linode's slimmed down intrepid
60
- run "addgroup admin"
61
- dwell1.append_to_file_if_missing "/etc/sudoers", "%admin ALL=(ALL) ALL"
62
- sudo "apt-get install ubuntu-standard -y"
63
- end
64
- create_deploy_user
65
- copy_ssh_key
66
- set :user, deploy_user
67
- # test deploy login via ssh before we disable root login
68
- sudo "echo"
69
- disable_root_login
70
- setup_static_ip
71
- end
72
-
73
66
  end
74
67
  end
75
68
  end
@@ -0,0 +1,59 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :dwell do
3
+ namespace :server do
4
+
5
+ set :deploy_user, nil
6
+
7
+ task :create_deploy_user do
8
+ dwell1.adduser deploy_user, :group => "admin"
9
+ puts
10
+ new_password = Capistrano::CLI.ui.ask("Enter DESIRED password for #{deploy_user}:") { |q| q.echo = true }
11
+ dwell1.invoke_with_input("passwd #{deploy_user}", /UNIX password/, new_password)
12
+ end
13
+
14
+ task :push_ssh_keys do
15
+ set :deploy_user, user if deploy_user.nil?
16
+ dwell1.mkdir "/home/#{deploy_user}/.ssh", :mode => 0700,
17
+ :owner => "#{deploy_user}.admin", :via => :sudo
18
+ run "rm -f /home/#{deploy_user}/.ssh/authorized_keys"
19
+ Dir.glob("config/dwell/authorized_keys/#{deploy_user}/*").each do |file|
20
+ key=File.read(file)
21
+ dwell1.append_to_file_if_missing("/home/#{deploy_user}/.ssh/authorized_keys", key)
22
+ end
23
+ sudo "chown #{deploy_user}.admin /home/#{deploy_user}/.ssh/authorized_keys"
24
+ run "chmod 0600 /home/#{deploy_user}/.ssh/authorized_keys"
25
+ end
26
+
27
+ task :disable_root_login do
28
+ dwell1.config_gsub "/etc/ssh/sshd_config", /^PermitRootLogin (.*)$/,"PermitRootLogin no"
29
+ sudo "/etc/init.d/ssh reload"
30
+ end
31
+
32
+ desc "bootstrap linode box"
33
+ task :bootstrap do
34
+ set :deploy_user, user
35
+ auth_keys="config/dwell/authorized_keys/#{deploy_user}"
36
+ unless File.exist?(auth_keys)
37
+ puts "\n Please place authorized SSH keys for #{deploy_user} in:"
38
+ puts " #{auth_keys}\n\n"
39
+ exit
40
+ end
41
+ set :user, "root"
42
+ puts "Enter your ROOT password now (so we can setup you #{deploy_user} user)."
43
+ if ubuntu1.lsb_info[:distrib_codename]=="intrepid"
44
+ # for linode's slimmed down intrepid
45
+ run "addgroup admin"
46
+ dwell1.append_to_file_if_missing "/etc/sudoers", "%admin ALL=(ALL) ALL"
47
+ sudo "apt-get install ubuntu-standard -y"
48
+ end
49
+ create_deploy_user
50
+ push_ssh_keys
51
+ set :user, deploy_user
52
+ # test deploy login via ssh before we disable root login
53
+ sudo "echo"
54
+ disable_root_login
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -29,8 +29,8 @@ Capistrano::Configuration.instance(:must_exist).load do
29
29
  put File.read("config/dwell/deploy_keys/#{user}.pub"), "/home/#{user}/.ssh/id_rsa.pub", :mode => 0600
30
30
  sudo "chown #{user}.admin /home/#{user}/.ssh/id_rsa.pub"
31
31
  end
32
- known_hosts.each do |host|
33
- key=File.open("#{File.dirname(__FILE__)}/../known_hosts/#{host}").read
32
+ Dir.glob("config/dwell/known_hosts/*").each do |file|
33
+ key=File.open(file).read
34
34
  dwell1.append_to_file_if_missing("/home/#{user}/.ssh/known_hosts", key)
35
35
  end
36
36
  sudo "chown #{user}.admin /home/#{user}/.ssh/known_hosts"
@@ -53,8 +53,7 @@
53
53
  # Server Private Key
54
54
  SSLCertificateKeyFile /etc/ssl/private/<%= domain %>.key
55
55
 
56
- <% Dir.glob("config/dwell/ssl/*").each do |file|
57
- next unless file =~ /CA/ %>
56
+ <% Dir.glob("config/dwell/ssl/ca/*").each do |file| %>
58
57
  SSLCACertificateFile /etc/ssl/certs/<%= File.basename(file) %>
59
58
  <% end %>
60
59
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yyyc514-dwell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Bousquet
@@ -22,6 +22,15 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.0.0
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubigen
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.4
33
+ version:
25
34
  description: Automated Rails production environment setup for Ubuntu
26
35
  email: robert@robertbousquet.com
27
36
  executables:
@@ -34,12 +43,11 @@ files:
34
43
  - bin/dwell
35
44
  - lib/dwell
36
45
  - lib/dwell/cap_extensions.rb
37
- - lib/dwell/known_hosts
38
- - lib/dwell/known_hosts/github
39
46
  - lib/dwell/recipes
40
47
  - lib/dwell/recipes/apache.rb
41
48
  - lib/dwell/recipes/bootstrap
42
49
  - lib/dwell/recipes/bootstrap/linode.rb
50
+ - lib/dwell/recipes/bootstrap/server.rb
43
51
  - lib/dwell/recipes/campfire.rb
44
52
  - lib/dwell/recipes/extras
45
53
  - lib/dwell/recipes/extras/daemontools.rb
@@ -66,14 +74,19 @@ files:
66
74
  - lib/dwell/recipes/ubuntu.rb
67
75
  - lib/dwell/recipes.rb
68
76
  - lib/dwell/templates
69
- - lib/dwell/templates/deploy.rb
70
77
  - lib/dwell/templates/passenger.conf
71
78
  - lib/dwell/templates/vhost.conf
72
79
  - lib/dwell/templates/vhost_ssl.conf
73
80
  - lib/dwell/ubuntu_extensions.rb
74
81
  - lib/dwell.rb
82
+ - generators/dwell
83
+ - generators/dwell/dwell_generator.rb
84
+ - generators/dwell/templates
85
+ - generators/dwell/templates/deploy.rb
86
+ - generators/dwell/templates/known_hosts
87
+ - generators/dwell/templates/known_hosts/github
75
88
  - LICENSE
76
- - README.txt
89
+ - README.markdown
77
90
  has_rdoc: true
78
91
  homepage: http://github.com/bousquet/dwell
79
92
  post_install_message:
data/README.txt DELETED
@@ -1,37 +0,0 @@
1
- DWELL -- Capistrano recipe to setup a production Rails environment on Ubuntu.
2
-
3
-
4
- 1) Install Capistrano2 if you don't already have it:
5
- $ sudo gem install capistrano
6
-
7
- 2) Build this gem:
8
- $ gem build dwell.gemspec
9
-
10
- 3) Install gem with:
11
- $ sudo gem install dwell-0.1.gem
12
-
13
-
14
-
15
- USAGE
16
-
17
- 1) From within your Rails directory, run:
18
- $ capify .
19
-
20
- 2) Click this link for recommended contents of config/deploy.rb:
21
- http://pastie.org/private/lodo1zveqgc2i0rto9idw
22
-
23
- 3) Configure application name, domain, repository location and server name details
24
-
25
- 4) $ cap dwell:install
26
-
27
-
28
-
29
- STACK DETAILS
30
-
31
- 1) Updates Ubuntu sources and distro
32
- 2) Installs Apache2
33
- 3) Installs MySQL5
34
- 4) Installs Subversion and Git
35
- 5) Installs Ruby, RubyGems, Rails and Merb
36
- 6) Installs Passenger module for Apache2 and creates basic config
37
-