Skip to content

Commit

Permalink
Breaking change: Remove dependencies on external gems
Browse files Browse the repository at this point in the history
v0.9.3 introduced two new features that required reliance on external
libraries. Installing these libraries through our Traveling
Ruby-packaged executable has introduced issues for users. Some users
reported permissions issues related to now-deprecated Bundler behavior
that is still in use on the version of Bundler used by Traveling Ruby
(Ruby 2.2.2 is still locked to Bundler 1.9.x).

After spending considerable time attempting to work through packaging
problems I now think that the potential benefits from these dependencies
are not worth the trouble. We can accomplish most of the needed
functionality without help from external gems.

This commit makes the following changes to Parity:

- **BREAKING CHANGE** Remove the `dotenv` gem and stop loading `ERB`. We
  were previously using `dotenv` and `erb` to allow users to define
  their database name in development dynamically in a `database.yml.erb`
  file that included environment variables. This configuration is an
  edge case that doesn't warrant adding non-trivial complexity to
  accommodate.
- Remove the `git` gem. This gem parsed Git remotes, allowing parity to
  determine the application name and pass the confirmation argument for
  applications named differently than the local development directory.
  This functionality has been retained by leveraging Heroku CLI's `info`
  command to get the application name.
- Remove packaging changes previously made to convey gems along with
  parity for Traveling Ruby packaging.

While I suspect I may have been the only user to make use of environment
variables to specify the name of the development database, these changes
will require a major version update as they break backwards
compatibility.

Fix #91, #93, #96.
  • Loading branch information
geoffharcourt committed Jul 27, 2016
1 parent e2d965e commit 5704201
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 98 deletions.
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
source 'https://rubygems.org'

gem "dotenv"
gem "git"
gem "rake"

group :development do
gem "climate_control"
gem "rake"
gem "rspec"
end
3 changes: 0 additions & 3 deletions lib/parity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
require "parity/version"
require "parity/environment"
require "parity/usage"
require "erb"
require "git"
require "dotenv"
require "open3"
require "pathname"
require "uri"
Expand Down
8 changes: 3 additions & 5 deletions lib/parity/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ def remote_db_backup_url
end

def development_db
YAML.load(parsed_database_yml).
YAML.load(database_yaml_file).
fetch(DEVELOPMENT_ENVIRONMENT_KEY_NAME).
fetch(DATABASE_KEY_NAME)
end

def parsed_database_yml
Dotenv.load
yaml_file = IO.read(DATABASE_YML_RELATIVE_PATH)
ERB.new(yaml_file).result
def database_yaml_file
IO.read(DATABASE_YML_RELATIVE_PATH)
end
end
end
30 changes: 14 additions & 16 deletions lib/parity/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def run

private

GIT_REMOTE_SEGMENT_DELIMITER_REGEX = /[\/:]/
GIT_REMOTE_FILE_EXTENSION_REGEX = /\.git$/
PROTECTED_ENVIRONMENTS = %w(development production)

attr_accessor :environment, :subcommand, :arguments
Expand Down Expand Up @@ -94,19 +92,19 @@ def restore_confirmation_argument
end

def console
Kernel.system("heroku run rails console --remote #{environment}")
Kernel.system(command_for_remote("run rails console"))
end

def migrate
Kernel.system(%{
heroku run rake db:migrate --remote #{environment} &&
heroku restart --remote #{environment}
#{command_for_remote('run rake db:migrate')} &&
#{command_for_remote('restart')}
})
end

def tail
Kernel.system(
"heroku logs --tail #{arguments.join(" ")} --remote #{environment}"
command_for_remote("logs --tail #{arguments.join(' ')}"),
)
end

Expand All @@ -125,20 +123,20 @@ def redis_cli
end

def raw_redis_url
@redis_to_go_url ||= Open3.capture3(
"heroku config:get REDIS_URL "\
"--remote #{environment}"
)[0].strip
@redis_to_go_url ||= Open3.
capture3(command_for_remote("config:get REDIS_URL"))[0].
strip
end

def git_remote
Git.init.remote(environment).url
def heroku_app_name
@heroku_app_name ||= Open3.
capture3(command_for_remote("info"))[0].
split("\n")[0].
gsub(/(\s|=)+/, "")
end

def heroku_app_name
git_remote.
split(GIT_REMOTE_SEGMENT_DELIMITER_REGEX).
last.sub(GIT_REMOTE_FILE_EXTENSION_REGEX, "")
def command_for_remote(command)
"heroku #{command} --remote #{environment}"
end

def run_migrations?
Expand Down
31 changes: 0 additions & 31 deletions spec/parity/backup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "climate_control"

require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'parity')

describe Parity::Backup do
Expand All @@ -17,35 +15,6 @@
with(heroku_production_to_development_passthrough)
end

context "with a database.yml that uses ERB and environment variables" do
around do |example|
ClimateControl.modify DEVELOPMENT_DATABASE_NAME: "erb_database_name" do
example.run
end
end

it "correctly parses database.yml" do
development_db = ENV["DEVELOPMENT_DATABASE_NAME"]
allow(IO).to receive(:read).and_return(database_with_erb_fixture)
allow(Kernel).to receive(:system)

Parity::Backup.new(from: "production", to: "development").restore

expect(Kernel).
to have_received(:system).
with(
drop_development_database_drop_command(db_name: development_db),
)
expect(Kernel).
to have_received(:system).
with(
heroku_production_to_development_passthrough(
db_name: development_db,
),
)
end
end

it "restores backups to staging from production" do
allow(Kernel).to receive(:system)

Expand Down
49 changes: 11 additions & 38 deletions spec/parity/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
expect(Kernel).to have_received(:system).with(heroku_backup)
end

it "correctly connects to the Heroku app when the $PWD's name does not match the app's name (remote uses git:// protocol)" do
it "connects to the Heroku app when $PWD does not match the app name" do
backup = stub_parity_backup
stub_git_remote(base_name: "parity-integration", environment: "staging")
allow(Parity::Backup).to receive(:new).and_return(backup)
Expand All @@ -49,26 +49,6 @@
expect(backup).to have_received(:restore)
end

it "correctly connects to the Heroku app when the $PWD's name does not match the app's name (remote uses https:// protocol)" do
backup = stub_parity_backup
stub_git_remote_for_https(
base_name: "parity-integration",
environment: "staging",
)
allow(Parity::Backup).to receive(:new).and_return(backup)

Parity::Environment.new("staging", ["restore", "production"]).run

expect(Parity::Backup).
to have_received(:new).
with(
from: "production",
to: "staging",
additional_args: "--confirm parity-integration-staging",
)
expect(backup).to have_received(:restore)
end

it "restores backups from production to staging" do
backup = stub_parity_backup
stub_git_remote(environment: "staging")
Expand Down Expand Up @@ -379,23 +359,16 @@ def stub_migration_path_check(result)
end

def stub_git_remote(base_name: "parity", environment: "staging")
git_remote = instance_double(
"Git::Remote",
url: "git@heroku.com:#{base_name}-#{environment}.git",
)
git = instance_double("Git::Base")
allow(git).to receive(:remote).with("staging").and_return(git_remote)
allow(Git).to receive(:init).and_return(git)
end

def stub_git_remote_for_https(base_name: "parity", environment: "staging")
git_remote = instance_double(
"Git::Remote",
url: "https://git.heroku.com/#{base_name}-#{environment}.git",
)
git = instance_double("Git::Base")
allow(git).to receive(:remote).with("staging").and_return(git_remote)
allow(Git).to receive(:init).and_return(git)
allow(Open3).
to receive(:capture3).
with("heroku info --remote #{environment}").
and_return(
[
"=== #{base_name}-#{environment}\nAddOns: blahblahblah",
"",
{},
],
)
end

def stub_parity_backup
Expand Down

0 comments on commit 5704201

Please sign in to comment.