rails_deployer 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b502a8937a57384ae06cc336a20186aa8ff676a
4
+ data.tar.gz: 02fdbeb08baa1f0aef75c05ff97983c3278596b9
5
+ SHA512:
6
+ metadata.gz: 7ad826f9f28f2d27ab2c4f5b66812137437652cc3bd0643ce9458aa15d992f80fcfe2942a65e4a0465303a0b722642d047d72eb32fdfd0f622fc2565f6103b58
7
+ data.tar.gz: ce4811d904694d437f20efcff0991b1656ff36c5969536976da9c5ce454fdf7e6ee0c4119f68540987f3b2e1c77bd32515284896664a27aa995e4de28df5e035
@@ -0,0 +1,22 @@
1
+ .DS_Store
2
+ .idea
3
+ pkg/*
4
+
5
+ *.gem
6
+ *.rbc
7
+ .bundle
8
+ .config
9
+ coverage
10
+ InstalledFiles
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
@@ -0,0 +1,5 @@
1
+ Metrics/AbcSize:
2
+ Max: 18
3
+
4
+ Metrics/LineLength:
5
+ Max: 100
@@ -0,0 +1 @@
1
+ 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', group: :test
4
+
5
+ # Specify your gem's dependencies in kp-rails-deployer.gemspec
6
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_deployer (0.1.1)
5
+ net-ssh (~> 2.6, >= 2.6.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ diff-lcs (1.2.5)
14
+ net-ssh (2.9.2)
15
+ parser (2.2.2.6)
16
+ ast (>= 1.1, < 3.0)
17
+ powerpack (0.1.1)
18
+ rainbow (2.0.0)
19
+ rake (10.4.2)
20
+ rspec (3.3.0)
21
+ rspec-core (~> 3.3.0)
22
+ rspec-expectations (~> 3.3.0)
23
+ rspec-mocks (~> 3.3.0)
24
+ rspec-core (3.3.2)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-expectations (3.3.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-mocks (3.3.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.3.0)
32
+ rspec-support (3.3.0)
33
+ rubocop (0.32.1)
34
+ astrolabe (~> 1.3)
35
+ parser (>= 2.2.2.5, < 3.0)
36
+ powerpack (~> 0.1)
37
+ rainbow (>= 1.99.1, < 3.0)
38
+ ruby-progressbar (~> 1.4)
39
+ ruby-progressbar (1.7.5)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ rails_deployer!
46
+ rake (~> 10.3, >= 10.3.2)
47
+ rspec
48
+ rubocop
49
+
50
+ BUNDLED WITH
51
+ 1.10.6
@@ -0,0 +1,25 @@
1
+ # Rails deployer
2
+
3
+ Contains common rake tasks for being able to deploy to heroku or bring's own systems
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails_deployer', git: 'git@github.com:bring/kp-rails-deployer.git'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Clone this gem
16
+
17
+ git clone git@github.com:bring/kp-rails-deployer.git
18
+
19
+ ## Usage examples
20
+
21
+ rake qa:deploy
22
+ rake qa:deploy branch=topic_branch
23
+
24
+ rake production:deploy
25
+ rake production:deploy branch=topic_branch
@@ -0,0 +1,23 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: [:spec, :rubocop]
11
+
12
+ module RuboCop
13
+ module Cop
14
+ module Style
15
+ # Enforce double indent on continued lines
16
+ class MultilineOperationIndentation
17
+ def correct_indentation(*)
18
+ configured_indentation_width * 2
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ require 'rails_deployer/version'
2
+ require 'rails_deployer/common'
3
+ require 'rails_deployer/bring'
4
+ require 'rails_deployer/heroku'
@@ -0,0 +1,44 @@
1
+ require_relative 'common'
2
+
3
+ module RailsDeployer
4
+ # Operations specific to the Bring operational environment
5
+ module Bring
6
+ include RailsDeployer::Common
7
+
8
+ def change_branch(env)
9
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
10
+ say "Checking out the branch we are deploying: #{env[:branch]}"
11
+ ssh.exec("cd #{env[:remote_path]} && git checkout #{env[:branch]}")
12
+ end
13
+ end
14
+
15
+ def make_env(app_name, rails_env)
16
+ branch = ENV['branch'] || 'master'
17
+ suffix = ("_#{rails_env}" if rails_env != 'production')
18
+ user = 'posten'
19
+ host = rails_env == 'production' ? 'posap408.unix.cosng.net' : 'posap413.unix.cosng.net'
20
+ {
21
+ branch: branch,
22
+ host: host,
23
+ http_proxy: 'http://proxy.ergogroup.no:3128',
24
+ push_to_repo: "#{user}@#{host}:/var/apps/#{app_name}#{suffix}/.git",
25
+ rails_env: rails_env,
26
+ remote_path: "/var/apps/#{app_name}#{suffix}",
27
+ user: user,
28
+ wheneverize: true,
29
+ }
30
+ end
31
+
32
+ def deploy(app_name, rails_env)
33
+ env = make_env(app_name, rails_env)
34
+ pp env
35
+ upload(env)
36
+ change_branch(env)
37
+ install_bundle(env)
38
+ precompile_assets(env)
39
+ migrate(env)
40
+ seed(env, :seed => (ENV['seed'] == 'true'))
41
+ restart(env)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ module RailsDeployer::Bring::Rake
2
+ extend RailsDeployer::Bring
3
+ extend ::Rake::DSL
4
+
5
+ def self.define_tasks(app_name)
6
+ namespace :deploy do
7
+ [:qa, :production].each do |app_env|
8
+
9
+ desc "deploy to #{app_env} with optional arguments [branch=branchname] and [seed=true] to load data from seeds.rb"
10
+ task(app_env) { deploy(app_name, app_env.to_s) }
11
+
12
+ namespace app_env do
13
+ desc 'Initialize the server environment'
14
+ task :initialize do
15
+ env = make_env(app_name, app_env.to_s)
16
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
17
+ puts 'Create app directory'
18
+ ssh.exec("mkdir -p #{env[:remote_path]}")
19
+ puts 'Initialize the GIT repo'
20
+ ssh.exec("cd #{env[:remote_path]} && git init && git config receive.denyCurrentBranch=ignore")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,143 @@
1
+ require 'net/ssh'
2
+
3
+ module RailsDeployer
4
+ # Common deployment tasks
5
+ # All methods takes in a environment hash with possible arguments
6
+ # :push_to_repo => the remote repo
7
+ # :host => the remote host
8
+ # :user => the user to the remote host
9
+ # :rails_env => the rails environment being used
10
+ # :remote_path => the remote path
11
+ # :branch => the branch to deploy
12
+ # :queue_script_path => the path to the queue init script
13
+ # :local_path => the path for local chechout of repo (used by kp-miniapp-deploy)
14
+ # :name => the name of the application
15
+ # :http_proxy => the proxy to use when doing external requests
16
+ # :rails_relative_url_root => assets precompile with relative url
17
+ module Common
18
+ RBENV = '~/.rbenv/bin/rbenv exec'
19
+ BUNDLE = "#{RBENV} bundle"
20
+ RAKE = "#{BUNDLE} exec rake"
21
+
22
+ def checkout(env)
23
+ say "Fetching latest of #{get_name(env)} from Github"
24
+ system("#{set_proxy(env)} #{cd_to_local(env[:local_path])} git pull origin #{env[:branch]}")
25
+ end
26
+
27
+ def upload(env)
28
+ say 'Pushing git repo'
29
+ system("#{cd_to_local(env[:local_path])} git push --mirror #{env[:push_to_repo]}")
30
+ end
31
+
32
+ def seed(env, opts)
33
+ unless opts[:seed]
34
+ say "Not seeding since you did not specify 'seed=true'"
35
+ return
36
+ end
37
+
38
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
39
+ say 'Seeding database'
40
+ ssh.exec("cd #{env[:remote_path]} && #{RAKE} db:seed #{set_env(env)}")
41
+ end
42
+ end
43
+
44
+ def migrate(env)
45
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
46
+ say 'Migrating database'
47
+ ssh.exec("cd #{env[:remote_path]} && #{RAKE} db:migrate #{set_env(env)}")
48
+ end
49
+ end
50
+
51
+ def install_bundle(env)
52
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
53
+ say 'installing bundle'
54
+ bundle_command = "#{BUNDLE} install --without=test development cucumber --deployment"
55
+ ssh.exec("#{set_proxy(env)} cd #{env[:remote_path]} && #{bundle_command}")
56
+ end
57
+ end
58
+
59
+ def precompile_assets(env)
60
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
61
+ say 'precompiling assets bundle'
62
+ ssh.exec("cd #{env[:remote_path]} && #{RAKE} assets:precompile #{set_env(env)} #{set_precompile_relative_url(env)}")
63
+ end
64
+ end
65
+
66
+ def restart(env)
67
+ say 'Restarting...'
68
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
69
+ say "removing #{env[:remote_path]}/tmp/restart.txt before running a touch"
70
+ ssh.exec("rm -v #{env[:remote_path]}/tmp/restart.txt")
71
+ end
72
+ # run in two different sessions to make sure they are run after
73
+ # each other so that restart.txt is not removed AFTER it was touched
74
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
75
+ say "touching #{env[:remote_path]}/tmp/restart.txt"
76
+ ssh.exec("touch #{env[:remote_path]}/tmp/restart.txt")
77
+ end
78
+ end
79
+
80
+ def update_crontab(env)
81
+ return unless env[:wheneverize]
82
+ say 'Updating crontab..'
83
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
84
+ say "running whenever command in #{env[:remote_path]}"
85
+ bundle_command = "#{BUNDLE} exec whenever --set environment=#{env[:rails_env]}"
86
+ ssh.exec("cd #{env[:remote_path]} && #{bundle_command} --update-crontab")
87
+ end
88
+ end
89
+
90
+ def restart_queue(env)
91
+ return if env[:queue_script_path].nil? || env[:queue_script_path].empty?
92
+ kp_forms_queue_script = "#{env[:queue_script_path]}-#{env[:rails_env]}"
93
+
94
+ say "Restarting #{get_name(env)} sidekiq queue.."
95
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
96
+ ssh.exec("#{kp_forms_queue_script} quiet")
97
+ ssh.exec("#{kp_forms_queue_script} stop")
98
+ end
99
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
100
+ ssh.exec("#{kp_forms_queue_script} start")
101
+ end
102
+ end
103
+
104
+ def restart_websocket(env)
105
+ return unless env[:restart_websocket]
106
+ say 'Restarting websocket'
107
+ Net::SSH.start(env[:host], env[:user]) do |ssh|
108
+ say "running whenever command in #{env[:remote_path]}"
109
+ command_context = "cd #{env[:remote_path]} && RAILS_ENV=#{env[:rails_env]}"
110
+ ssh.exec("#{command_context} #{RAKE} websocket_rails:stop_server")
111
+ ssh.exec("#{command_context} #{RAKE} websocket_rails:start_server")
112
+ end
113
+ end
114
+
115
+ def cd_to_local(local_path)
116
+ "cd #{local_path} &&" if local_path
117
+ end
118
+
119
+ def say(message)
120
+ puts message
121
+ end
122
+
123
+ def get_name(env)
124
+ env.fetch('name', 'application')
125
+ end
126
+
127
+ def set_env(env) # rubocop:disable Style/AccessorMethodName
128
+ "RAILS_ENV=#{env[:rails_env]} RACK_ENV=#{env[:rails_env]}"
129
+ end
130
+
131
+ def set_precompile_relative_url(env)
132
+ return unless env[:rails_relative_url_root]
133
+ "RAILS_RELATIVE_URL_ROOT=#{env[:rails_relative_url_root]}"
134
+ end
135
+
136
+ def set_proxy(env) # rubocop:disable Style/AccessorMethodName
137
+ return '' if env[:http_proxy].nil? || env[:http_proxy].empty?
138
+ exports = "export https_proxy=#{env[:https_proxy]}; export http_proxy=#{env[:http_proxy]}"
139
+ git_config = "git config --global http.proxy #{env[:http_proxy]}"
140
+ "#{exports} ; #{git_config} &&"
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'common'
2
+
3
+ module RailsDeployer
4
+ # Deployment setup for Heroku
5
+ module Heroku
6
+ include RailsDeployer::Common
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # Name space for Bring Rails Deployment
2
+ module RailsDeployer
3
+ VERSION = '0.1.1'
4
+ end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rails_deployer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rails_deployer'
7
+ spec.version = RailsDeployer::VERSION
8
+ spec.date = '2013-04-10'
9
+ spec.summary = 'Common rails deployment tasks for konsernportalen'
10
+ spec.description = 'Common rails deployment tasks for konsernportalen'
11
+ spec.authors = ['Hans-Christian Fjeldberg']
12
+ spec.email = 'hcf@bekk.no'
13
+ spec.homepage = 'http://posten.no'
14
+ spec.metadata.delete('allowed_push_host') # use this gem from GH source
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'net-ssh', '~> 2.6', '>= 2.6.1'
22
+
23
+ spec.add_development_dependency 'rake', '~> 10.3', '>= 10.3.2'
24
+ spec.add_development_dependency 'rubocop'
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsDeployer::Bring do
4
+ include_context 'shared'
5
+ it 'has the correct methods' do
6
+ expect(RailsDeployer::Bring.public_method_defined? :change_branch).to be true
7
+ common_methods.each do |method|
8
+ expect(RailsDeployer::Bring.public_method_defined? method).to be true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsDeployer::Common do
4
+ include_context 'shared'
5
+ it 'has the correct methods' do
6
+ common_methods.each do |method|
7
+ expect(RailsDeployer::Common.public_method_defined? method).to be true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsDeployer::Heroku do
4
+ include_context 'shared'
5
+ it 'has the correct methods' do
6
+ common_methods.each do |method|
7
+ expect(RailsDeployer::Heroku.public_method_defined? method).to be true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsDeployer do
4
+ it 'VERSION constant should have major-, minor- and build- or git SHA1-version or jenkins' do
5
+ expect(RailsDeployer::VERSION)
6
+ .to match(/\d+\.\d+\.(\d+|\h{5,40}|jenkins-kp-rails-deployer-\d+)/)
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_deployer'
2
+
3
+ Dir[('./spec/support/**/*.rb')].each { |file| require file }
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |c|
7
+ c.syntax = :expect
8
+ end
9
+
10
+ config.fail_fast = true
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.shared_context 'shared' do
2
+ let(:common_methods) do
3
+ %i(
4
+ checkout upload seed migrate install_bundle precompile_assets restart
5
+ update_crontab restart_queue restart_websocket cd_to_local say get_name
6
+ set_env set_proxy
7
+ )
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_deployer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Hans-Christian Fjeldberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.6.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 10.3.2
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 10.3.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: rubocop
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ description: Common rails deployment tasks for konsernportalen
68
+ email: hcf@bekk.no
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - ".gitignore"
74
+ - ".rubocop.yml"
75
+ - ".ruby-version"
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.md
79
+ - Rakefile
80
+ - lib/rails_deployer.rb
81
+ - lib/rails_deployer/bring.rb
82
+ - lib/rails_deployer/bring/rake.rb
83
+ - lib/rails_deployer/common.rb
84
+ - lib/rails_deployer/heroku.rb
85
+ - lib/rails_deployer/version.rb
86
+ - rails_deployer.gemspec
87
+ - spec/rails_deployer/bring_spec.rb
88
+ - spec/rails_deployer/common_spec.rb
89
+ - spec/rails_deployer/heroku_spec.rb
90
+ - spec/rails_deployer/version_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/support/contexts/shared_context.rb
93
+ homepage: http://posten.no
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Common rails deployment tasks for konsernportalen
116
+ test_files:
117
+ - spec/rails_deployer/bring_spec.rb
118
+ - spec/rails_deployer/common_spec.rb
119
+ - spec/rails_deployer/heroku_spec.rb
120
+ - spec/rails_deployer/version_spec.rb
121
+ - spec/spec_helper.rb
122
+ - spec/support/contexts/shared_context.rb
123
+ has_rdoc: