cf_heroku_migrator 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cf_heroku_migrator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Karl Isenberg
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ cf_heroku_migrator
2
+ ==================
3
+
4
+ Migrate from Heroku to Cloud Foundry
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cf_heroku_migrator'
4
+ CfMigrator.migrate
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cf_heroku_migrator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cf_heroku_migrator"
8
+ spec.version = CfHerokuMigrator::VERSION
9
+ spec.authors = ["Pivotpong"]
10
+ spec.email = ["ple+pivotpong@pivotallabs.com", "jpalermo@pivotallabs.com"]
11
+ spec.summary = %q{Move an app to CF from Heroku}
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "heroku-api"
20
+ spec.add_dependency "highline"
21
+ spec.add_dependency "sshkey"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,3 @@
1
+ module CfHerokuMigrator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,71 @@
1
+ require "highline/import"
2
+ require "heroku-api"
3
+ require "json"
4
+ require "cf_heroku_migrator/version"
5
+ require "sshkey"
6
+ require "tmpdir"
7
+
8
+ class CfMigrator
9
+ def self.migrate
10
+ heroku_username = ask("What is your heroku username: ")
11
+ heroku_password = ask("What is your heroku password: ") { |q| q.echo = "*" }
12
+
13
+ heroku = Heroku::API.new(:username => heroku_username, :password => heroku_password)
14
+
15
+ apps = heroku.get_apps.body.collect { |app| app["name"] }
16
+
17
+ heroku_app_name = ask("Which app do you want to import? (#{apps.join(", ")}): ") { |q| q.default = apps.first }
18
+
19
+ config_vars = heroku.get_config_vars(heroku_app_name).body
20
+ database_url = config_vars["DATABASE_URL"]
21
+ config_vars_to_exclude = %w(PGBACKUPS_URL BUNDLE_WITHOUT LOGGING_EXPANDED_UPGRADE DATABASE_URL APP_NAME COMMIT_HASH URL HEROKU_POSTGRESQL_SILVER_URL LAST_GIT_BY RACK_ENV LANG CONSOLE_AUTH STACK)
22
+ config_vars.delete_if { |key, value| config_vars_to_exclude.include? key }
23
+
24
+ config_vars_keys_to_import = ask("Which config vars do you want to import? Space separate them, or press Enter to select all. (#{config_vars.keys.join(", ")}): ")
25
+ if config_vars_keys_to_import.length > 0
26
+ keys_to_keep = config_vars_keys_to_import.downcase.split(" ")
27
+ config_vars.select! { |key, value| keys_to_keep.include? key.downcase }
28
+
29
+ raise "KEY NOT FOUND" unless keys_to_keep.length == config_vars.length
30
+ end
31
+
32
+ ssh_key = SSHKey.generate
33
+ heroku.post_key(ssh_key.ssh_public_key)
34
+
35
+ Dir.mktmpdir("app") do |dir|
36
+ Dir.chdir(dir) do
37
+ File.open("private_key", "w") {|f| f << ssh_key.private_key.to_s }
38
+ File.chmod(0600, "private_key")
39
+ `ssh-add private_key && git clone git@heroku.com:#{heroku_app_name}.git`
40
+
41
+ heroku.delete_key(ssh_key.ssh_public_key)
42
+
43
+ Dir.chdir(heroku_app_name) do
44
+ say "Pushing app to CF"
45
+ `cf push #{heroku_app_name} --no-start --random-route`
46
+ end
47
+ end
48
+ end
49
+
50
+ say "Creating a DB"
51
+ `cf create-service elephantsql turtle #{heroku_app_name}-db`
52
+
53
+ say "Binding to app #{heroku_app_name}"
54
+ `cf bind-service #{heroku_app_name} #{heroku_app_name}-db`
55
+
56
+ app_json = JSON.parse(`cf curl /v2/apps`)["resources"].find { |resource| resource["entity"]["name"] == heroku_app_name }
57
+ service_binding_url = app_json["entity"]["service_bindings_url"]
58
+ elephantsql_url = JSON.parse(`cf curl #{service_binding_url}`)["resources"].first["entity"]["credentials"]["uri"]
59
+
60
+
61
+ say "Migrating DB from Heroku to CF"
62
+ `pg_dump #{database_url} | psql -q #{elephantsql_url}`
63
+
64
+ config_vars.each do |k, v|
65
+ say "Setting ENV: #{k}"
66
+ `cf set-env #{heroku_app_name} #{k} #{v}`
67
+ end
68
+
69
+ exec "cf start #{heroku_app_name} "
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cf_heroku_migrator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pivotpong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: heroku-api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sshkey
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.6'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.6'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description:
95
+ email:
96
+ - ple+pivotpong@pivotallabs.com
97
+ - jpalermo@pivotallabs.com
98
+ executables:
99
+ - cf_heroku_migrate
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - bin/cf_heroku_migrate
109
+ - cf_heroku_migrator.gemspec
110
+ - lib/cf_heroku_migrator.rb
111
+ - lib/cf_heroku_migrator/version.rb
112
+ homepage:
113
+ licenses:
114
+ - MIT
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.23.2
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Move an app to CF from Heroku
137
+ test_files: []