deployer_files 0.0.2

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/.gitignore ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deployer_generators.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deployer_files (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ deployer_files!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Adam Dratwinski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # DeployerGenerators
2
+
3
+ Useful generators for creating files needed to deployment in way Ryan Bytes shows in his Railscasts.
4
+ Created for my enviroment, but maybe useful if you planning to write something similar :-)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'deployer_generators'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install deployer_generators
19
+
20
+ ## Usage
21
+
22
+ run `rails g deployer:files` and answer folllowed questions
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:features) do |t|
7
+ t.cucumber_opts = "features --format progress"
8
+ end
9
+
10
+ task :default => :features
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/deployer_files/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Adam Dratwinski"]
6
+ gem.email = ["adam.dratwinski@gmail.com"]
7
+ gem.description = "Useful generators for creating files needed to deployment in way Ryan Bytes shows in his Railscasts."
8
+ gem.summary = "Useful generators for creating files needed to deployment in way Ryan Bytes shows in his Railscasts."
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "deployer_files"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DeployerFiles::VERSION
17
+ end
@@ -0,0 +1,3 @@
1
+ module DeployerFiles
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Will generate files needed for deployment
3
+
4
+ Example:
5
+ rails generate deployer:files
6
+
7
+ This will create:
8
+ Capfile
9
+ deploy.rb
10
+ nginx.conf
11
+ unicorn.rb
12
+ unicorn_init.sh
@@ -0,0 +1,60 @@
1
+ module Deployer
2
+ module Generators
3
+ class FilesGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ attr_accessor :app_name, :app_path, :app_user, :application_host, :server_host, :git_path, :git_branch
6
+
7
+ def run_files_generator
8
+ default_app_name = Rails.application.class.parent_name.underscore
9
+
10
+ self.app_name = ask("Remote application name (#{default_app_name}):")
11
+ self.app_name = default_app_name if self.app_name.blank?
12
+
13
+ self.app_user = ask("Remote application deployer name:")
14
+
15
+ self.app_path = ask("Remote application path:")
16
+
17
+ self.server_host = ask("Remote server host:")
18
+ self.application_host = ask("Application host:")
19
+
20
+ self.git_path = ask("Remote git path:")
21
+ self.git_branch = ask("Remote git branch: (master)")
22
+ self.git_branch = "master" if self.git_branch.blank?
23
+
24
+ puts "You have provided:"
25
+ puts ""
26
+ puts "App Name: #{app_name}"
27
+ puts "App User: #{app_user}"
28
+ puts "App Path: #{app_path}"
29
+ puts "Server Host: #{server_host}"
30
+ puts "Application Host: #{application_host}"
31
+ puts "Git Path: #{git_path}"
32
+ puts "Git Branch: #{git_branch}"
33
+ puts ""
34
+ if yes?("Is this ok?")
35
+ template "deploy.rb", "config/deploy.rb"
36
+ template "nginx.conf", "config/nginx.conf"
37
+ template "unicorn.rb", "config/unicorn.rb"
38
+ template "unicorn_init.sh", "config/unicorn_init.sh"
39
+ template "Capfile", "Capfile"
40
+
41
+ gem "capistrano"
42
+ gem "unicorn"
43
+
44
+ system "chmod +x config/unicorn_init.sh"
45
+
46
+ puts ""
47
+ puts ""
48
+ puts "====================================="
49
+ puts "= ensure you've created remote repo ="
50
+ puts "= then push all local changes and ="
51
+ puts "= `cap deploy:setup` ="
52
+ puts "= `cap deploy:cold` ="
53
+ puts "====================================="
54
+ else
55
+ self.run_files_generator
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ load 'deploy'
2
+ load 'deploy/assets'
3
+ Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
4
+ load 'config/deploy' # remove this line to skip loading any of the default tasks
5
+
@@ -0,0 +1,66 @@
1
+ require "bundler/capistrano"
2
+
3
+ server "<%= server_host %>", :web, :app, :db, primary: true
4
+
5
+ set :application, "<%= app_name %>"
6
+ set :user, "<%= app_user %>"
7
+ set :deploy_to, "<%= app_path %>"
8
+ set :deplay_via, :remote_cache
9
+ set :use_sudo, false
10
+
11
+ set :scm, :git
12
+ set :repository, "<%= git_path %>"
13
+ set :branch, "<%= git_branch %>"
14
+
15
+ default_run_options[:pty] = true
16
+ ssh_options[:forward_agent] = true
17
+
18
+ after "deploy", "deploy:cleanup"
19
+
20
+ namespace :deploy do
21
+ %w[start stop restart].each do |command|
22
+ desc "#{command} unicorn server"
23
+ task command, roles: :app, except: {no_release: true} do
24
+ run "/etc/init.d/unicorn_#{application} #{command}"
25
+ end
26
+ end
27
+
28
+ task :setup_config, roles: :app do
29
+ sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
30
+ sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
31
+ run "mkdir -p #{shared_path}/config"
32
+ put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
33
+ puts "Now edit the config files in #{shared_path}."
34
+ end
35
+ after "deploy:setup", "deploy:setup_config"
36
+
37
+ task :symlink_config, roles: :app do
38
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
39
+ end
40
+ after "deploy:finalize_update", "deploy:symlink_config"
41
+
42
+ desc "Make sure local git is in sync with remote."
43
+ task :check_revision, roles: :web do
44
+ unless `git rev-parse HEAD` == `git rev-parse origin/master`
45
+ puts "WARNING: HEAD is not the same as origin/master"
46
+ puts "Run `git push` to sync changes."
47
+ exit
48
+ end
49
+ end
50
+ before "deploy", "deploy:check_revision"
51
+
52
+ ############# TO DEPLOY FASTER UNCOMMENT THESE LINES AFTER DEPLOY COLD
53
+ #
54
+ # namespace :assets do
55
+ #
56
+ # task :precompile, :roles => :web, :except => { :no_release => true } do
57
+ # from = source.next_revision(current_revision)
58
+ # if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
59
+ # run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
60
+ # else
61
+ # logger.info "Skipping asset pre-compilation because there were no asset changes"
62
+ # end
63
+ # end
64
+ # end
65
+ end
66
+
@@ -0,0 +1,31 @@
1
+ upstream <%= app_name %> {
2
+ server unix:/tmp/unicorn.<%= app_name %>.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80;
7
+ server_name <%= application_host %>;
8
+
9
+ root <%= app_path %>/public;
10
+
11
+ try_files $uri/index.html $uri @<%= app_name %>;
12
+
13
+ location ~ ^/(assets)/ {
14
+ gzip_static on;
15
+ expires max;
16
+ add_header Cache-Controll public;
17
+ add_header ETag "";
18
+ break;
19
+ }
20
+
21
+ location @<%= app_name %> {
22
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
23
+ proxy_set_header Host $http_host;
24
+ proxy_redirect off;
25
+ proxy_pass http://<%= app_name %>;
26
+ }
27
+
28
+ error_page 500 502 503 504 /500.html;
29
+ client_max_body_size 4G;
30
+ keepalive_timeout 10;
31
+ }
@@ -0,0 +1,12 @@
1
+ APP_PATH = "<%= app_path %>/current"
2
+ APP_NAME = "<%= app_name %>" #gittest
3
+
4
+ working_directory APP_PATH
5
+
6
+ pid "#{APP_PATH}/tmp/pids/unicorn.pid"
7
+ stderr_path "#{APP_PATH}/log/unicorn.log"
8
+ stdout_path "#{APP_PATH}/log/unicorn.log"
9
+
10
+ listen "/tmp/unicorn.#{APP_NAME}.sock"
11
+ worker_processes 2
12
+ timeout 30
@@ -0,0 +1,93 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= app_path %>/current #SET THIS TO WORK!
16
+ PID=$APP_ROOT/tmp/pids/unicorn.pid
17
+ CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
18
+ AS_USER=<%= app_user %> #CONSIDER TO SET THIS AS WELL
19
+ set -u
20
+
21
+ OLD_PIN="$PID.oldbin"
22
+
23
+ sig () {
24
+ test -s "$PID" && kill -$1 `cat $PID`
25
+ }
26
+
27
+ oldsig () {
28
+ test -s $old_pid && kill -$1 `cat $old_pid`
29
+ }
30
+
31
+
32
+ sig () {
33
+ test -s "$PID" && kill -$1 `cat $PID`
34
+ }
35
+
36
+ oldsig () {
37
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
38
+ }
39
+
40
+ run () {
41
+ if [ "$(id -un)" = "$AS_USER" ]; then
42
+ eval $1
43
+ else
44
+ su -c "$1" - $AS_USER
45
+ fi
46
+ }
47
+
48
+ case "$1" in
49
+ start)
50
+ sig 0 && echo >&2 "Already running" && exit 0
51
+ run "$CMD"
52
+ ;;
53
+ stop)
54
+ sig QUIT && exit 0
55
+ echo >&2 "Not running"
56
+ ;;
57
+ force-stop)
58
+ sig TERM && exit 0
59
+ echo >&2 "Not running"
60
+ ;;
61
+ restart|reload)
62
+ sig HUP && echo reloaded OK && exit 0
63
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
64
+ run "$CMD"
65
+ ;;
66
+ upgrade)
67
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
68
+ then
69
+ n=$TIMEOUT
70
+ while test -s $OLD_PIN && test $n -ge 0
71
+ do
72
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
73
+ done
74
+ echo
75
+
76
+ if test $n -lt 0 && test -s $OLD_PIN
77
+ then
78
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
79
+ exit 1
80
+ fi
81
+ exit 0
82
+ fi
83
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
84
+ run "$CMD"
85
+ ;;
86
+ reopen-logs)
87
+ sig USR1
88
+ ;;
89
+ *)
90
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
91
+ exit 1
92
+ ;;
93
+ esac
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployer_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Dratwinski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Useful generators for creating files needed to deployment in way Ryan
15
+ Bytes shows in his Railscasts.
16
+ email:
17
+ - adam.dratwinski@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - deployer_files.gemspec
29
+ - lib/deployer_files/version.rb
30
+ - lib/generators/deployer/files/USAGE
31
+ - lib/generators/deployer/files/files_generator.rb
32
+ - lib/generators/deployer/files/templates/Capfile
33
+ - lib/generators/deployer/files/templates/deploy.rb
34
+ - lib/generators/deployer/files/templates/nginx.conf
35
+ - lib/generators/deployer/files/templates/unicorn.rb
36
+ - lib/generators/deployer/files/templates/unicorn_init.sh
37
+ homepage: ''
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.15
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Useful generators for creating files needed to deployment in way Ryan Bytes
61
+ shows in his Railscasts.
62
+ test_files: []