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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6234f6e4b0de3c9522d680873f0656eadc2eb9e1
4
- data.tar.gz: 8eb26ea4a4baaa7d1725c77ba189f4e37b6dcc68
3
+ metadata.gz: e4e155834acdf736ab29c1ec93f809a224aad99f
4
+ data.tar.gz: 2456550fe32dfd2a44f4103ca52120cb2a0b0fb7
5
5
  SHA512:
6
- metadata.gz: 51fc15b1ecd873d961a3faae32c56cb7c164f6118ff87b40eb1a708432fabf679687bc43daa54247b6e830a5479d8343e9e0fbaeb0399ce6aebd899d1993d0bf
7
- data.tar.gz: 26c3c4270ac85ba8d70fc82b62250aafebe61ebce301c673a9b1c97854f91644c027e3132923469234e6814538b3494226ef9fac1adc160b6819d36b06f1bed4
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
- OSX:
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
- Alternatively, you can do the following on all systems
37
- (requires a Ruby installation):
38
-
39
- gem install parity
19
+ [releases]: https://github.com/thoughtbot/parity/releases
40
20
 
41
- All these methods install the following three shell commands:
21
+ Parity requires these command-line programs:
42
22
 
43
- development
44
- staging
45
- production
23
+ git
24
+ heroku
25
+ pg_restore
46
26
 
47
- [releases]: https://github.com/thoughtbot/parity/releases
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 Yaml for
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 'parity'
120
+ require "parity"
144
121
 
145
122
  if ARGV.empty?
146
123
  puts Parity::Usage.new
147
124
  else
148
- Parity::Environment.new('feature-geoff', ARGV).run
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
@@ -5,5 +5,5 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'parity')
5
5
  if ARGV.empty?
6
6
  puts Parity::Usage.new
7
7
  else
8
- Parity::Environment.new('development', ARGV).run
8
+ exit Parity::Environment.new('development', ARGV).run
9
9
  end
data/bin/production CHANGED
@@ -5,5 +5,5 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'parity')
5
5
  if ARGV.empty?
6
6
  puts Parity::Usage.new
7
7
  else
8
- Parity::Environment.new('production', ARGV).run
8
+ exit Parity::Environment.new('production', ARGV).run
9
9
  end
data/bin/staging CHANGED
@@ -5,5 +5,5 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'parity')
5
5
  if ARGV.empty?
6
6
  puts Parity::Usage.new
7
7
  else
8
- Parity::Environment.new('staging', ARGV).run
8
+ exit Parity::Environment.new('staging', ARGV).run
9
9
  end
data/lib/parity.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  $LOAD_PATH << File.expand_path("..", __FILE__)
2
2
 
3
3
  require "parity/version"
4
- require "parity/configuration"
5
4
  require "parity/environment"
6
5
  require "parity/usage"
7
6
  require "open3"
8
7
  require "uri"
9
-
10
- Parity.configure
data/lib/parity/backup.rb CHANGED
@@ -8,10 +8,12 @@ module Parity
8
8
  end
9
9
 
10
10
  def restore
11
- if to == 'development'
11
+ if to == "development"
12
12
  restore_to_development
13
+ elsif from == "development"
14
+ restore_from_development
13
15
  else
14
- restore_to_pass_through
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 restore_to_development
25
- Kernel.system "#{curl} | #{pg_restore}"
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 curl
29
- "curl -s `#{db_backup_url}`"
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 restore_to_pass_through
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
- "`#{db_backup_url}` DATABASE"
52
+ "`#{remote_db_backup_url}` DATABASE"
45
53
  end
46
54
 
47
- def db_backup_url
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(Parity.config.database_config_path)
60
+ yaml_file = IO.read("config/database.yml")
53
61
  YAML.load(yaml_file)['development']['database']
54
62
  end
55
63
  end
@@ -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 "heroku", subcommand, *arguments, "--remote", environment
32
+ Kernel.system("heroku", subcommand, *arguments, "--remote", environment)
31
33
  end
32
34
 
33
35
  def backup
34
- Kernel.system "heroku pg:backups capture --remote #{environment}"
36
+ Kernel.system("heroku pg:backups capture --remote #{environment}")
35
37
  end
36
38
 
37
39
  def deploy
38
- skip_migration = skip_migration?
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 environment == "production"
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: arguments.drop(1).join(" ")
63
+ additional_args: additional_restore_arguments,
56
64
  ).restore
57
65
  end
58
66
  end
59
67
 
60
- def console
61
- Kernel.system "heroku run rails console --remote #{environment}"
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 log2viz
65
- Kernel.system "open https://log2viz.herokuapp.com/app/#{heroku_app_name}"
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 #{Parity.config.redis_url_env_variable} "\
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
- Parity.config.heroku_app_basename || Dir.pwd.split('/').last
127
+ Dir.pwd.split("/").last
108
128
  end
109
129
 
110
- def skip_migration?
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
@@ -1,3 +1,3 @@
1
1
  module Parity
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
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.7.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-05-08 00:00:00.000000000 Z
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.4.5
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.
@@ -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