wildland_dev_tools 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +2 -0
- data/lib/tasks/heroku.rake +66 -15
- data/lib/wildland_dev_tools/heroku.rb +29 -29
- data/lib/wildland_dev_tools/version.rb +1 -1
- data/wildland_dev_tools.gemspec +2 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5041629440879fa44f3c8f0aab7891fa580fd3d4
|
4
|
+
data.tar.gz: 4f2bfdcd71896ce4e3f005f76542c5b45ed6f9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 030424c622c3137d16135c8f3317f0ba65877977def3fd86260951da215888cc93759595b2cde721013be5cf7fe875fdda389a244b5a6f2301135ff49e4eefce
|
7
|
+
data.tar.gz: 421b71174dc8faa0878e08334abbb4570afa0100131f0495680a8eb29e6a52fbd170e52e3c3e1c0267dbc31c35b5bfb300e5569071d06de4cd581bb9ea98c21d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
## [Unreleased]
|
5
|
+
### Added *for new features*
|
6
|
+
### Changed *for changes in existing functionality*
|
7
|
+
### Deprecated *for soon-to-be removed features*
|
8
|
+
### Removed *for now removed features*
|
9
|
+
### Fixed *for any bug fixes*
|
10
|
+
### Security *in case of vulnerabilities*
|
11
|
+
|
12
|
+
## [1.1.0] - 2017-01-29
|
13
|
+
### Added *for new features*
|
14
|
+
- `copy_production_database_to_staging` added as a rake task
|
15
|
+
- Now contains a `CHANGELOG.md`
|
16
|
+
|
17
|
+
### Changed *for changes in existing functionality*
|
18
|
+
- Most heroku commands will now ask if you want to continue running with a missing remove if run with verbose or force. This means that if you do a staging deploy with no `production` remove it would skip copying the production database.
|
19
|
+
|
20
|
+
### Deprecated *for soon-to-be removed features*
|
21
|
+
- None
|
22
|
+
|
23
|
+
### Removed *for now removed features*
|
24
|
+
- None
|
25
|
+
|
26
|
+
### Fixed *for any bug fixes*
|
27
|
+
- None
|
28
|
+
|
29
|
+
### Security *in case of vulnerabilities*
|
30
|
+
- None
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
This is a gem that contains all of our dev rake tasks.
|
3
3
|
These are most useful for projects created by [trailhead](https://github.com/wildland/trailhead) and are deployed on [heroku](https://www.heroku.com/home) using the [pipeline](https://devcenter.heroku.com/articles/pipelines) feature. This allows for separate `staging` and `production` enviroments as well as review apps.
|
4
4
|
|
5
|
+
Checkout our [Changelog](CHANGELOG.md) for what has changed.
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
- Add the following to your `Gemfile`:
|
data/lib/tasks/heroku.rake
CHANGED
@@ -1,24 +1,36 @@
|
|
1
1
|
require 'wildland_dev_tools/heroku'
|
2
|
+
require 'highline'
|
2
3
|
|
3
4
|
namespace :wildland do
|
4
5
|
namespace :heroku do
|
5
6
|
desc 'Imports the latest production database backup to local database.'
|
6
|
-
task :import_latest_production_database_backup, [:verbose] => [:
|
7
|
+
task :import_latest_production_database_backup, [:verbose] => [:check_production_remote, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
7
8
|
WildlandDevTools::Heroku.import_production_database(args[:verbose])
|
8
9
|
Rake::Task['db:migrate'].invoke
|
9
10
|
end
|
10
11
|
|
11
12
|
desc 'Imports the latest staging database backup to local database.'
|
12
|
-
task :import_latest_staging_database_backup, [:verbose] => [:
|
13
|
+
task :import_latest_staging_database_backup, [:verbose] => [:check_staging_remote, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
13
14
|
WildlandDevTools::Heroku.import_staging_database(args[:verbose])
|
14
15
|
Rake::Task['db:migrate'].invoke
|
15
16
|
end
|
16
17
|
|
17
18
|
desc 'Backups production database'
|
18
|
-
task :backup_production_database, [:verbose] => [:
|
19
|
+
task :backup_production_database, [:verbose] => [:check_production_remote, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
19
20
|
WildlandDevTools::Heroku.backup_production_database(args[:verbose])
|
20
21
|
end
|
21
22
|
|
23
|
+
desc 'Copys the production database to staging'
|
24
|
+
task :copy_production_database_to_staging, [:verbose] => [:check_remotes, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
25
|
+
begin
|
26
|
+
Rake::Task['wildland:heroku:maintenance_mode_on'].execute
|
27
|
+
WildlandDevTools::Heroku.copy_production_data_to_staging(args[:verbose])
|
28
|
+
WildlandDevTools::Heroku.migrate_staging_database(args[:verbose])
|
29
|
+
ensure
|
30
|
+
Rake::Task['wildland:heroku:maintenance_mode_off'].execute
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
22
34
|
desc 'Promotes staging to production. This automatically creates a production release tag.'
|
23
35
|
task :promote_to_production, [:verbose] => [:check_remotes, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
24
36
|
begin
|
@@ -31,17 +43,21 @@ namespace :wildland do
|
|
31
43
|
puts e
|
32
44
|
WildlandDevTools::Heroku.rollback_production_deploy(true)
|
33
45
|
raise
|
46
|
+
ensure
|
47
|
+
Rake::Task['wildland:heroku:maintenance_mode_off'].execute
|
34
48
|
end
|
35
49
|
end
|
36
50
|
|
37
51
|
desc 'Deploy master to staging. This automatically creates a release candidate tag.'
|
38
52
|
task :deploy_to_staging, [:verbose, :force] => [:check_remotes, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
39
53
|
begin
|
40
|
-
|
54
|
+
Rake::Task['wildland:heroku:maintenance_mode_on'].execute
|
41
55
|
Rake::Task['wildland:releases:create_release_candidate_tag'].execute
|
42
56
|
WildlandDevTools::Heroku.deploy_master_to_staging(args[:verbose], args[:force])
|
43
|
-
WildlandDevTools::Heroku.
|
44
|
-
|
57
|
+
if WildlandDevTools::Heroku.production_remote_available?
|
58
|
+
WildlandDevTools::Heroku.copy_production_data_to_staging(args[:verbose])
|
59
|
+
WildlandDevTools::Heroku.migrate_staging_database(args[:verbose])
|
60
|
+
end
|
45
61
|
rescue WildlandDevTools::GitSyncException => e
|
46
62
|
puts e
|
47
63
|
rescue RuntimeError => e
|
@@ -49,17 +65,19 @@ namespace :wildland do
|
|
49
65
|
WildlandDevTools::Heroku.rollback_staging_deploy(true)
|
50
66
|
raise
|
51
67
|
ensure
|
52
|
-
|
68
|
+
Rake::Task['wildland:heroku:maintenance_mode_off'].execute
|
53
69
|
end
|
54
70
|
end
|
55
71
|
|
56
72
|
desc 'Deploy current branch to staging as master. This does not create a release canidate tag.'
|
57
73
|
task :deploy_current_branch_to_staging, [:verbose, :force] => [:check_remotes, :check_heroku] do |_t, args| # rubocop:disable Metrics/LineLength
|
58
74
|
begin
|
59
|
-
|
75
|
+
Rake::Task['wildland:heroku:maintenance_mode_on'].execute
|
60
76
|
WildlandDevTools::Heroku.deploy_current_branch_to_staging(args[:verbose], args[:force])
|
61
|
-
WildlandDevTools::Heroku.
|
62
|
-
|
77
|
+
if WildlandDevTools::Heroku.production_remote_available?
|
78
|
+
WildlandDevTools::Heroku.copy_production_data_to_staging(args[:verbose])
|
79
|
+
WildlandDevTools::Heroku.migrate_staging_database(args[:verbose])
|
80
|
+
end
|
63
81
|
rescue WildlandDevTools::GitSyncException => e
|
64
82
|
puts e
|
65
83
|
rescue RuntimeError => e
|
@@ -67,7 +85,7 @@ namespace :wildland do
|
|
67
85
|
WildlandDevTools::Heroku.rollback_staging_deploy(true)
|
68
86
|
raise
|
69
87
|
ensure
|
70
|
-
|
88
|
+
Rake::Task['wildland:heroku:maintenance_mode_off'].execute
|
71
89
|
end
|
72
90
|
end
|
73
91
|
|
@@ -94,21 +112,54 @@ namespace :wildland do
|
|
94
112
|
task :check_heroku do
|
95
113
|
unless WildlandDevTools::Heroku.heroku_toolbelt_available?
|
96
114
|
Kernel.abort(
|
97
|
-
'Missing heroku toolbelt.
|
115
|
+
'Missing heroku toolbelt. See \'https://devcenter.heroku.com/articles/heroku-cli\'.'
|
98
116
|
)
|
99
117
|
end
|
100
118
|
end
|
101
119
|
|
102
|
-
task :check_remotes
|
120
|
+
task :check_remotes => [:check_staging_remote, :check_production_remote]
|
121
|
+
|
122
|
+
task :check_staging_remote do |t, args|
|
123
|
+
ask = args[:force] || args[:verbose] || false
|
124
|
+
manual_override = false
|
103
125
|
unless WildlandDevTools::Heroku.staging_remote_available?
|
126
|
+
if ask
|
127
|
+
cli = HighLine.new
|
128
|
+
cli.choose do |menu|
|
129
|
+
menu.prompt = "Staging remote not found. Try to continue anyways? "
|
130
|
+
menu.choice(:yes) do
|
131
|
+
cli.say("Trying to continue.")
|
132
|
+
manual_override = true
|
133
|
+
end
|
134
|
+
menu.choice(:no)
|
135
|
+
menu.default = :no
|
136
|
+
end
|
137
|
+
end
|
104
138
|
Kernel.abort(
|
105
139
|
'Missing staging git remote. Run \'heroku git:remote -a <app-name> -r staging\'' # rubocop:disable Metrics/LineLength
|
106
|
-
)
|
140
|
+
) unless manual_override
|
107
141
|
end
|
142
|
+
end
|
143
|
+
|
144
|
+
task :check_production_remote do |t, args|
|
145
|
+
ask = args[:force] || args[:verbose] || false
|
146
|
+
manual_override = false
|
108
147
|
unless WildlandDevTools::Heroku.production_remote_available?
|
148
|
+
if ask
|
149
|
+
cli = HighLine.new
|
150
|
+
cli.choose do |menu|
|
151
|
+
menu.prompt = "Production remote not found. Try to continue anyways? "
|
152
|
+
menu.choice(:yes) do
|
153
|
+
cli.say("Trying to continue.")
|
154
|
+
manual_override = true
|
155
|
+
end
|
156
|
+
menu.choice(:no)
|
157
|
+
menu.default = :no
|
158
|
+
end
|
159
|
+
end
|
109
160
|
Kernel.abort(
|
110
161
|
'Missing production git remote. Run \'heroku git:remote -a <app-name> -r production\'' # rubocop:disable Metrics/LineLength
|
111
|
-
)
|
162
|
+
) unless manual_override
|
112
163
|
end
|
113
164
|
end
|
114
165
|
end
|
@@ -10,44 +10,34 @@ module WildlandDevTools
|
|
10
10
|
rollback_production_database(verbose)
|
11
11
|
end
|
12
12
|
|
13
|
-
def turn_on_staging_maintenance_mode(verbose = false)
|
14
|
-
remote = 'staging'
|
15
|
-
puts "Turning on maintenance mode for #{remote}" if verbose
|
16
|
-
system("heroku maintenance:on -r #{remote}")
|
17
|
-
end
|
18
|
-
|
19
|
-
def turn_off_staging_maintenance_mode(verbose = false)
|
20
|
-
remote = 'staging'
|
21
|
-
puts "Turning off maintenance mode for #{remote}" if verbose
|
22
|
-
system("heroku maintenance:off -r #{remote}")
|
23
|
-
end
|
24
|
-
|
25
13
|
def turn_on_heroku_maintenance_mode(verbose = false)
|
26
14
|
%w(staging production).each do |remote|
|
27
|
-
|
28
|
-
|
15
|
+
if remote_available? remote
|
16
|
+
puts "Turning on maintenance mode for #{remote}" if verbose
|
17
|
+
system("heroku maintenance:on -r #{remote}")
|
18
|
+
end
|
29
19
|
end
|
30
20
|
end
|
31
21
|
|
32
22
|
def turn_off_heroku_maintenance_mode(verbose = false)
|
33
23
|
%w(staging production).each do |remote|
|
34
|
-
|
35
|
-
|
24
|
+
if remote_available? remote
|
25
|
+
puts "Turning off maintenance mode for #{remote}" if verbose
|
26
|
+
system("heroku maintenance:off -r #{remote}")
|
27
|
+
end
|
36
28
|
end
|
37
29
|
end
|
38
30
|
|
39
31
|
def deploy_master_to_staging(verbose = false, force = false)
|
40
32
|
puts 'Detecting current branch name.' if verbose
|
41
|
-
branch
|
42
|
-
|
43
|
-
deploy_to_staging(branch, verbose, force)
|
33
|
+
raise GitSyncException, 'Please checkout master branch' unless on_master_branch?
|
34
|
+
deploy_to_staging(get_current_branch_name, verbose, force)
|
44
35
|
end
|
45
36
|
|
46
37
|
|
47
38
|
def deploy_current_branch_to_staging(verbose = false, force = false)
|
48
39
|
puts 'Detecting current branch name.' if verbose
|
49
|
-
|
50
|
-
deploy_to_staging(branch, verbose, force)
|
40
|
+
deploy_to_staging(get_current_branch_name, verbose, force)
|
51
41
|
end
|
52
42
|
|
53
43
|
def deploy_to_staging(branch, verbose = false, force = false)
|
@@ -127,11 +117,15 @@ module WildlandDevTools
|
|
127
117
|
end
|
128
118
|
|
129
119
|
def staging_remote_available?
|
130
|
-
|
120
|
+
remote_available? 'staging'
|
131
121
|
end
|
132
122
|
|
133
123
|
def production_remote_available?
|
134
|
-
|
124
|
+
remote_available? 'production'
|
125
|
+
end
|
126
|
+
|
127
|
+
def remote_available?(remote_name)
|
128
|
+
Git.open('.').remotes.map(&:to_s).include?(remote_name)
|
135
129
|
end
|
136
130
|
|
137
131
|
def heroku_toolbelt_available?
|
@@ -160,12 +154,10 @@ module WildlandDevTools
|
|
160
154
|
system("heroku rollback #{remote}")
|
161
155
|
end
|
162
156
|
|
163
|
-
def rollback_database(remote
|
157
|
+
def rollback_database(remote)
|
164
158
|
ensure_valid_remote(remote)
|
165
|
-
|
166
|
-
|
167
|
-
puts 'Then run \"rake wildland:heroku:maintenance_mode_off\"'
|
168
|
-
end
|
159
|
+
puts "Manually restore database for #{remote}"
|
160
|
+
puts 'Then run \"rake wildland:heroku:maintenance_mode_off\"'
|
169
161
|
end
|
170
162
|
|
171
163
|
def migrate_database(remote, verbose = false)
|
@@ -191,7 +183,15 @@ module WildlandDevTools
|
|
191
183
|
end
|
192
184
|
|
193
185
|
def get_current_branch_name
|
194
|
-
`git rev-parse --abbrev-ref HEAD`.strip
|
186
|
+
`git rev-parse --abbrev-ref HEAD`.strip # TODO swap to ruby-git
|
187
|
+
end
|
188
|
+
|
189
|
+
def on_master_branch?
|
190
|
+
on_branch? 'master'
|
191
|
+
end
|
192
|
+
|
193
|
+
def on_branch?(branch_name)
|
194
|
+
get_current_branch_name == branch_name
|
195
195
|
end
|
196
196
|
|
197
197
|
def get_app_name(remote, verbose = false)
|
data/wildland_dev_tools.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "wildland_dev_tools"
|
8
8
|
spec.version = WildlandDevTools::VERSION
|
9
9
|
spec.authors = ["Joe Weakley"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["joe@wild.land.com"]
|
11
11
|
|
12
12
|
spec.summary = 'Wildland Dev Tools'
|
13
13
|
spec.description = 'Wildland Dev Tools'
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'git', '~> 1.3', '>= 1.3.0'
|
24
24
|
spec.add_runtime_dependency 'table_print', '~> 1.5', '>= 1.5.6'
|
25
25
|
spec.add_runtime_dependency 'brakeman', '~> 4.1'
|
26
|
+
spec.add_runtime_dependency 'highline', '~> 1.7'
|
26
27
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.10"
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wildland_dev_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Weakley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -98,6 +98,20 @@ dependencies:
|
|
98
98
|
- - "~>"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '4.1'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: highline
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '1.7'
|
108
|
+
type: :runtime
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '1.7'
|
101
115
|
- !ruby/object:Gem::Dependency
|
102
116
|
name: bundler
|
103
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +156,7 @@ dependencies:
|
|
142
156
|
version: '0'
|
143
157
|
description: Wildland Dev Tools
|
144
158
|
email:
|
145
|
-
-
|
159
|
+
- joe@wild.land.com
|
146
160
|
executables: []
|
147
161
|
extensions: []
|
148
162
|
extra_rdoc_files: []
|
@@ -150,6 +164,7 @@ files:
|
|
150
164
|
- ".gitignore"
|
151
165
|
- ".rspec"
|
152
166
|
- ".travis.yml"
|
167
|
+
- CHANGELOG.md
|
153
168
|
- Gemfile
|
154
169
|
- LICENSE.txt
|
155
170
|
- README.md
|