heroku_ops 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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +3 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/heroku_ops.gemspec +35 -0
- data/lib/heroku_ops/railtie.rb +7 -0
- data/lib/heroku_ops/version.rb +3 -0
- data/lib/heroku_ops.rb +6 -0
- data/lib/tasks/db_restore.rake +55 -0
- data/lib/tasks/deploy.rake +85 -0
- data/lib/tasks/pipeline_setup.rake +60 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 387d93e0a3e2f8801af4cd0a0ff792fbe50ea3fb
|
4
|
+
data.tar.gz: 6d00fdc0ce03b61fcc07e15580b6f9f39e645c91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ebbb62e94d49842902a5d88b41c92e9d511b89d44771f3e5d7c5a66b515e9dc555b8efdc9a7a6abfc2ee7131b941d224b9cb87ae66555aa5c7def17c3a0e6f2
|
7
|
+
data.tar.gz: 91042e589e978cd8a3564e909256d3288215dc7bbfd68e41681258dad9af45fd4bbfb9e2eb3eaf6cf927aa8ca4f7aaa81ba2c6c085f38f971921aa47ea0c613f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 nrowegt
|
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,68 @@
|
|
1
|
+
# HerokuOps
|
2
|
+
|
3
|
+
A (for now) very opinionated gem which has 3 sections:
|
4
|
+
|
5
|
+
* pipeline/app setup
|
6
|
+
* db restore (pull down your heroku database and `psql < tmp/latest.db`)
|
7
|
+
* deploys (push to heroku remotes)
|
8
|
+
|
9
|
+
These tasks all assume your heroku application names are of the format `"#{Rails.application.class.parent_name.underscore.gsub('_','-')}-#{environment}"`, where environment is one of staging, production. Setting up an app includes the following free Heroku addons:
|
10
|
+
|
11
|
+
*heroku-postgresql:hobby-dev
|
12
|
+
*newrelic:wayne
|
13
|
+
*papertrail:choklad
|
14
|
+
*rediscloud:30
|
15
|
+
*scheduler:standard
|
16
|
+
*sendgrid:starter
|
17
|
+
|
18
|
+
App name configuration flags and more detailed documentation will come in a later version.
|
19
|
+
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'heroku_ops', group: :development # No need to include this on production or staging
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install heroku_ops
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
To see an updated list of tasks and descriptions:
|
39
|
+
`bundle exec rake heroku_ops -T heroku_ops`
|
40
|
+
|
41
|
+
~~~bash
|
42
|
+
rake heroku_ops:db:restore # Pull Down a copy of the database from the specified heroku environment
|
43
|
+
rake heroku_ops:db:restore:from_local_dump # Restore from local dump file (defaults to '/tmp/latest.dump' - specify with DUMP_FILE Environmental Variable)
|
44
|
+
rake heroku_ops:db:restore:local # Erase local development and test database and restore from the local dump file
|
45
|
+
rake heroku_ops:db:restore:production # Restore a local copy of Heroku's Production Environment database
|
46
|
+
rake heroku_ops:db:restore:staging # Restore a local copy of Heroku's Staging Environment database
|
47
|
+
rake heroku_ops:deploy # Deploy Safely to Heroku
|
48
|
+
rake heroku_ops:deploy:production # Deploy to Heroku's Production Environment
|
49
|
+
rake heroku_ops:deploy:production:quick # Quick Deploy to Production, without running migrations
|
50
|
+
rake heroku_ops:deploy:staging:quick # Quick Deploy to Staging, without running migrations
|
51
|
+
rake heroku_ops:pipeline:setup # Create a pipeline, staging and production applications
|
52
|
+
rake heroku_ops:pipeline:setup:pipeline # Setup a pipeline with your applications in the appropriate stages
|
53
|
+
rake heroku_ops:pipeline:setup:production # Setup a production app (with addons) and git remote for heroku
|
54
|
+
rake heroku_ops:pipeline:setup:staging # Setup a staging app (with addons) and remote for heroku
|
55
|
+
~~~
|
56
|
+
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nrowegt/heroku_ops.
|
61
|
+
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
66
|
+
|
67
|
+
Thanks to [@danielricecodes](http://www.ldstudios.co/) for the inspiration and the initial base implementations of the restore and deploy tasks.
|
68
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "heroku_ops"
|
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/heroku_ops.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heroku_ops/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "heroku_ops"
|
8
|
+
spec.version = HerokuOps::VERSION
|
9
|
+
spec.authors = ["nrowegt"]
|
10
|
+
spec.email = ["rowe.nathaniel@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Helpful Heroku Ops Rake Tasks"
|
13
|
+
spec.description = "Tasks to setup pipelines for your app with the typical free tier addons and run deploys and db restores"
|
14
|
+
spec.homepage = "https://github.com/nrowegt/heroku_ops"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
data/lib/heroku_ops.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
DataBaseReference = ""
|
2
|
+
|
3
|
+
namespace :heroku_ops do
|
4
|
+
namespace :db do
|
5
|
+
desc 'Pull Down a copy of the database from the specified heroku environment'
|
6
|
+
task :restore do
|
7
|
+
env = ENV['ENV']
|
8
|
+
|
9
|
+
abort "Please specify ENV=production or ENV=staging" unless env
|
10
|
+
app = app_name_from_environment(env)
|
11
|
+
|
12
|
+
if ENV['LATEST'] #if this is here, then create a fresh backup, if not grab whichever is the latest
|
13
|
+
sh "heroku pg:backups capture --app #{app}"
|
14
|
+
end
|
15
|
+
|
16
|
+
sh "curl -o tmp/latest.dump `heroku pg:backups public-url --app #{app} | head -n 1`"
|
17
|
+
|
18
|
+
#ensures there are no extra tables or views
|
19
|
+
Rake::Task["heroku_ops:db:restore:local"].invoke
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :restore do
|
23
|
+
desc "Restore a local copy of Heroku's Staging Environment database"
|
24
|
+
task :staging do
|
25
|
+
ENV['ENV'] = "staging"
|
26
|
+
Rake::Task["heroku_ops:db:restore"].invoke
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Restore a local copy of Heroku's Production Environment database"
|
30
|
+
task :production do
|
31
|
+
ENV['ENV'] = "production"
|
32
|
+
Rake::Task["heroku_ops:db:restore"].invoke
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Erase local development and test database and restore from the local dump file."
|
36
|
+
task :local do
|
37
|
+
#ensures there are no extra tables or views
|
38
|
+
Rake::Task["db:drop"].invoke
|
39
|
+
Rake::Task["db:create"].invoke
|
40
|
+
|
41
|
+
Rake::Task["heroku_ops:db:restore:from_local_dump"].invoke
|
42
|
+
#migrate the database, remove sensitive information, and setup tests
|
43
|
+
Rake::Task["db:migrate"].invoke
|
44
|
+
Rake::Task["db:test:prepare"].invoke
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Restore from local dump file (defaults to '/tmp/latest.dump' - specify with DUMP_FILE Environmental Variable)"
|
48
|
+
task :from_local_dump do
|
49
|
+
dump_file_location = (ENV['DUMP_FILE'] || "tmp/latest.dump")
|
50
|
+
#in backticks so that pg_restore warnings dont exit this routine
|
51
|
+
`pg_restore --verbose --clean --no-acl --no-owner -h localhost -d #{Rails.application.class.parent_name.underscore}_development #{dump_file_location}`
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
def app_name_from_environment(env)
|
2
|
+
case env.downcase
|
3
|
+
when "production"
|
4
|
+
"#{Rails.application.class.parent_name.underscore.gsub('_','-')}-production"
|
5
|
+
when "staging"
|
6
|
+
"#{Rails.application.class.parent_name.underscore.gsub('_','-')}-staging"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def push_command_from_env(env)
|
11
|
+
case env
|
12
|
+
when "production"
|
13
|
+
"git push #{env} master"
|
14
|
+
when "staging"
|
15
|
+
# heroku requires that deployes be pushed to the master branch on heroku git repo
|
16
|
+
"git push #{env} staging:master"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :heroku_ops do
|
21
|
+
desc 'Deploy Safely to Heroku'
|
22
|
+
task :deploy do
|
23
|
+
env = ENV['ENV']
|
24
|
+
|
25
|
+
abort "Please specify ENV={production|staging}" unless env
|
26
|
+
|
27
|
+
app_name = app_name_from_environment(env)
|
28
|
+
|
29
|
+
#take db backup first
|
30
|
+
sh "heroku pg:backups capture --app #{app_name}"
|
31
|
+
|
32
|
+
#push up new code release
|
33
|
+
sh push_command_from_env(env)
|
34
|
+
|
35
|
+
#migrate database and ensure seed values are present always (Settings, ContentMgmts)
|
36
|
+
sh "heroku run rake db:migrate db:seed --app #{app_name}"
|
37
|
+
|
38
|
+
#restart dynos to ensure all users get the new released version immediately
|
39
|
+
sh "heroku restart --app #{app_name}"
|
40
|
+
|
41
|
+
#warm up the Heroku dynos
|
42
|
+
sh "curl -o /dev/null http://#{app_name}.herokuapp.com"
|
43
|
+
end
|
44
|
+
|
45
|
+
namespace :deploy do
|
46
|
+
desc "Deploy to Heroku's Staging Environment"
|
47
|
+
|
48
|
+
desc "Deploy to Heroku's Production Environment"
|
49
|
+
task :production do
|
50
|
+
ENV['ENV'] = "production"
|
51
|
+
sh "git push origin master"
|
52
|
+
Rake::Task["heroku_ops:deploy"].invoke
|
53
|
+
end
|
54
|
+
|
55
|
+
task :staging do
|
56
|
+
ENV['ENV'] = "staging"
|
57
|
+
sh "git push origin staging"
|
58
|
+
Rake::Task["heroku_ops:deploy"].invoke
|
59
|
+
end
|
60
|
+
|
61
|
+
namespace :production do
|
62
|
+
desc 'Quick Deploy to Production, without running migrations.'
|
63
|
+
task :quick do
|
64
|
+
app_name = app_name_from_environment(env)
|
65
|
+
Bundler.with_clean_env do
|
66
|
+
puts `git push origin master`
|
67
|
+
puts `git push production master`
|
68
|
+
puts `heroku restart --app app_name`
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
namespace :staging do
|
74
|
+
desc 'Quick Deploy to Staging, without running migrations.'
|
75
|
+
task :quick do
|
76
|
+
app_name = app_name_from_environment(env)
|
77
|
+
Bundler.with_clean_env do
|
78
|
+
puts `git push origin staging`
|
79
|
+
puts `git push staging staging:master`
|
80
|
+
puts `heroku restart --app app_name`
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
def base_app_name
|
2
|
+
"#{Rails.application.class.parent_name.underscore.gsub('_','-')}"
|
3
|
+
end
|
4
|
+
|
5
|
+
def app_name_for_env(env)
|
6
|
+
case env.downcase
|
7
|
+
when "production"
|
8
|
+
"#{base_app_name}-production"
|
9
|
+
when "staging"
|
10
|
+
"#{base_app_name}-staging"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_addons_for_appname(appname)
|
15
|
+
sh "heroku addons:create heroku-postgresql:hobby-dev -a #{appname}"
|
16
|
+
sh "heroku addons:create newrelic:wayne -a #{appname}"
|
17
|
+
sh "heroku addons:create papertrail:choklad -a #{appname}"
|
18
|
+
sh "heroku addons:create rediscloud:30 -a #{appname}"
|
19
|
+
sh "heroku addons:create scheduler:standard -a #{appname}"
|
20
|
+
sh "heroku addons:create sendgrid:starter -a #{appname}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_remote_for_appname(env, appname)
|
24
|
+
sh "git remote add #{env} git@heroku.com:#{appname}.git"
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace :heroku_ops do
|
28
|
+
namespace :pipeline do
|
29
|
+
desc 'Create a pipeline, staging and production applications.'
|
30
|
+
task :setup do
|
31
|
+
Rake::Task['heroku_ops:pipeline:setup:staging'].invoke
|
32
|
+
Rake::Task['heroku_ops:pipeline:setup:production'].invoke
|
33
|
+
Rake::Task['heroku_ops:pipeline:setup:pipeline'].invoke
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :setup do
|
37
|
+
desc "Setup a staging app (with addons) and remote for heroku"
|
38
|
+
task :staging do
|
39
|
+
app_name = app_name_for_env("staging")
|
40
|
+
sh "heroku create #{app_name}"
|
41
|
+
sh "git remote remove heroku"
|
42
|
+
create_addons_for_appname(app_name)
|
43
|
+
create_remote_for_appname("staging", app_name)
|
44
|
+
end
|
45
|
+
desc "Setup a production app (with addons) and git remote for heroku"
|
46
|
+
task :production do
|
47
|
+
app_name = app_name_for_env("production")
|
48
|
+
sh "heroku create #{app_name}"
|
49
|
+
sh "git remote remove heroku"
|
50
|
+
create_addons_for_appname(app_name)
|
51
|
+
create_remote_for_appname("production", app_name)
|
52
|
+
end
|
53
|
+
desc "Setup a pipeline with your applications in the appropriate stages."
|
54
|
+
task :pipeline do
|
55
|
+
sh "heroku pipelines:create -a#{app_name_for_env("staging")} --stage staging"
|
56
|
+
sh "heroku pipelines:add -a#{app_name_for_env("production")} #{base_app_name} --stage production"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_ops
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nrowegt
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Tasks to setup pipelines for your app with the typical free tier addons
|
42
|
+
and run deploys and db restores
|
43
|
+
email:
|
44
|
+
- rowe.nathaniel@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- heroku_ops.gemspec
|
57
|
+
- lib/heroku_ops.rb
|
58
|
+
- lib/heroku_ops/railtie.rb
|
59
|
+
- lib/heroku_ops/version.rb
|
60
|
+
- lib/tasks/db_restore.rake
|
61
|
+
- lib/tasks/deploy.rake
|
62
|
+
- lib/tasks/pipeline_setup.rake
|
63
|
+
homepage: https://github.com/nrowegt/heroku_ops
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
allowed_push_host: https://rubygems.org
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.5.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Helpful Heroku Ops Rake Tasks
|
88
|
+
test_files: []
|