shoestrap 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  #Changelog
2
2
 
3
+ ## 0.2.0 - 2013-03-09
4
+
5
+ - Preparations for new servers/workflow:
6
+ A new generator has been added which is called on app generation.
7
+ It adds:
8
+ - unicorn config
9
+ - database config
10
+ - deployment task
11
+
12
+ The generator can be called on exisiting apps as well in order to migrate
13
+ to the new server setup:
14
+
15
+ `rails generate shoestrap:deployment`
16
+
3
17
  ## 0.1.1 - 2013-02-14
4
18
 
5
19
  * Fix: Don't use deleted kuhsaft branch
@@ -16,6 +16,7 @@ module Shoestrap
16
16
  build :setup_bdd_env
17
17
  build :configure_generators
18
18
  build :install_kuhsaft
19
+ build :setup_deployment
19
20
  build :setup_database
20
21
  build :outro
21
22
  end
@@ -4,7 +4,7 @@ require "rails/generators/active_record/model/model_generator"
4
4
 
5
5
  module Shoestrap
6
6
  class CmsGenerator < ActiveRecord::Generators::ModelGenerator
7
- source_root File.expand_path('../templates', __FILE__)
7
+ source_root File.expand_path('../templates/cms', __FILE__)
8
8
  # ... and those files are from: activerecord-3.2.11/lib/rails/generators/active_record/model/templates
9
9
 
10
10
  remove_hook_for :test_framework
@@ -0,0 +1,42 @@
1
+ require 'rails/generators'
2
+ require 'pathname'
3
+
4
+ module Shoestrap
5
+ class DeploymentGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../templates/deployment', __FILE__)
7
+
8
+ def add_unicorn_config
9
+ copy_file 'unicorn.rb', 'config/unicorn.rb'
10
+ end
11
+
12
+ def add_database_config
13
+ template 'database.yml.erb', 'config/database.yml', :force => true
14
+ end
15
+
16
+ def add_deployment_task
17
+ template 'deployment.rake.erb', 'lib/tasks/deployment.rake'
18
+ end
19
+
20
+ protected
21
+
22
+ def app_name
23
+ Pathname.new(Rails.root).basename.to_s
24
+ end
25
+
26
+ def db_credentials_production
27
+ '<%= begin IO.read("#{ENV[\'HOME\']}/.config/' + app_name + '_production/db") rescue "" end %>'
28
+ end
29
+
30
+ def db_credentials_staging
31
+ '<%= begin IO.read("#{ENV[\'HOME\']}/.config/' + app_name + '_staging/db") rescue "" end %>'
32
+ end
33
+
34
+ def restart_unicorn_command
35
+ '#{ENV[\'HOME\']}/unicorn.sh upgrade ' + app_name + '_#{ENV[\'RAILS_ENV\']}'
36
+ end
37
+
38
+ def restart_monit_command
39
+ 'monit -g ' + app_name + '_#{ENV[\'RAILS_ENV\']} monitor'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ production:
2
+ adapter: postgresql
3
+ database: <%= app_name %>_production
4
+ username: <%= app_name %>
5
+ password: <%= db_credentials_production %>
6
+ encoding: unicode
7
+ pool: 5
8
+
9
+ staging:
10
+ adapter: postgresql
11
+ database: <%= app_name %>_staging
12
+ username: <%= app_name %>
13
+ password: <%= db_credentials_staging %>
14
+ encoding: unicode
15
+ pool: 5
16
+
17
+ development:
18
+ adapter: postgresql
19
+ database: <%= app_name %>_development
20
+ username: screenconcept
21
+ password:
22
+ encoding: unicode
23
+ pool: 5
24
+
25
+ test:
26
+ adapter: sqlite3
27
+ database: db/test.sqlite3
28
+ pool: 5
29
+ timeout: 5000
@@ -0,0 +1,19 @@
1
+ desc 'run post-deployment stuff'
2
+ task :post_deploy do
3
+
4
+ # Precompile assets
5
+ puts 'Precompiling assets'
6
+ Rake::Task["assets:precompile"].invoke
7
+
8
+ # Run migrations
9
+ puts 'Running migrations if necessary'
10
+ Rake::Task["db:migrate"].invoke
11
+
12
+ # Trigger Unicorn reexec with 0 downtime
13
+ puts 'restarting unicorns'
14
+ system "<%= restart_unicorn_command %>"
15
+
16
+ # Enable monit monitoring
17
+ puts 'enable monit'
18
+ system "<%= restart_monit_command %>"
19
+ end
@@ -0,0 +1,38 @@
1
+ APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
2
+
3
+ worker_processes 3
4
+ working_directory APP_ROOT
5
+ preload_app true
6
+ timeout 30
7
+
8
+ listen APP_ROOT + "/tmp/unicorn.sock", :backlog => 64
9
+ pid APP_ROOT + "/tmp/unicorn.pid"
10
+
11
+ stderr_path APP_ROOT + "/log/unicorn.stderr.log"
12
+ stdout_path APP_ROOT + "/log/unicorn.stdout.log"
13
+
14
+ before_fork do |server, worker|
15
+ if defined?(ActiveRecord::Base)
16
+ ActiveRecord::Base.connection.disconnect!
17
+ end
18
+
19
+ old_pid = APP_ROOT + '/tmp/unicorn.pid.oldbin'
20
+ if File.exists?(old_pid) && server.pid != old_pid
21
+ begin
22
+ puts "Killing old master"
23
+ Process.kill("QUIT", File.read(old_pid).to_i)
24
+ rescue Errno::ENOENT, Errno::ESRCH
25
+ puts "Old master alerady dead"
26
+ end
27
+ end
28
+ end
29
+
30
+ after_fork do |server, worker|
31
+ if defined?(ActiveRecord::Base)
32
+ ActiveRecord::Base.establish_connection
33
+ end
34
+
35
+ child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
36
+ system("echo #{Process.pid} > #{child_pid}")
37
+ end
38
+
@@ -1,11 +1,7 @@
1
1
  module Shoestrap
2
2
  class AppBuilder < Rails::AppBuilder
3
3
  def readme
4
- config = {
5
- app_name: app_name
6
- }
7
-
8
- template 'README.md.erb', 'README.md', config
4
+ template 'README.md.erb', 'README.md'
9
5
  end
10
6
 
11
7
  def gemfile
@@ -25,9 +21,6 @@ module Shoestrap
25
21
  end
26
22
 
27
23
  def setup_database
28
- # TODO: implement
29
- # use pg db sample
30
- # rake db:create?
31
24
  rake 'db:migrate'
32
25
  rake 'db:seed'
33
26
  end
@@ -94,6 +87,10 @@ module Shoestrap
94
87
  template '_main_navigation.html.haml.erb', 'app/views/kuhsaft/cms/admin/_main_navigation.html.haml'
95
88
  end
96
89
 
90
+ def setup_deployment
91
+ generate 'shoestrap:deployment'
92
+ end
93
+
97
94
  def outro
98
95
  say 'Application is ready!'
99
96
  end
data/shoestrap.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "shoestrap"
6
- s.version = '0.1.1'
6
+ s.version = '0.2.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Immanuel Häussermann", "Felipe Kaufmann", "Phil Schilter", "Noëlle Rosenberg"]
9
9
  s.email = "info@screenconcept.ch"
@@ -2,11 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  <%= rails_gemfile_entry -%>
4
4
 
5
- <%= database_gemfile_entry -%>
6
-
7
- <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%>
8
-
9
5
  <%= assets_gemfile_entry %>
6
+
10
7
  <%= javascript_gemfile_entry -%>
11
8
 
12
9
  gem 'bcrypt-ruby', '~> 3.0.0'
@@ -23,15 +20,17 @@ gem 'mail'
23
20
  gem 'fabrication'
24
21
  gem 'shoestrap'
25
22
  gem 'kuhsaft'
23
+ gem 'pg'
26
24
 
27
25
  group :development, :test do
28
26
  gem 'pry'
29
27
  gem 'rspec-rails'
28
+ gem 'cucumber-rails'
30
29
  end
31
30
 
32
31
  group :test do
33
32
  gem 'database_cleaner'
34
- gem 'cucumber-rails'
33
+ gem 'sqlite3'
35
34
  end
36
35
 
37
36
  group :development do
@@ -1,4 +1,4 @@
1
- # <%= config[:app_name] %>
1
+ # <%= app_name %>
2
2
 
3
3
  ## IMPORTANT REMARKS
4
4
 
@@ -13,7 +13,6 @@ The app runs on the <server> server
13
13
 
14
14
  * Home:
15
15
  * Web:
16
- * External:
17
16
 
18
17
  ### Production
19
18
  * The app runs on the <server> server
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoestrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-02-14 00:00:00.000000000 Z
15
+ date: 2013-03-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec
@@ -81,10 +81,14 @@ files:
81
81
  - bin/shoestrap
82
82
  - lib/generators/shoestrap/app_generator.rb
83
83
  - lib/generators/shoestrap/cms_generator.rb
84
- - lib/generators/shoestrap/templates/migration.rb
85
- - lib/generators/shoestrap/templates/model.rb
86
- - lib/generators/shoestrap/templates/model.yml.erb
87
- - lib/generators/shoestrap/templates/view.yml.erb
84
+ - lib/generators/shoestrap/deployment_generator.rb
85
+ - lib/generators/shoestrap/templates/cms/migration.rb
86
+ - lib/generators/shoestrap/templates/cms/model.rb
87
+ - lib/generators/shoestrap/templates/cms/model.yml.erb
88
+ - lib/generators/shoestrap/templates/cms/view.yml.erb
89
+ - lib/generators/shoestrap/templates/deployment/database.yml.erb
90
+ - lib/generators/shoestrap/templates/deployment/deployment.rake.erb
91
+ - lib/generators/shoestrap/templates/deployment/unicorn.rb
88
92
  - lib/shoestrap.rb
89
93
  - lib/shoestrap/app_builder.rb
90
94
  - shoestrap.gemspec