conjure 0.1.2 → 0.1.3
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/History.md +5 -0
- data/README.md +8 -5
- data/lib/conjure.rb +1 -5
- data/lib/conjure/service/database.rb +25 -0
- data/lib/conjure/service/database/mysql.rb +71 -0
- data/lib/conjure/service/database/postgres.rb +79 -0
- data/lib/conjure/service/docker_host.rb +2 -1
- data/lib/conjure/service/rails_application.rb +2 -3
- data/lib/conjure/service/rails_codebase.rb +19 -6
- data/lib/conjure/service/rails_server.rb +1 -1
- data/lib/conjure/version.rb +3 -0
- metadata +7 -6
- data/lib/conjure/service.rb +0 -12
- data/lib/conjure/service/machine_instance.rb +0 -54
- data/lib/conjure/service/postgres_database.rb +0 -69
data/History.md
CHANGED
data/README.md
CHANGED
@@ -20,8 +20,8 @@ Also, your Rails application requires all of the following:
|
|
20
20
|
* It must have a `.ruby-version` file indicating which version of
|
21
21
|
Ruby to run
|
22
22
|
|
23
|
-
* It must be able to run in production mode with a single
|
24
|
-
|
23
|
+
* It must be able to run in production mode with a single Postgres
|
24
|
+
or MySQL database (any existing database.yml will be ignored)
|
25
25
|
|
26
26
|
* It must be checked out locally into a git repository with a valid
|
27
27
|
`origin` remote
|
@@ -85,15 +85,18 @@ deploy`.
|
|
85
85
|
|
86
86
|
#### Export
|
87
87
|
|
88
|
-
Produce a Postgres
|
89
|
-
production database, and save it to the
|
88
|
+
Produce a native-format (Postgres or MySQL) dump of the
|
89
|
+
currently-deployed server's production database, and save it to the
|
90
|
+
local file `FILE`.
|
90
91
|
|
91
92
|
conjure export FILE
|
92
93
|
|
93
94
|
#### Import
|
94
95
|
|
95
96
|
Overwrite the production database on the currently-deployed server
|
96
|
-
with a
|
97
|
+
with a dump from the local file `FILE`. The dump should be in the same
|
98
|
+
format as that produced by the `export` command (either a Postgres or
|
99
|
+
MySQL dump according to the database type).
|
97
100
|
|
98
101
|
conjure import FILE
|
99
102
|
|
data/lib/conjure.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
module Conjure
|
2
|
-
|
3
|
-
VERSION = "0.1.2" unless defined?(VERSION)
|
4
|
-
autoload :Command, "conjure/command"
|
5
|
-
autoload :Config, "conjure/config"
|
6
|
-
autoload :Service, "conjure/service"
|
2
|
+
Dir[File.join(File.dirname(__FILE__), "conjure/**/*.rb")].each { |f| require f }
|
7
3
|
|
8
4
|
def self.config
|
9
5
|
@config ||= Config.load Dir.pwd
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Conjure
|
2
|
+
module Service
|
3
|
+
class Database
|
4
|
+
def self.new(options)
|
5
|
+
services_by_gem.each do |gem_name, service_class|
|
6
|
+
if options[:codebase].gem_names.include? gem_name
|
7
|
+
return service_class.new(
|
8
|
+
:docker_host => options[:docker_host],
|
9
|
+
:database_name => options[:codebase].database_name,
|
10
|
+
:adapter_name => adapters_by_gem[gem_name],
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.services_by_gem
|
17
|
+
{"pg" => Postgres, "mysql2" => Mysql, "mysql" => Mysql}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.adapters_by_gem
|
21
|
+
{"pg" => "postgresql", "mysql2" => "mysql2", "mysql" => "mysql"}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Conjure
|
2
|
+
module Service
|
3
|
+
class Database
|
4
|
+
class Mysql
|
5
|
+
def initialize(options)
|
6
|
+
@host = options[:docker_host]
|
7
|
+
@db_name = options[:database_name]
|
8
|
+
@adapter_name = options[:adapter_name]
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_image
|
12
|
+
@base_image ||= @host.images.create(
|
13
|
+
label: "mysql",
|
14
|
+
base_image: "ubuntu",
|
15
|
+
setup_commands: [
|
16
|
+
"apt-get install -y mysql-server mysql-client"
|
17
|
+
],
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def server_image
|
22
|
+
@server_image ||= @host.images.create(
|
23
|
+
label: "mysqlserver",
|
24
|
+
base_image: base_image,
|
25
|
+
setup_commands: [
|
26
|
+
"/usr/sbin/mysqld & sleep 5; echo \"GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '' WITH GRANT OPTION\" | /usr/bin/mysql",
|
27
|
+
],
|
28
|
+
daemon_command: "/usr/sbin/mysqld --bind-address=0.0.0.0",
|
29
|
+
volumes: ["/var/lib/mysql"],
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def run
|
34
|
+
container
|
35
|
+
end
|
36
|
+
|
37
|
+
def container
|
38
|
+
@container ||= server_image.run
|
39
|
+
end
|
40
|
+
|
41
|
+
def name
|
42
|
+
@db_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def ip_address
|
46
|
+
container.ip_address
|
47
|
+
end
|
48
|
+
|
49
|
+
def export(file)
|
50
|
+
File.open file, "w" do |f|
|
51
|
+
f.write base_image.command("/usr/bin/mysqldump #{client_options}")
|
52
|
+
end
|
53
|
+
Conjure.log "[export] #{File.size file} bytes exported to #{file}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def import(file)
|
57
|
+
base_image.command "echo 'source /files/#{File.basename file}' | /usr/bin/mysql #{client_options}", files: [file]
|
58
|
+
Conjure.log "[import] #{File.size file} bytes imported from #{file}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def client_options
|
62
|
+
"-u root -h #{ip_address} #{@db_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def adapter_name
|
66
|
+
@adapter_name || "mysql2"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Conjure
|
2
|
+
module Service
|
3
|
+
class Database
|
4
|
+
class Postgres
|
5
|
+
def initialize(options)
|
6
|
+
@host = options[:docker_host]
|
7
|
+
@db_name = options[:database_name]
|
8
|
+
end
|
9
|
+
|
10
|
+
def base_image
|
11
|
+
@base_image ||= @host.images.create(
|
12
|
+
label: "postgres",
|
13
|
+
base_image: "ubuntu",
|
14
|
+
setup_commands: [
|
15
|
+
"apt-get install -y python-software-properties software-properties-common",
|
16
|
+
"add-apt-repository -y ppa:pitti/postgresql",
|
17
|
+
"apt-get update",
|
18
|
+
"apt-get install -y postgresql-9.2 postgresql-client-9.2 postgresql-contrib-9.2",
|
19
|
+
],
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def server_image
|
24
|
+
@server_image ||= @host.images.create(
|
25
|
+
label: "pgserver",
|
26
|
+
base_image: base_image,
|
27
|
+
setup_commands: [
|
28
|
+
"service postgresql start; su postgres -c 'createuser -d -r -s root; createdb -O root root'; service postgresql stop",
|
29
|
+
"echo 'host all all 0.0.0.0/0 trust' >>/etc/postgresql/9.2/main/pg_hba.conf",
|
30
|
+
"echo \"listen_addresses='*'\" >>/etc/postgresql/9.2/main/postgresql.conf",
|
31
|
+
],
|
32
|
+
daemon_command: "su postgres -c '#{bin_path}/postgres -c config_file=/etc/postgresql/9.2/main/postgresql.conf'",
|
33
|
+
volumes: ["/var/lib/postgresql/9.2/main"],
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
container
|
39
|
+
end
|
40
|
+
|
41
|
+
def container
|
42
|
+
@container ||= server_image.run
|
43
|
+
end
|
44
|
+
|
45
|
+
def name
|
46
|
+
@db_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def ip_address
|
50
|
+
container.ip_address
|
51
|
+
end
|
52
|
+
|
53
|
+
def export(file)
|
54
|
+
File.open file, "w" do |f|
|
55
|
+
f.write base_image.command("#{bin_path}/pg_dump #{client_options} #{@db_name}")
|
56
|
+
end
|
57
|
+
Conjure.log "[export] #{File.size file} bytes exported to #{file}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def import(file)
|
61
|
+
base_image.command "#{bin_path}/psql #{client_options} -d #{@db_name} -f /files/#{File.basename file}", files: [file]
|
62
|
+
Conjure.log "[import] #{File.size file} bytes imported from #{file}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def client_options
|
66
|
+
"-U root -h #{ip_address}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def bin_path
|
70
|
+
"/usr/lib/postgresql/9.2/bin"
|
71
|
+
end
|
72
|
+
|
73
|
+
def adapter_name
|
74
|
+
"postgresql"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -206,7 +206,8 @@ module Conjure
|
|
206
206
|
end
|
207
207
|
|
208
208
|
def find(options)
|
209
|
-
image_name = options[:image_name]
|
209
|
+
image_name = options[:image_name].clone
|
210
|
+
image_name << ":" unless image_name.include? ":"
|
210
211
|
id = host.command("ps | grep #{image_name} ; true").strip.split("\n").first.to_s[0..11]
|
211
212
|
id = nil if id == ""
|
212
213
|
Container.new(:host => host, :id => id) if id
|
@@ -12,7 +12,6 @@ module Conjure
|
|
12
12
|
def deploy
|
13
13
|
Conjure.log "[deploy] Deploying #{@name}:#{@branch} to #{@environment}"
|
14
14
|
unless @test
|
15
|
-
database.run
|
16
15
|
codebase.install
|
17
16
|
rails.run
|
18
17
|
Conjure.log "[deploy] Application deployed to #{docker.ip_address}"
|
@@ -24,11 +23,11 @@ module Conjure
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def database
|
27
|
-
|
26
|
+
codebase.database
|
28
27
|
end
|
29
28
|
|
30
29
|
def codebase
|
31
|
-
@codebase ||= Service::RailsCodebase.new docker, @origin, @branch, @name,
|
30
|
+
@codebase ||= Service::RailsCodebase.new docker, @origin, @branch, @name, @environment
|
32
31
|
end
|
33
32
|
|
34
33
|
def rails
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Conjure
|
2
2
|
module Service
|
3
3
|
class RailsCodebase
|
4
|
-
def initialize(host, github_url, branch, app_name,
|
4
|
+
def initialize(host, github_url, branch, app_name, rails_environment)
|
5
5
|
@github_url = github_url
|
6
6
|
@branch = branch
|
7
7
|
@app_name = app_name
|
8
|
-
@database_ip_address = database_ip_address
|
9
8
|
@rails_environment = rails_environment
|
9
|
+
@host = host
|
10
10
|
github_private_key = Conjure.config.file_contents(:private_key_file).gsub("\n", "\\n")
|
11
11
|
github_public_key = Conjure.config.file_contents(:public_key_file).gsub("\n", "\\n")
|
12
|
-
@image = host.images.create(
|
12
|
+
@image = @host.images.create(
|
13
13
|
label: "codebase",
|
14
14
|
base_image: "ubuntu",
|
15
15
|
setup_commands: [
|
@@ -26,10 +26,10 @@ module Conjure
|
|
26
26
|
def database_yml
|
27
27
|
{
|
28
28
|
@rails_environment => {
|
29
|
-
"adapter" =>
|
30
|
-
"database" =>
|
29
|
+
"adapter" => database.adapter_name,
|
30
|
+
"database" => database.name,
|
31
31
|
"encoding" => "utf8",
|
32
|
-
"host" =>
|
32
|
+
"host" => database.ip_address,
|
33
33
|
"username" => "root",
|
34
34
|
"template" => "template0",
|
35
35
|
}
|
@@ -66,6 +66,19 @@ module Conjure
|
|
66
66
|
setup = 'Rails.logger = Logger.new "#{Rails.root}/log/#{Rails.env}.log"'
|
67
67
|
@image.command "echo '#{setup}' >/#{@app_name}/config/initializers/z_conjure_logger.rb"
|
68
68
|
end
|
69
|
+
|
70
|
+
def database_name
|
71
|
+
"#{@app_name}_#{@rails_environment}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_names
|
75
|
+
gemfile = @image.command "cat #{@app_name}/Gemfile"
|
76
|
+
gemfile.scan(/gem ['"]([^'"]+)['"]/).flatten
|
77
|
+
end
|
78
|
+
|
79
|
+
def database
|
80
|
+
@database ||= Database.new :docker_host => @host, :codebase => self
|
81
|
+
end
|
69
82
|
end
|
70
83
|
end
|
71
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conjure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: unf
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -104,12 +104,13 @@ files:
|
|
104
104
|
- lib/conjure/service/rails_server.rb
|
105
105
|
- lib/conjure/service/rails_codebase.rb
|
106
106
|
- lib/conjure/service/rails_application.rb
|
107
|
-
- lib/conjure/service/
|
107
|
+
- lib/conjure/service/database/postgres.rb
|
108
|
+
- lib/conjure/service/database/mysql.rb
|
108
109
|
- lib/conjure/service/remote_shell.rb
|
109
110
|
- lib/conjure/service/docker_host.rb
|
110
|
-
- lib/conjure/service/
|
111
|
+
- lib/conjure/service/database.rb
|
111
112
|
- lib/conjure/config.rb
|
112
|
-
- lib/conjure/
|
113
|
+
- lib/conjure/version.rb
|
113
114
|
- lib/conjure/command.rb
|
114
115
|
- README.md
|
115
116
|
- History.md
|
data/lib/conjure/service.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module Conjure
|
2
|
-
module Service
|
3
|
-
autoload :RailsApplication, "conjure/service/rails_application"
|
4
|
-
autoload :RailsCodebase, "conjure/service/rails_codebase"
|
5
|
-
autoload :RailsServer, "conjure/service/rails_server"
|
6
|
-
autoload :MachineInstance, "conjure/service/machine_instance"
|
7
|
-
autoload :DockerHost, "conjure/service/docker_host"
|
8
|
-
autoload :CloudServer, "conjure/service/cloud_server"
|
9
|
-
autoload :PostgresDatabase, "conjure/service/postgres_database"
|
10
|
-
autoload :RemoteShell, "conjure/service/remote_shell"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require "vagrant"
|
2
|
-
|
3
|
-
module Conjure
|
4
|
-
module Service
|
5
|
-
class MachineInstance
|
6
|
-
def start
|
7
|
-
@config_path = File.expand_path "../../../../config", __FILE__
|
8
|
-
load_environment
|
9
|
-
install_base_image
|
10
|
-
@vm = @vagrant.primary_vm
|
11
|
-
start_vm
|
12
|
-
issue_test_command
|
13
|
-
end
|
14
|
-
|
15
|
-
def load_environment
|
16
|
-
@vagrant = Vagrant::Environment.new :cwd => @config_path
|
17
|
-
end
|
18
|
-
|
19
|
-
def install_base_image
|
20
|
-
unless @vagrant.boxes.find "precise64"
|
21
|
-
puts "Downloading 300MB Ubuntu base image for Vagrant, this may take a few minutes..."
|
22
|
-
@vagrant.boxes.add "precise64", "http://files.vagrantup.com/precise64.box"
|
23
|
-
load_environment
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def start_vm
|
28
|
-
unless @vm.state == :running
|
29
|
-
puts "Starting a VM..."
|
30
|
-
@vm.up
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def ssh_address
|
35
|
-
info = @vm.ssh.info
|
36
|
-
"#{info[:username]}@#{info[:host]}"
|
37
|
-
end
|
38
|
-
|
39
|
-
def ssh_options
|
40
|
-
info = @vm.ssh.info
|
41
|
-
"-p #{info[:port]} -i #{info[:private_key_path]}"
|
42
|
-
end
|
43
|
-
|
44
|
-
def remote_command_output(command)
|
45
|
-
command.gsub! "'", "'\\\\''"
|
46
|
-
`ssh #{ssh_address} #{ssh_options} '#{command}'`
|
47
|
-
end
|
48
|
-
|
49
|
-
def issue_test_command
|
50
|
-
puts "OS info reported by the VM: #{remote_command_output 'uname -mrs'}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module Conjure
|
2
|
-
module Service
|
3
|
-
class PostgresDatabase
|
4
|
-
def initialize(host, db_name)
|
5
|
-
@host = host
|
6
|
-
@db_name = db_name
|
7
|
-
end
|
8
|
-
|
9
|
-
def base_image
|
10
|
-
@base_image ||= @host.images.create(
|
11
|
-
label: "postgres",
|
12
|
-
base_image: "ubuntu",
|
13
|
-
setup_commands: [
|
14
|
-
"apt-get install -y python-software-properties software-properties-common",
|
15
|
-
"add-apt-repository -y ppa:pitti/postgresql",
|
16
|
-
"apt-get update",
|
17
|
-
"apt-get install -y postgresql-9.2 postgresql-client-9.2 postgresql-contrib-9.2",
|
18
|
-
],
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
def server_image
|
23
|
-
@server_image ||= @host.images.create(
|
24
|
-
label: "pgserver",
|
25
|
-
base_image: base_image,
|
26
|
-
setup_commands: [
|
27
|
-
"service postgresql start; su postgres -c 'createuser -d -r -s root; createdb -O root root'; service postgresql stop",
|
28
|
-
"echo 'host all all 0.0.0.0/0 trust' >>/etc/postgresql/9.2/main/pg_hba.conf",
|
29
|
-
"echo \"listen_addresses='*'\" >>/etc/postgresql/9.2/main/postgresql.conf",
|
30
|
-
],
|
31
|
-
daemon_command: "su postgres -c '#{bin_path}/postgres -c config_file=/etc/postgresql/9.2/main/postgresql.conf'",
|
32
|
-
volumes: ["/var/lib/postgresql/9.2/main"],
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def run
|
37
|
-
container
|
38
|
-
end
|
39
|
-
|
40
|
-
def container
|
41
|
-
@container ||= server_image.run
|
42
|
-
end
|
43
|
-
|
44
|
-
def ip_address
|
45
|
-
container.ip_address
|
46
|
-
end
|
47
|
-
|
48
|
-
def export(file)
|
49
|
-
File.open file, "w" do |f|
|
50
|
-
f.write base_image.command("#{bin_path}/pg_dump #{client_options} #{@db_name}")
|
51
|
-
end
|
52
|
-
Conjure.log "[export] #{File.size file} bytes exported to #{file}"
|
53
|
-
end
|
54
|
-
|
55
|
-
def import(file)
|
56
|
-
base_image.command "#{bin_path}/psql #{client_options} -d #{@db_name} -f /files/#{File.basename file}", files: [file]
|
57
|
-
Conjure.log "[import] #{File.size file} bytes imported from #{file}"
|
58
|
-
end
|
59
|
-
|
60
|
-
def client_options
|
61
|
-
"-U root -h #{ip_address}"
|
62
|
-
end
|
63
|
-
|
64
|
-
def bin_path
|
65
|
-
"/usr/lib/postgresql/9.2/bin"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|