parity 0.7.0 → 0.8.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 +4 -4
- data/README.md +25 -48
- data/bin/development +1 -1
- data/bin/production +1 -1
- data/bin/staging +1 -1
- data/lib/parity.rb +0 -3
- data/lib/parity/backup.rb +19 -11
- data/lib/parity/environment.rb +40 -20
- data/lib/parity/version.rb +1 -1
- metadata +3 -4
- data/lib/parity/configuration.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4e155834acdf736ab29c1ec93f809a224aad99f
|
4
|
+
data.tar.gz: 2456550fe32dfd2a44f4103ca52120cb2a0b0fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5390a193b5833b01e5b30f5dd96a1d505667807a21e6fe8bbeab22c7967d7f1ca7cffaa5d07a2a66bf6105df2374987a5fa6f82f839ac31d4f00ba337c2c24d9
|
7
|
+
data.tar.gz: acd28f15ba2039c1d96a36c5083de72b4ef0c9d67724f9c87eed7a0a6c32fc6be569efc2c5b1ac5901aad115809fbbfd2107fdeba21a844351c0e72ef3958c1c
|
data/README.md
CHANGED
@@ -3,27 +3,10 @@ Parity
|
|
3
3
|
|
4
4
|
Shell commands for development, staging, and production parity for Heroku apps.
|
5
5
|
|
6
|
-
Prerequisites
|
7
|
-
-------------
|
8
|
-
|
9
|
-
Your development machine will need these command-line programs:
|
10
|
-
|
11
|
-
git
|
12
|
-
curl
|
13
|
-
heroku
|
14
|
-
pg_restore
|
15
|
-
|
16
|
-
On a Mac,
|
17
|
-
`curl` and `git` are installed by default
|
18
|
-
and the other programs can be installed with Homebrew:
|
19
|
-
|
20
|
-
brew install heroku-toolbelt
|
21
|
-
brew install postgres
|
22
|
-
|
23
6
|
Install
|
24
7
|
-------
|
25
8
|
|
26
|
-
|
9
|
+
On OS X, this installs everything you need:
|
27
10
|
|
28
11
|
brew tap thoughtbot/formulae
|
29
12
|
brew install parity
|
@@ -33,18 +16,17 @@ On other systems you can:
|
|
33
16
|
1. Download the package for your system from the [releases page][releases]
|
34
17
|
1. Extract the tarball and place it so that `/bin` is in your `PATH`
|
35
18
|
|
36
|
-
|
37
|
-
(requires a Ruby installation):
|
38
|
-
|
39
|
-
gem install parity
|
19
|
+
[releases]: https://github.com/thoughtbot/parity/releases
|
40
20
|
|
41
|
-
|
21
|
+
Parity requires these command-line programs:
|
42
22
|
|
43
|
-
|
44
|
-
|
45
|
-
|
23
|
+
git
|
24
|
+
heroku
|
25
|
+
pg_restore
|
46
26
|
|
47
|
-
|
27
|
+
On OS X, these programs are installed
|
28
|
+
as Homebrew package dependencies of
|
29
|
+
the `parity` Homebrew package.
|
48
30
|
|
49
31
|
Usage
|
50
32
|
-----
|
@@ -63,6 +45,10 @@ Restore a production database backup into staging:
|
|
63
45
|
|
64
46
|
staging restore production
|
65
47
|
|
48
|
+
Push your local development database backup up to staging:
|
49
|
+
|
50
|
+
development restore staging
|
51
|
+
|
66
52
|
Deploy from master, and migrate and restart the dynos if necessary:
|
67
53
|
|
68
54
|
production deploy
|
@@ -73,11 +59,6 @@ Open a console:
|
|
73
59
|
production console
|
74
60
|
staging console
|
75
61
|
|
76
|
-
Open [log2viz][1]:
|
77
|
-
|
78
|
-
production log2viz
|
79
|
-
staging log2viz
|
80
|
-
|
81
62
|
Migrate a database and restart the dynos:
|
82
63
|
|
83
64
|
production migrate
|
@@ -99,7 +80,6 @@ with `heroku ______ --remote staging` or `heroku ______ --remote production`:
|
|
99
80
|
watch production ps
|
100
81
|
staging open
|
101
82
|
|
102
|
-
[1]: https://blog.heroku.com/archives/2013/3/19/log2viz
|
103
83
|
[2]: http://redis.io/commands
|
104
84
|
|
105
85
|
Convention
|
@@ -109,7 +89,7 @@ Parity expects:
|
|
109
89
|
|
110
90
|
* A `staging` remote pointing to the staging Heroku app.
|
111
91
|
* A `production` remote pointing to the production Heroku app.
|
112
|
-
* There is a `config/database.yml` file that can be parsed as
|
92
|
+
* There is a `config/database.yml` file that can be parsed as YAML for
|
113
93
|
`['development']['database']`.
|
114
94
|
* The Heroku apps are named like `app-staging` and `app-production`
|
115
95
|
where `app` is equal to `basename $PWD`.
|
@@ -117,21 +97,18 @@ Parity expects:
|
|
117
97
|
Customization
|
118
98
|
-------------
|
119
99
|
|
120
|
-
Override some of the conventions:
|
121
|
-
|
122
|
-
```ruby
|
123
|
-
Parity.configure do |config|
|
124
|
-
config.database_config_path = "different/path.yml"
|
125
|
-
config.heroku_app_basename = "different-base-name"
|
126
|
-
config.redis_url_env_variable = "DIFFERENT_REDIS_URL"
|
127
|
-
end
|
128
|
-
```
|
129
|
-
|
130
100
|
If you have Heroku environments beyond staging and production (such as a feature
|
131
101
|
environment for each developer), you can add a [binstub] to the `bin` folder of
|
132
102
|
your application. Custom environments share behavior with staging: they can be
|
133
103
|
backed up and can restore from production.
|
134
104
|
|
105
|
+
Using feature environments requires including Parity as a gem in your
|
106
|
+
application's Gemfile.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
gem "parity"
|
110
|
+
```
|
111
|
+
|
135
112
|
[binstub]: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs
|
136
113
|
|
137
114
|
Here's an example binstub for a 'feature-geoff' environment, hosted at
|
@@ -140,24 +117,24 @@ myapp-feature-geoff.herokuapp.com.
|
|
140
117
|
```ruby
|
141
118
|
#!/usr/bin/env ruby
|
142
119
|
|
143
|
-
require
|
120
|
+
require "parity"
|
144
121
|
|
145
122
|
if ARGV.empty?
|
146
123
|
puts Parity::Usage.new
|
147
124
|
else
|
148
|
-
Parity::Environment.new(
|
125
|
+
Parity::Environment.new("feature-geoff", ARGV).run
|
149
126
|
end
|
150
127
|
```
|
151
128
|
|
152
129
|
Contributing
|
153
130
|
------------
|
154
131
|
|
155
|
-
Please see CONTRIBUTING.md for details.
|
132
|
+
Please see [`CONTRIBUTING.md`](CONTRIBUTING.md) for details.
|
156
133
|
|
157
134
|
Releasing
|
158
135
|
---------
|
159
136
|
|
160
|
-
See guidelines in RELEASING.md for details
|
137
|
+
See guidelines in [`RELEASING.md`](RELEASING.md) for details
|
161
138
|
|
162
139
|
License
|
163
140
|
-------
|
data/bin/development
CHANGED
data/bin/production
CHANGED
data/bin/staging
CHANGED
data/lib/parity.rb
CHANGED
data/lib/parity/backup.rb
CHANGED
@@ -8,10 +8,12 @@ module Parity
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def restore
|
11
|
-
if to ==
|
11
|
+
if to == "development"
|
12
12
|
restore_to_development
|
13
|
+
elsif from == "development"
|
14
|
+
restore_from_development
|
13
15
|
else
|
14
|
-
|
16
|
+
restore_to_remote_environment
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -21,35 +23,41 @@ module Parity
|
|
21
23
|
|
22
24
|
private
|
23
25
|
|
24
|
-
def
|
25
|
-
Kernel.system
|
26
|
+
def restore_from_development
|
27
|
+
Kernel.system(
|
28
|
+
"heroku pg:push #{development_db} DATABASE_URL --remote #{to} "\
|
29
|
+
"#{additional_args}",
|
30
|
+
)
|
26
31
|
end
|
27
32
|
|
28
|
-
def
|
29
|
-
|
33
|
+
def restore_to_development
|
34
|
+
Kernel.system(
|
35
|
+
"heroku pg:pull DATABASE_URL #{development_db} --remote #{from} "\
|
36
|
+
"#{additional_args}",
|
37
|
+
)
|
30
38
|
end
|
31
39
|
|
32
40
|
def pg_restore
|
33
41
|
"pg_restore --verbose --clean --no-acl --no-owner -d #{development_db}"
|
34
42
|
end
|
35
43
|
|
36
|
-
def
|
44
|
+
def restore_to_remote_environment
|
37
45
|
Kernel.system(
|
38
46
|
"heroku pg:backups restore #{backup_from} --remote #{to} "\
|
39
|
-
"#{additional_args}"
|
47
|
+
"#{additional_args}",
|
40
48
|
)
|
41
49
|
end
|
42
50
|
|
43
51
|
def backup_from
|
44
|
-
"`#{
|
52
|
+
"`#{remote_db_backup_url}` DATABASE"
|
45
53
|
end
|
46
54
|
|
47
|
-
def
|
55
|
+
def remote_db_backup_url
|
48
56
|
"heroku pg:backups public-url --remote #{from}"
|
49
57
|
end
|
50
58
|
|
51
59
|
def development_db
|
52
|
-
yaml_file = IO.read(
|
60
|
+
yaml_file = IO.read("config/database.yml")
|
53
61
|
YAML.load(yaml_file)['development']['database']
|
54
62
|
end
|
55
63
|
end
|
data/lib/parity/environment.rb
CHANGED
@@ -20,6 +20,8 @@ module Parity
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
PROTECTED_ENVIRONMENTS = %w(development production)
|
24
|
+
|
23
25
|
attr_accessor :environment, :subcommand, :arguments
|
24
26
|
|
25
27
|
def open
|
@@ -27,49 +29,67 @@ module Parity
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def run_via_cli
|
30
|
-
Kernel.system
|
32
|
+
Kernel.system("heroku", subcommand, *arguments, "--remote", environment)
|
31
33
|
end
|
32
34
|
|
33
35
|
def backup
|
34
|
-
Kernel.system
|
36
|
+
Kernel.system("heroku pg:backups capture --remote #{environment}")
|
35
37
|
end
|
36
38
|
|
37
39
|
def deploy
|
38
|
-
|
39
|
-
|
40
|
-
Kernel.system "git push #{environment} master"
|
41
|
-
|
42
|
-
unless skip_migration
|
40
|
+
if deploy_to_heroku && run_migration?
|
43
41
|
migrate
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
45
|
+
def deploy_to_heroku
|
46
|
+
if production?
|
47
|
+
Kernel.system("git push production master")
|
48
|
+
else
|
49
|
+
Kernel.system(
|
50
|
+
"git push #{environment} HEAD:master --force",
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
47
55
|
def restore
|
48
|
-
if
|
56
|
+
if production?
|
49
57
|
$stdout.puts "Parity does not support restoring backups into your "\
|
50
58
|
"production environment."
|
51
59
|
else
|
52
60
|
Backup.new(
|
53
61
|
from: arguments.first,
|
54
62
|
to: environment,
|
55
|
-
additional_args:
|
63
|
+
additional_args: additional_restore_arguments,
|
56
64
|
).restore
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
|
-
def
|
61
|
-
|
68
|
+
def production?
|
69
|
+
environment == "production"
|
70
|
+
end
|
71
|
+
|
72
|
+
def additional_restore_arguments
|
73
|
+
(arguments.drop(1) + [restore_confirmation_argument]).
|
74
|
+
compact.
|
75
|
+
join(" ")
|
62
76
|
end
|
63
77
|
|
64
|
-
def
|
65
|
-
|
78
|
+
def restore_confirmation_argument
|
79
|
+
unless PROTECTED_ENVIRONMENTS.include?(environment)
|
80
|
+
"--confirm #{heroku_app_name}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def console
|
85
|
+
Kernel.system("heroku run rails console --remote #{environment}")
|
66
86
|
end
|
67
87
|
|
68
88
|
def migrate
|
69
|
-
Kernel.system
|
89
|
+
Kernel.system(%{
|
70
90
|
heroku run rake db:migrate --remote #{environment} &&
|
71
91
|
heroku restart --remote #{environment}
|
72
|
-
}
|
92
|
+
})
|
73
93
|
end
|
74
94
|
|
75
95
|
def tail
|
@@ -94,7 +114,7 @@ module Parity
|
|
94
114
|
|
95
115
|
def raw_redis_url
|
96
116
|
@redis_to_go_url ||= Open3.capture3(
|
97
|
-
"heroku config:get
|
117
|
+
"heroku config:get REDIS_URL "\
|
98
118
|
"--remote #{environment}"
|
99
119
|
)[0].strip
|
100
120
|
end
|
@@ -104,14 +124,14 @@ module Parity
|
|
104
124
|
end
|
105
125
|
|
106
126
|
def basename
|
107
|
-
|
127
|
+
Dir.pwd.split("/").last
|
108
128
|
end
|
109
129
|
|
110
|
-
def
|
111
|
-
Kernel.system
|
130
|
+
def run_migration?
|
131
|
+
!Kernel.system(%{
|
112
132
|
git fetch #{environment} &&
|
113
133
|
git diff --quiet #{environment}/master..master -- db/migrate
|
114
|
-
}
|
134
|
+
})
|
115
135
|
end
|
116
136
|
end
|
117
137
|
end
|
data/lib/parity/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Development/staging/production parity makes it easier for
|
@@ -28,7 +28,6 @@ files:
|
|
28
28
|
- bin/staging
|
29
29
|
- lib/parity.rb
|
30
30
|
- lib/parity/backup.rb
|
31
|
-
- lib/parity/configuration.rb
|
32
31
|
- lib/parity/environment.rb
|
33
32
|
- lib/parity/usage.rb
|
34
33
|
- lib/parity/version.rb
|
@@ -52,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
51
|
version: '0'
|
53
52
|
requirements: []
|
54
53
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
54
|
+
rubygems_version: 2.5.0
|
56
55
|
signing_key:
|
57
56
|
specification_version: 4
|
58
57
|
summary: Shell commands for development, staging, and production parity.
|
data/lib/parity/configuration.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Parity
|
2
|
-
class Configuration
|
3
|
-
attr_accessor \
|
4
|
-
:database_config_path,
|
5
|
-
:heroku_app_basename,
|
6
|
-
:redis_url_env_variable
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@database_config_path = "config/database.yml"
|
10
|
-
@redis_url_env_variable = "REDIS_URL"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
attr_accessor :config
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.configure
|
19
|
-
self.config ||= Configuration.new
|
20
|
-
|
21
|
-
if block_given?
|
22
|
-
yield config
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|