heroku_rails_deploy 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.overcommit.yml +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +15 -0
- data/heroku_rails_deploy.gemspec +31 -0
- data/lib/generators/heroku_rails_deploy/heroku_rails_deploy_generator.rb +14 -0
- data/lib/generators/heroku_rails_deploy/templates/deploy +7 -0
- data/lib/generators/heroku_rails_deploy/templates/heroku.yml +11 -0
- data/lib/heroku_rails_deploy.rb +9 -0
- data/lib/heroku_rails_deploy/deployer.rb +103 -0
- data/lib/heroku_rails_deploy/version.rb +3 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9735e2adea62cb3eb911e797afeaf47803517e44
|
4
|
+
data.tar.gz: db9355ebc07bf1013ef783aa782a4decd366cdd7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 240b8f705fc58112e1616a92147befa4469d545828aa14989eb84ce0bbae892b61a1c53778dc4fb3f9e47bf5b6fd26fdd6d5d6fb584728e3ade96af1b29a4a6b
|
7
|
+
data.tar.gz: abb3a2c9cc963ad7be67bea6c9bd924721fd4c41752dade7b2107590fcd778f67502498514560dbac3a304d6f190345c74e127fd9f101ad9f08ba9146482f159
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Salsify, Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# HerokuRailsDeploy
|
2
|
+
|
3
|
+
This gem provides a simple Heroku deploy script for Rails applications. Deploys
|
4
|
+
following the following steps:
|
5
|
+
|
6
|
+
1. Push code to Heroku
|
7
|
+
2. If there are pending migrations, run them and restart the Heroku dynos
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
group :development do
|
15
|
+
gem 'heroku_rails_deploy'
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
Then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Then run the generator to create the deploy script and configuration file:
|
24
|
+
|
25
|
+
$ rails generate heroku_rails_deploy
|
26
|
+
|
27
|
+
Finally follow the instructions in `config/heroku.yml` to configure the
|
28
|
+
environments/Heroku applications for your project e.g.
|
29
|
+
|
30
|
+
```yml
|
31
|
+
production: my-app-prod
|
32
|
+
staging: my-app-staging
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
From your application's root directory run the `bin/deploy` script with the `--help`
|
38
|
+
argument to print usage:
|
39
|
+
|
40
|
+
```
|
41
|
+
$ bin/deploy --help
|
42
|
+
Usage: deploy [options]
|
43
|
+
-e, --environment ENVIRONMENT The environment to deploy to. Must be in production, staging (default production)
|
44
|
+
-r, --revision REVISION The git revision to push. (default HEAD)
|
45
|
+
-h, --help Show this message
|
46
|
+
```
|
47
|
+
|
48
|
+
A typical deploy command will look something like:
|
49
|
+
```
|
50
|
+
$ bin/deploy --environment production
|
51
|
+
```
|
52
|
+
|
53
|
+
Note you can omit the environment to deploy to your default environment.
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
58
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
59
|
+
interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
62
|
+
|
63
|
+
To release a new version, update the version number in `version.rb`, and then
|
64
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
65
|
+
push git commits and tags, and push the `.gem` file to
|
66
|
+
[rubygems.org](https://rubygems.org).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
Bug reports and pull requests are welcome on GitHub at
|
71
|
+
https://github.com/salsify/heroku_rails_deploy.
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'heroku_rails_deploy'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
machine:
|
2
|
+
ruby:
|
3
|
+
version:
|
4
|
+
2.3.1
|
5
|
+
|
6
|
+
database:
|
7
|
+
override:
|
8
|
+
- echo 'nothing to setup'
|
9
|
+
|
10
|
+
test:
|
11
|
+
override:
|
12
|
+
- bundle exec rubocop
|
13
|
+
- bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/junit.xml --format progress spec
|
14
|
+
post:
|
15
|
+
- cp -R log $CIRCLE_ARTIFACTS
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heroku_rails_deploy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'heroku_rails_deploy'
|
8
|
+
spec.version = HerokuRailsDeploy::VERSION
|
9
|
+
spec.authors = ['Salsify, Inc']
|
10
|
+
spec.email = ['engineering@salsify.com']
|
11
|
+
|
12
|
+
spec.summary = 'Simple deployment of Rails app to Heroku'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/salsify/heroku_rails_deploy'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'rails'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
27
|
+
spec.add_development_dependency 'salsify_rubocop', '~> 0.42.0'
|
28
|
+
spec.add_development_dependency 'overcommit'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'rspec_junit_formatter', '0.2.2'
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
class HerokuRailsDeployGenerator < Rails::Generators::Base
|
4
|
+
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
5
|
+
|
6
|
+
def create_config_file
|
7
|
+
template('heroku.yml', 'config/heroku.yml')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_executable_file
|
11
|
+
template('deploy', 'bin/deploy')
|
12
|
+
chmod('bin/deploy', 0755)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# A map from environment name to Heroku application name.
|
2
|
+
# Entries should be of the form:
|
3
|
+
#
|
4
|
+
# <environment>: <heroku app name>
|
5
|
+
#
|
6
|
+
# The first environment mentioned will be the default
|
7
|
+
# used for deploys that don't specify an environment.
|
8
|
+
#
|
9
|
+
# TODO: Update for your desired environments/Heroku applications
|
10
|
+
# staging: my-service-staging
|
11
|
+
# production: my-service-production
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module HerokuRailsDeploy
|
5
|
+
class Deployer
|
6
|
+
attr_reader :config_file, :args
|
7
|
+
|
8
|
+
class Options < Struct.new(:environment, :revision)
|
9
|
+
def self.create_default(app_registry)
|
10
|
+
new(app_registry.keys.first, 'HEAD')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(config_file, args)
|
15
|
+
@config_file = config_file
|
16
|
+
@args = args
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
raise "Missing config file #{config_file}" unless File.file?(config_file)
|
21
|
+
app_registry = YAML.load(File.read(config_file))
|
22
|
+
|
23
|
+
options = Options.create_default(app_registry)
|
24
|
+
OptionParser.new do |parser|
|
25
|
+
parser.on_tail('-h', '--help', 'Show this message') do
|
26
|
+
puts parser
|
27
|
+
# rubocop:disable Lint/NonLocalExitFromIterator
|
28
|
+
return
|
29
|
+
# rubocop:enable Lint/NonLocalExitFromIterator
|
30
|
+
end
|
31
|
+
|
32
|
+
parser.on('-e', '--environment ENVIRONMENT',
|
33
|
+
"The environment to deploy to. Must be in #{app_registry.keys.join(', ')} (default #{app_registry.keys.first})") do |environment|
|
34
|
+
options.environment = environment
|
35
|
+
end
|
36
|
+
|
37
|
+
parser.on('-r', '--revision REVISION',
|
38
|
+
'The git revision to push. (default HEAD)') do |revision|
|
39
|
+
options.revision = revision
|
40
|
+
end
|
41
|
+
end.parse!(args)
|
42
|
+
|
43
|
+
app_name = app_registry.fetch(options.environment) do
|
44
|
+
raise OptionParser::InvalidArgument.new("Invalid environment '#{options.environment}'. " \
|
45
|
+
"Must be in #{app_registry.keys.join(', ')}")
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "Pushing code to Heroku app #{app_name} for environment #{options.environment}"
|
49
|
+
push_code(app_name, options.revision)
|
50
|
+
|
51
|
+
puts 'Checking for pending migrations'
|
52
|
+
if pending_migrations?(app_name)
|
53
|
+
puts 'Running migrations'
|
54
|
+
run_migrations(app_name)
|
55
|
+
puts 'Restarting dynos'
|
56
|
+
restart_dynos(app_name)
|
57
|
+
else
|
58
|
+
puts 'No migrations required'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def push_code(app_name, revision)
|
63
|
+
run_command!("git push --force git@heroku.com:#{app_name}.git #{revision}:master")
|
64
|
+
end
|
65
|
+
|
66
|
+
def run_migrations(app_name)
|
67
|
+
run_heroku_command!(app_name, 'run rake db:migrate')
|
68
|
+
end
|
69
|
+
|
70
|
+
def restart_dynos(app_name)
|
71
|
+
run_heroku_command!(app_name, 'ps:restart')
|
72
|
+
end
|
73
|
+
|
74
|
+
def pending_migrations?(app_name)
|
75
|
+
!run_heroku_command(app_name, 'run rake db:abort_if_pending_migrations')
|
76
|
+
end
|
77
|
+
|
78
|
+
def run_heroku_command!(app_name, command)
|
79
|
+
success = run_heroku_command(app_name, command)
|
80
|
+
raise "Heroku command '#{command}' failed" unless success
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_heroku_command(app_name, command)
|
84
|
+
cli_command = "heroku #{command} --app #{app_name}"
|
85
|
+
if command.start_with?('run ')
|
86
|
+
# If we're running a shell command, return the underlying
|
87
|
+
# shell command exit code
|
88
|
+
cli_command << ' --exit-code'
|
89
|
+
end
|
90
|
+
run_command(cli_command)
|
91
|
+
end
|
92
|
+
|
93
|
+
def run_command!(command)
|
94
|
+
success = run_command(command)
|
95
|
+
raise "Command '#{command}' failed" unless success
|
96
|
+
end
|
97
|
+
|
98
|
+
def run_command(command)
|
99
|
+
puts command
|
100
|
+
Bundler.with_clean_env { system(command) }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_rails_deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Salsify, Inc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: salsify_rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.42.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.42.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: overcommit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec_junit_formatter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.2
|
111
|
+
description: Simple deployment of Rails app to Heroku
|
112
|
+
email:
|
113
|
+
- engineering@salsify.com
|
114
|
+
executables:
|
115
|
+
- console
|
116
|
+
- setup
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".overcommit.yml"
|
122
|
+
- ".rspec"
|
123
|
+
- ".rubocop.yml"
|
124
|
+
- CHANGELOG.md
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- circle.yml
|
132
|
+
- heroku_rails_deploy.gemspec
|
133
|
+
- lib/generators/heroku_rails_deploy/heroku_rails_deploy_generator.rb
|
134
|
+
- lib/generators/heroku_rails_deploy/templates/deploy
|
135
|
+
- lib/generators/heroku_rails_deploy/templates/heroku.yml
|
136
|
+
- lib/heroku_rails_deploy.rb
|
137
|
+
- lib/heroku_rails_deploy/deployer.rb
|
138
|
+
- lib/heroku_rails_deploy/version.rb
|
139
|
+
homepage: https://github.com/salsify/heroku_rails_deploy
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.5.1
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Simple deployment of Rails app to Heroku
|
163
|
+
test_files: []
|