funkenplate 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/bin/funkenplate +3 -6
  3. data/lib/funkenplate.rb +49 -0
  4. data/lib/modules/capistrano.rb +123 -0
  5. data/lib/modules/database.rb +10 -0
  6. data/lib/modules/extensions.rb +17 -0
  7. data/lib/modules/finished.rb +1 -0
  8. data/lib/modules/general.rb +14 -0
  9. data/lib/modules/git.rb +37 -0
  10. data/lib/modules/secrets.rb +67 -0
  11. data/lib/string.rb +17 -0
  12. metadata +60 -41
  13. data/README.textile +0 -37
  14. data/funkenplate.rb +0 -263
  15. data/lib/dummy +0 -0
  16. data/templates/config/deploy/header.rb +0 -17
  17. data/templates/config/deploy/helper.rb +0 -53
  18. data/templates/config/deploy/options.rb +0 -19
  19. data/templates/config/deploy/repositories/fs.rb +0 -7
  20. data/templates/config/deploy/repositories/fs_remote_fs +0 -1
  21. data/templates/config/deploy/repositories/fs_remote_git +0 -1
  22. data/templates/config/deploy/repositories/github.rb +0 -5
  23. data/templates/config/deploy/repositories/github_remote +0 -1
  24. data/templates/config/deploy/tasks.rb +0 -116
  25. data/templates/config/initializers/directories.rb +0 -9
  26. data/templates/gitignore +0 -15
  27. data/templates/lib/core_extensions/array.rb +0 -9
  28. data/templates/lib/core_extensions/object.rb +0 -19
  29. data/templates/lib/core_extensions/string.rb +0 -7
  30. data/templates/lib/gem_extensions/formtastic.rb +0 -21
  31. data/templates/lib/rails_extensions/action_controller_base.rb +0 -37
  32. data/templates/lib/rails_extensions/action_controller_restful_test_case.rb +0 -56
  33. data/templates/lib/rails_extensions/active_record.rb +0 -5
  34. data/templates/lib/rails_extensions/application_helper.rb +0 -10
  35. data/templates/lib/restful.rb +0 -81
  36. data/templates/tmproj +0 -26
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 funkensturm.
1
+ Copyright (c) 2011 funkensturm.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -5,9 +5,6 @@ require 'rubygems'
5
5
  puts
6
6
  puts "Version: #{Gem.source_index.find_name('funkenplate').last.version.version}"
7
7
  puts
8
- puts "Online Usage:"
9
- puts "rails myapp --template http://github.com/funkensturm/funkenplate/raw/master/funkenplate.rb"
10
- puts
11
- puts "Offline Usage:"
12
- puts "rails myapp --template #{Gem.source_index.find_name('funkenplate').last.full_gem_path}/funkenplate.rb"
13
- puts
8
+ puts "Usage:"
9
+ puts "rails new myapp --template #{Gem.source_index.find_name('funkenplate').last.full_gem_path}/lib/funkenplate.rb"
10
+ puts
@@ -0,0 +1,49 @@
1
+ # –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
2
+ # This template initializes a Rails app with git and Capistrano
3
+ # for a repository located on the application server or Github.
4
+ #
5
+ # Installation: (sudo) gem install funkenplate
6
+ # Documentation: http://github.com/funkensturm/funkenplate
7
+ # Usage: Run "funkenplate" in your Terminal for instructions
8
+ # –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
9
+
10
+ unless defined?(Rails)
11
+ puts 'This is not a standalone application, it is to be used as a template for Rails.'
12
+ exit 1
13
+ end
14
+
15
+ unless Gem.available?('funkenplate')
16
+ say_status :error, 'Please install the funkenplate gem first with "gem install funkenplate".', :red
17
+ exit 1
18
+ end
19
+
20
+ def shout_status(*args)
21
+ puts
22
+ say_status(*args)
23
+ puts
24
+ end
25
+
26
+ def ask(question)
27
+ puts
28
+ say_status :QUESTION, question, :blue
29
+ print ' ' * 16
30
+ $stdin.gets.strip
31
+ end
32
+
33
+ def yes?(question)
34
+ answer = ask("#{question} (ENTER: yes)").downcase
35
+ puts
36
+ answer == '' or answer == "\n" or answer == 'y' or answer == 'yes' or answer == 'j' or answer == 'ja'
37
+ end
38
+
39
+ say_status :WELCOME, 'Welcome to funkenplate', :green
40
+
41
+ modules_path = "#{Gem.source_index.find_name('funkenplate').last.full_gem_path}/lib/modules"
42
+
43
+ apply "#{modules_path}/secrets.rb"
44
+ apply "#{modules_path}/general.rb"
45
+ apply "#{modules_path}/extensions.rb"
46
+ apply "#{modules_path}/database.rb"
47
+ apply "#{modules_path}/git.rb"
48
+ apply "#{modules_path}/capistrano.rb"
49
+ apply "#{modules_path}/finished.rb"
@@ -0,0 +1,123 @@
1
+ say_status :CAPISTRANO, 'Capifying application...', :yellow
2
+
3
+ deploy_header = <<-END
4
+ # ——————————————
5
+ # Setting up RVM
6
+ # ——————————————
7
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
8
+ require 'rvm/capistrano'
9
+ require 'bundler/capistrano'
10
+
11
+ # ––––––––––––––––––
12
+ # APPLICATION SERVER
13
+ # ————————————————––
14
+ set :application, "~app_name~"
15
+ set :user, "~user~"
16
+ set :domain, "~domain~"
17
+ set :port, ~port~
18
+ set :deploy_to, '/apps/~app_name~'
19
+
20
+ # ––––––––––––––
21
+ # DEPLOY OPTIONS
22
+ # —————————————–
23
+ role :app, domain
24
+ role :web, domain
25
+ role :db, domain, :primary => true
26
+ set :scm, :git
27
+ set :use_sudo, false
28
+ set :keep_releases, 3
29
+ set :default_run_options, { :pty => true }
30
+ set :ssh_options, {
31
+ :forward_agent => true,
32
+ :paranoid => false,
33
+ :keys => ["~keys~"],
34
+ :port => port
35
+ }
36
+
37
+ END
38
+
39
+ deploy_github = <<-END
40
+ # ––––––––––––––––––
41
+ # REPOSITORY: GITHUB
42
+ # ––––––––––––––––––
43
+ set :repository, "git://github.com/~github_account~/~app_name~.git"
44
+
45
+ END
46
+
47
+ deploy_fs = <<-END
48
+ # ––––––––––––––
49
+ # REPOSITORY: FS
50
+ # ––––––––––––––
51
+ set :repository, "file:///home/git/repositories/~app_name~"
52
+ set :local_repository, "fs.git:/home/git/repositories/~app_name~"
53
+ set :deploy_via, :remote_cache
54
+
55
+ END
56
+
57
+ deploy_footer = <<-END
58
+ # ———————————–––––—
59
+ # FUNKENPLATE HOOKS
60
+ # ————————————–––––
61
+ after 'deploy:setup', 'deploy:setup_additions'
62
+ after 'deploy:update_code', 'deploy:additional_symlinks'
63
+
64
+ # ———————————–
65
+ # DEPLOY TASKS
66
+ # ————————————
67
+ namespace :deploy do
68
+
69
+ # Happens after initial setup
70
+ desc "Add some more dirs into shared"
71
+ task :setup_additions do
72
+ mkshared 'private'
73
+ mkshared 'config'
74
+ run "touch \#{shared_database}"
75
+ logger.important "REMEMBER TO EDIT \#{shared_database} ON THE SERVER - NOT in THIS shell!" unless test_remote? :file_with_content, repository_on_server?
76
+ end
77
+
78
+ # Happens with each release
79
+ desc "Link in critical data from shared and install bundles"
80
+ task :additional_symlinks do
81
+ symlinker 'config/database.yml'
82
+ symlinker 'private'
83
+ end
84
+
85
+ # Overwriting default spin scripts
86
+ desc 'Restart passenger'
87
+ task :restart, :roles => :app, :except => { :no_release => true } do
88
+ run "touch \#{File.join(current_path,'tmp','restart.txt')}"
89
+ end
90
+ task :start do; end
91
+ task :stop do; end
92
+
93
+ end
94
+
95
+ # ———————————–––
96
+ # HELPER METHODS
97
+ # ————————————––
98
+
99
+ # Creates a symlink from <tt>deploy_to/shared/...</tt> to <tt>release_path/...</tt>
100
+ # If <tt>to</tt> is omitted, the release path mirrors in the shared path
101
+ def symlinker(from, to='')
102
+ to = from if to.blank?
103
+ run "ln -nfs \#{File.join deploy_to, 'shared', from} \#{File.join release_path, to}"
104
+ end
105
+
106
+ END
107
+
108
+
109
+ say_status :CAPISTRANO, 'Capify...', :magenta
110
+ capify!
111
+
112
+ say_status :CAPISTRANO, 'Backup original deploy.rb...', :magenta
113
+ run 'cp config/deploy.rb config/deploy.rb.sample'
114
+
115
+ say_status :CAPISTRANO, 'Generating deploy.fs.rb for repositories on fs server...', :magenta
116
+ file 'config/deploy.fs.rb', deploy_header.personalize(app_name, @secrets) + deploy_fs.personalize(app_name, @secrets) + deploy_footer
117
+
118
+ say_status :CAPISTRANO, 'Generating deploy.github.rb for repositories on github.com...', :magenta
119
+ file 'config/deploy.github.rb', deploy_header.personalize(app_name, @secrets) + deploy_github.personalize(app_name, @secrets) + deploy_footer
120
+
121
+ say_status :GIT, 'Commiting capistrano changes...', :magenta
122
+ git :add => '.'
123
+ git :commit => "-a -m 'Capified the app.'"
@@ -0,0 +1,10 @@
1
+ say_status :TASK, 'Creating sample database.yml...', :magenta
2
+ file 'config/database.yml.sample', <<-END
3
+ # HINT: If you are on the server, you might want to delete
4
+ # the "development" and "test" database definitions in this file.
5
+ # This way you won't accidentally work on a development database.
6
+ #
7
+
8
+
9
+ #{File.read('config/database.yml')}
10
+ END
@@ -0,0 +1,17 @@
1
+ say_status :TASK, 'Creating example extension...', :magenta
2
+ lib 'core_extensions/object.rb', <<-END
3
+ module ObjectExtensions
4
+
5
+ end
6
+
7
+ class Object #:nodoc:
8
+ include ObjectExtensions
9
+ end
10
+ END
11
+
12
+ say_status :TASK, 'Creating initializer for lib extensions...', :magenta
13
+ initializer 'extensions.rb', <<-END
14
+ Dir.glob(File.join(Rails.root, 'lib', 'core_extensions', '*.rb')) { |file| require file }
15
+ Dir.glob(File.join(Rails.root, 'lib', 'rails_extensions', '*.rb')) { |file| require file }
16
+ Dir.glob(File.join(Rails.root, 'lib', 'gem_extensions', '*.rb')) { |file| require file }
17
+ END
@@ -0,0 +1 @@
1
+ shout_status :FINISHED, 'Congratulations.', :green
@@ -0,0 +1,14 @@
1
+ say_status :TASKS, 'Running general tasks...', :yellow
2
+
3
+ say_status :TASK, 'Clearing tmp directories...', :magenta
4
+ ['tmp/pids', 'tmp/sessions', 'tmp/sockets', 'tmp/cache'].each { |dir| remove_file dir }
5
+
6
+ say_status :TASK, 'Creating additional directories...', :magenta
7
+ ['private', "lib/#{app_name}", 'lib/core_extensions', 'lib/rails_extensions'].each { |dir| empty_directory dir }
8
+
9
+ say_status :TASK, 'Deleting boring files...', :magenta
10
+ ['public/index.html', 'public/images/rails.png'].each { |dir| remove_file dir }
11
+
12
+ say_status :TASK, 'Doing some beauty errands...', :magenta
13
+ run 'echo TODO > README'
14
+ run 'mv README README.textile'
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'string')
2
+
3
+ say_status :GIT, 'Gitifying application...', :yellow
4
+
5
+ say_status :GIT, 'Create .gitignore recursively in every empty directory...', :magenta
6
+ run 'find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;'
7
+
8
+ say_status :GIT, 'Create .gitignore in root...', :magenta
9
+ remove_file '.gitignore'
10
+ file '.gitignore', <<-END
11
+ .DS_Store
12
+ .bundle
13
+ .tmproj
14
+ tmtags
15
+ log/*.log
16
+ log/*.pid
17
+ db/*.db
18
+ db/*.sqlite3
19
+ db/schema.rb
20
+ tmp/*
21
+ tmp/**/*
22
+ doc/api
23
+ doc/app
24
+ config/database.yml
25
+ config/deploy*.rb
26
+ private
27
+ pkg
28
+ END
29
+
30
+ say_status :GIT, 'Initial commit...', :magenta
31
+ git :init
32
+ git :add => '.'
33
+ git :commit => "-a -m 'Initial commit.'"
34
+
35
+ say_status :GIT, 'Adding repository remote aliases for the fs server ...', :magenta
36
+ run 'git remote add fs fs:/home/git/repositories/~app_name~'.personalize(app_name, @secrets)
37
+ run 'git remote add fs.git fs.git:/home/git/repositories/~app_name~'.personalize(app_name, @secrets)
@@ -0,0 +1,67 @@
1
+ require 'yaml'
2
+ require File.join(File.dirname(__FILE__), '..', 'string')
3
+
4
+ # This is where we will search for funkenplate.yml containing individual secrets
5
+ secret_files = []
6
+ directories = ['..', ENV['HOME'], File.join(ENV['HOME'], '.ssh')]
7
+ files = ['funkenplate.yml', '.funkenplate.yml']
8
+ directories.each { |directory| files.each { |file| secret_files << File.expand_path(File.join(directory, file)) } }
9
+
10
+ # –––––––––––––––
11
+ # DEFAULT SECRETS
12
+ # –––––––––––––––
13
+
14
+ # Default secrets
15
+ default_secrets = {
16
+ :version => Gem.source_index.find_name('funkenplate').last.version.version,
17
+ :deploy => {
18
+ :app_server => {
19
+ :user => ENV['USER'].downcase,
20
+ :domain => 'YOUR_SERVER_DOMAIN_OR_IP_GOES_HERE',
21
+ :port => 22,
22
+ :keys => File.expand_path(File.join(ENV['HOME'], '.ssh', 'YOUR_PRIVATE_KEY'))
23
+ },
24
+ :github => {
25
+ :account => 'YOUR_GITHUB_ACCOUNT_NAME_GOES_HERE'
26
+ }
27
+ }
28
+ }
29
+
30
+ # –––––––––––––––––
31
+ # OBTAINING SECRETS
32
+ # –––––––––––––––––
33
+
34
+ @secrets = default_secrets
35
+
36
+ if secret_file = secret_files.find { |file| File.file? file }
37
+ @secrets = YAML.load_file secret_file
38
+ else
39
+ shout_status :error, "I could not find funkenplate.yml anywhere but I created one for you. You must edit it and then re-apply this template.", :red
40
+ say_status :info, "Note that you can put that yml file into any of these locations (top ones with higher priority):", :yellow
41
+ secret_files.each { |location| say_status '', " #{location}" }
42
+ shout_status :create, secret_files.first
43
+ File.open(secret_files.first, 'w') { |file| file.write YAML::dump(default_secrets) }
44
+ exit 3
45
+ end
46
+
47
+ shout_status :ENVIRONMENT, "These is the stuff we're working with here:", :yellow
48
+ print_table [
49
+ ['Application name:', app_name],
50
+ ['Application location:', destination_root],
51
+ ['Funkenplate gem:', Gem.source_index.find_name('funkenplate').last.full_gem_path],
52
+ ['Secret file:', secret_file],
53
+ ], :ident => 18
54
+
55
+ shout_status :SECRETS, "I was able to obtain these secrets from the secret file:", :yellow
56
+ print_table [
57
+ ['Application Server domain:', @secrets[:deploy][:app_server][:domain]],
58
+ ['Application Server SSH user:', @secrets[:deploy][:app_server][:user]],
59
+ ['Application Server SSH port:', @secrets[:deploy][:app_server][:port]],
60
+ ['Github account:', @secrets[:deploy][:github][:account]],
61
+ ['Location of your SSH key:', @secrets[:deploy][:app_server][:keys]],
62
+ ], :ident => 18
63
+
64
+ unless yes?("Are these values correct?")
65
+ shout_status :EXITING, "OK, please edit this file first: #{secret_file}"
66
+ exit 1
67
+ end
@@ -0,0 +1,17 @@
1
+ module StringExtensions
2
+
3
+ def personalize(app_name, hash)
4
+ self.
5
+ gsub('~app_name~', app_name).
6
+ gsub('~github_account~', hash[:deploy][:app_server][:user].to_s).
7
+ gsub('~domain~', hash[:deploy][:app_server][:domain].to_s).
8
+ gsub('~user~', hash[:deploy][:app_server][:user].to_s).
9
+ gsub('~port~', hash[:deploy][:app_server][:port].to_s).
10
+ gsub('~keys~', hash[:deploy][:app_server][:keys].to_s)
11
+ end
12
+
13
+ end
14
+
15
+ class String #:nodoc:
16
+ include StringExtensions
17
+ end
metadata CHANGED
@@ -1,86 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funkenplate
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 25
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 0
8
- - 5
9
- version: 0.0.5
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
- - Captain Future
13
+ - funkensturm.
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-01 00:00:00 +02:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: " funkenplate is a Rails Template according to the funkensturm. standards.\n"
18
+ date: 2011-04-14 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 23
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ name: bundler
33
+ prerelease: false
34
+ type: :development
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 1
43
+ segments:
44
+ - 1
45
+ - 5
46
+ - 1
47
+ version: 1.5.1
48
+ name: jeweler
49
+ prerelease: false
50
+ type: :development
51
+ requirement: *id002
52
+ description: funkenplate is a Rails Template according to the funkensturm. standards.
22
53
  email:
23
54
  executables:
24
55
  - funkenplate
25
56
  extensions: []
26
57
 
27
- extra_rdoc_files:
28
- - README.textile
58
+ extra_rdoc_files: []
59
+
29
60
  files:
30
- - init.rb
31
- - funkenplate.rb
32
61
  - MIT-LICENSE
33
- - README.textile
34
- - templates/config/deploy/header.rb
35
- - templates/config/deploy/helper.rb
36
- - templates/config/deploy/options.rb
37
- - templates/config/deploy/repositories/fs.rb
38
- - templates/config/deploy/repositories/fs_remote_fs
39
- - templates/config/deploy/repositories/fs_remote_git
40
- - templates/config/deploy/repositories/github.rb
41
- - templates/config/deploy/repositories/github_remote
42
- - templates/config/deploy/tasks.rb
43
- - templates/config/initializers/directories.rb
44
- - templates/gitignore
45
- - templates/lib/core_extensions/array.rb
46
- - templates/lib/core_extensions/object.rb
47
- - templates/lib/core_extensions/string.rb
48
- - templates/lib/gem_extensions/formtastic.rb
49
- - templates/lib/rails_extensions/action_controller_base.rb
50
- - templates/lib/rails_extensions/action_controller_restful_test_case.rb
51
- - templates/lib/rails_extensions/active_record.rb
52
- - templates/lib/rails_extensions/application_helper.rb
53
- - templates/lib/restful.rb
54
- - templates/tmproj
55
- - lib/dummy
56
62
  - bin/funkenplate
57
- has_rdoc: true
63
+ - init.rb
64
+ - lib/funkenplate.rb
65
+ - lib/modules/capistrano.rb
66
+ - lib/modules/database.rb
67
+ - lib/modules/extensions.rb
68
+ - lib/modules/finished.rb
69
+ - lib/modules/general.rb
70
+ - lib/modules/git.rb
71
+ - lib/modules/secrets.rb
72
+ - lib/string.rb
58
73
  homepage: http://github.com/funkensturm/funkenplate
59
- licenses: []
60
-
74
+ licenses:
75
+ - MIT
61
76
  post_install_message:
62
77
  rdoc_options: []
63
78
 
64
79
  require_paths:
65
80
  - lib
66
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
67
83
  requirements:
68
84
  - - ">="
69
85
  - !ruby/object:Gem::Version
86
+ hash: 3
70
87
  segments:
71
88
  - 0
72
89
  version: "0"
73
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
74
92
  requirements:
75
93
  - - ">="
76
94
  - !ruby/object:Gem::Version
95
+ hash: 3
77
96
  segments:
78
97
  - 0
79
98
  version: "0"
80
99
  requirements: []
81
100
 
82
101
  rubyforge_project:
83
- rubygems_version: 1.3.6
102
+ rubygems_version: 1.7.2
84
103
  signing_key:
85
104
  specification_version: 3
86
105
  summary: Rails Template used by funkensturm.