parity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzNiZWZhM2E4ZmJmYjU4NzhhMjZlYTFiZjQyMDZhMDE3MGU0ZWRiMA==
5
+ data.tar.gz: !binary |-
6
+ OTZmOWIxOTkzYjE0ZjVkNmY2YzE4YjZkNzRlZGMwNDdjYTJjNjg1MQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzIyZDJiNjAzNmFiMWQzYjJjZTkzMGU3ODZiODczYWI5YWQwY2UxYzRhMTdl
10
+ MWJhNzc0NjhjM2NhZGVlMWNhZTgxOGI1MmNiNmMxODQ4M2ZiNDMyMTg2N2Q0
11
+ MTJlZTdhNTE5OGU3Njc0ZDIzZmUzMjc3N2I3MTVjOTMwMWE2MGE=
12
+ data.tar.gz: !binary |-
13
+ YzIxNDQ1NzBkOTNhMjZhOGExYzA2YWNlOTk1NzNjYzI0ZWEzZjVlODNlOWY5
14
+ OTIzY2M5MDQyNjRjYWRmOTQ0NTAzMWJiYjVlYTYwN2NkMjM1MDg2YTFhODIx
15
+ MzMyZjM0MWE0NmQ0YTRmMDQ3NzBmMDBiYjM3MjlkYzI0ODc1ZDk=
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'parity')
4
+
5
+ Parity::Production.new(ARGV).run
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'parity')
5
+
6
+ options = {}
7
+
8
+ optparse = OptionParser.new do |opts|
9
+ opts.on '-f', '--from DATABASE_ENV', 'The source database (such as production or staging)' do |from|
10
+ options[:from] = from
11
+ end
12
+
13
+ opts.on '-t', '--to DATABASE_ENV', 'The target database (such as staging or development)' do |to|
14
+ options[:to] = to
15
+ end
16
+
17
+ opts.on '-h', '--help', 'Restore backup from one environment into another.' do
18
+ puts opts
19
+ exit
20
+ end
21
+ end
22
+
23
+ optparse.parse!
24
+ Parity::Backup.new(options).restore
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'parity')
4
+
5
+ Parity::Staging.new(ARGV).run
@@ -0,0 +1,4 @@
1
+ require 'parity/backup'
2
+ require 'parity/environment'
3
+ require 'parity/production'
4
+ require 'parity/staging'
@@ -0,0 +1,43 @@
1
+ require 'yaml'
2
+
3
+ module Parity
4
+ class Backup
5
+ def initialize(options)
6
+ @from = options[:from]
7
+ @to = options[:to]
8
+ end
9
+
10
+ def restore
11
+ if to == 'development'
12
+ restore_to_development
13
+ else
14
+ restore_to_pass_through
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :from, :to
21
+
22
+ def restore_to_development
23
+ system %{
24
+ curl -s `#{db_backup_url}` | \
25
+ pg_restore --verbose --clean --no-acl --no-owner -d #{development_db}
26
+ }
27
+ end
28
+
29
+ def restore_to_pass_through
30
+ system %{
31
+ heroku pgbackups:restore DATABASE `#{db_backup_url}` --remote #{to}
32
+ }
33
+ end
34
+
35
+ def db_backup_url
36
+ "heroku pgbackups:url --remote #{from}"
37
+ end
38
+
39
+ def development_db
40
+ YAML.load(IO.read('config/database.yml'))['development']['database']
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,40 @@
1
+ module Parity
2
+ class Environment
3
+ def initialize(subcommands)
4
+ @subcommand = subcommands.first
5
+ @pass_through = subcommands.join(' ')
6
+ end
7
+
8
+ def run
9
+ case subcommand
10
+ when 'backup'
11
+ system "heroku pgbackups:capture --expire --remote #{environment}"
12
+ when 'console'
13
+ system "heroku run console --remote #{environment}"
14
+ when 'log2viz'
15
+ system "open https://log2viz.herokuapp.com/app/#{heroku_app_name}"
16
+ when 'migrate'
17
+ system %{
18
+ heroku run rake db:migrate --remote #{environment} &&
19
+ heroku restart --remote #{environment}
20
+ }
21
+ when 'tail'
22
+ system "heroku logs --tail --remote #{environment}"
23
+ else
24
+ system "heroku #{pass_through} --remote #{environment}"
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :environment, :pass_through, :subcommand
31
+
32
+ def heroku_app_name
33
+ [app_name, environment].join('-')
34
+ end
35
+
36
+ def app_name
37
+ Dir.pwd.split('/').last
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ module Parity
2
+ class Production < Environment
3
+ def initialize(subcommands)
4
+ @environment = 'production'
5
+ super(subcommands)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Parity
2
+ class Staging < Environment
3
+ def initialize(subcommands)
4
+ @environment = 'staging'
5
+ super(subcommands)
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Croak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! " Devevelopment/staging/production parity is intended to decrease
14
+ the time\n between a developer writing code and having it deployed, make it possible\n
15
+ \ for the same people who wrote the code to deploy it and watch its behavior\n
16
+ \ in production, and reduce the number of tools necessary to manage.\n"
17
+ email:
18
+ - dan@thoughtbot.com
19
+ executables:
20
+ - production
21
+ - restore-backup
22
+ - staging
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - lib/parity.rb
27
+ - lib/parity/backup.rb
28
+ - lib/parity/environment.rb
29
+ - lib/parity/production.rb
30
+ - lib/parity/staging.rb
31
+ - bin/production
32
+ - bin/restore-backup
33
+ - bin/staging
34
+ homepage: https://github.com/croaky/parity
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.0.0
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Shell commands for development, staging, and production parity.
58
+ test_files: []
59
+ has_rdoc: