conjure 0.1.4 → 0.1.5
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/lib/conjure.rb +0 -4
- data/lib/conjure/command.rb +6 -0
- data/lib/conjure/log.rb +15 -0
- data/lib/conjure/service/cloud_server.rb +3 -2
- data/lib/conjure/service/database/mysql.rb +2 -2
- data/lib/conjure/service/database/postgres.rb +2 -2
- data/lib/conjure/service/docker_host.rb +8 -10
- data/lib/conjure/service/rails_application.rb +2 -2
- data/lib/conjure/service/rails_codebase.rb +2 -2
- data/lib/conjure/service/rails_server.rb +4 -4
- data/lib/conjure/service/remote_shell.rb +18 -11
- data/lib/conjure/service/repository_link.rb +2 -2
- data/lib/conjure/version.rb +1 -1
- metadata +3 -2
data/History.md
CHANGED
data/lib/conjure.rb
CHANGED
data/lib/conjure/command.rb
CHANGED
@@ -4,6 +4,12 @@ module Conjure
|
|
4
4
|
class Command < Thor
|
5
5
|
attr_accessor :application_options
|
6
6
|
|
7
|
+
class_option :verbose, :aliases => "-v", :type => :boolean, :desc => "Show details of low-level operations for debugging"
|
8
|
+
def initialize(*args)
|
9
|
+
super
|
10
|
+
Log.level = :debug if options[:verbose]
|
11
|
+
end
|
12
|
+
|
7
13
|
desc "deploy", "Deploy the app"
|
8
14
|
method_option :branch, :aliases => "-b", :type => :string, :desc => "Specify branch to deploy"
|
9
15
|
method_option :test, :type => :boolean, :desc => "Describe the deploy settings but don't deploy"
|
data/lib/conjure/log.rb
ADDED
@@ -3,6 +3,7 @@ module Conjure
|
|
3
3
|
class CloudServer
|
4
4
|
require "fog"
|
5
5
|
require "digest/md5"
|
6
|
+
require "pathname"
|
6
7
|
|
7
8
|
def initialize(name)
|
8
9
|
@name = name
|
@@ -39,12 +40,12 @@ module Conjure
|
|
39
40
|
|
40
41
|
def existing_server
|
41
42
|
server = connection.servers.find{|s| s.name == @name }
|
42
|
-
|
43
|
+
Log.info " [cloud] Using existing server #{@name}" if server
|
43
44
|
server
|
44
45
|
end
|
45
46
|
|
46
47
|
def new_server
|
47
|
-
|
48
|
+
Log.info " [cloud] Launching new server #{@name}"
|
48
49
|
connection.servers.bootstrap bootstrap_options.merge(fog_credentials)
|
49
50
|
end
|
50
51
|
|
@@ -48,12 +48,12 @@ module Conjure
|
|
48
48
|
File.open file, "w" do |f|
|
49
49
|
f.write base_image.command("/usr/bin/mysqldump #{client_options}")
|
50
50
|
end
|
51
|
-
|
51
|
+
Log.info "[export] #{File.size file} bytes exported to #{file}"
|
52
52
|
end
|
53
53
|
|
54
54
|
def import(file)
|
55
55
|
base_image.command "echo 'source /files/#{File.basename file}' | /usr/bin/mysql #{client_options}", files: [file]
|
56
|
-
|
56
|
+
Log.info "[import] #{File.size file} bytes imported from #{file}"
|
57
57
|
end
|
58
58
|
|
59
59
|
def client_options
|
@@ -52,12 +52,12 @@ module Conjure
|
|
52
52
|
File.open file, "w" do |f|
|
53
53
|
f.write base_image.command("#{bin_path}/pg_dump #{client_options} #{@db_name}")
|
54
54
|
end
|
55
|
-
|
55
|
+
Log.info "[export] #{File.size file} bytes exported to #{file}"
|
56
56
|
end
|
57
57
|
|
58
58
|
def import(file)
|
59
59
|
base_image.command "#{bin_path}/psql #{client_options} -d #{@db_name} -f /files/#{File.basename file}", files: [file]
|
60
|
-
|
60
|
+
Log.info "[import] #{File.size file} bytes imported from #{file}"
|
61
61
|
end
|
62
62
|
|
63
63
|
def client_options
|
@@ -3,8 +3,6 @@ require 'digest/sha1'
|
|
3
3
|
module Conjure
|
4
4
|
module Service
|
5
5
|
class DockerHost
|
6
|
-
VERBOSE = false
|
7
|
-
|
8
6
|
def initialize(server_name)
|
9
7
|
@server_name = server_name
|
10
8
|
end
|
@@ -18,7 +16,7 @@ module Conjure
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def new_docker_path
|
21
|
-
|
19
|
+
Log.info "[docker] Installing docker"
|
22
20
|
server.run "dd if=/dev/zero of=/root/swapfile bs=1024 count=524288"
|
23
21
|
server.run "mkswap /root/swapfile; swapon /root/swapfile"
|
24
22
|
server.run "curl https://get.docker.io/gpg | apt-key add -"
|
@@ -31,7 +29,7 @@ module Conjure
|
|
31
29
|
def existing_docker_path
|
32
30
|
path = server.run("which docker").stdout.to_s.strip
|
33
31
|
path = nil if path == ""
|
34
|
-
|
32
|
+
Log.info "[docker] Using installed #{path}" if path
|
35
33
|
path
|
36
34
|
end
|
37
35
|
|
@@ -44,8 +42,8 @@ module Conjure
|
|
44
42
|
full_command = "#{docker_path} #{command}"
|
45
43
|
full_command = "nohup #{full_command}" if options[:nohup]
|
46
44
|
full_command = "echo '#{shell_escape options[:stdin]}' | #{full_command}" if options[:stdin]
|
47
|
-
|
48
|
-
|
45
|
+
Log.debug " [scp] #{options[:files].inspect}" if options[:files]
|
46
|
+
Log.debug " [ssh] #{full_command}"
|
49
47
|
result = server.run full_command, :stream_stdin => options[:stream_stdin], :files => options[:files], &block
|
50
48
|
raise "Docker error: #{result.stdout} #{result.stderr}" unless result.status == 0
|
51
49
|
result.stdout
|
@@ -117,7 +115,7 @@ module Conjure
|
|
117
115
|
|
118
116
|
def run(command = "")
|
119
117
|
unless running_container
|
120
|
-
|
118
|
+
Log.info "[docker] Starting #{@label}"
|
121
119
|
run_options = host_volume_options(@host_volumes)
|
122
120
|
run_options += port_options(@ports)
|
123
121
|
command = shell_command command if command != ""
|
@@ -127,7 +125,7 @@ module Conjure
|
|
127
125
|
raise "Docker: #{@label} daemon exited with: #{output}"
|
128
126
|
end
|
129
127
|
end
|
130
|
-
|
128
|
+
Log.info "[docker] #{@label} is running at #{running_container.ip_address}"
|
131
129
|
running_container
|
132
130
|
end
|
133
131
|
|
@@ -157,7 +155,7 @@ module Conjure
|
|
157
155
|
|
158
156
|
def build
|
159
157
|
destroy_instances
|
160
|
-
|
158
|
+
Log.info "[docker] Building #{@label} image"
|
161
159
|
raise_build_errors(@host.command "build -t #{expected_image_name} -", stdin: dockerfile)
|
162
160
|
@host.containers.destroy_all_stopped
|
163
161
|
end
|
@@ -225,7 +223,7 @@ module Conjure
|
|
225
223
|
|
226
224
|
def destroy_all(options)
|
227
225
|
while container = find(:image_name => options[:image_name]) do
|
228
|
-
|
226
|
+
Log.info "[docker] Stopping #{options[:image_name]}"
|
229
227
|
host.command "stop #{container.id}"
|
230
228
|
host.command "rm #{container.id}"
|
231
229
|
end
|
@@ -10,11 +10,11 @@ module Conjure
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def deploy
|
13
|
-
|
13
|
+
Log.info "[deploy] Deploying #{@name}:#{@branch} to #{@environment}"
|
14
14
|
unless @test
|
15
15
|
codebase.install
|
16
16
|
rails.run
|
17
|
-
|
17
|
+
Log.info "[deploy] Application deployed to #{docker.ip_address}"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -42,12 +42,12 @@ module Conjure
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def configure_database
|
45
|
-
|
45
|
+
Log.info "[ repo] Generating database.yml"
|
46
46
|
volume.write "config/database.yml", database_yml
|
47
47
|
end
|
48
48
|
|
49
49
|
def configure_logs
|
50
|
-
|
50
|
+
Log.info "[ repo] Configuring application logger"
|
51
51
|
setup = 'Rails.logger = Logger.new "#{Rails.root}/log/#{Rails.env}.log"'
|
52
52
|
volume.write "config/initializers/z_conjure_logger.rb", setup
|
53
53
|
end
|
@@ -50,7 +50,7 @@ module Conjure
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def install_gems
|
53
|
-
|
53
|
+
Log.info "[ rails] Installing gems"
|
54
54
|
base_image.command "cd #{@app_name}; bundle --deployment"
|
55
55
|
end
|
56
56
|
|
@@ -59,17 +59,17 @@ module Conjure
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def database_exists
|
62
|
-
|
62
|
+
Log.info "[ rails] Checking the database status"
|
63
63
|
base_image.command("cd #{@app_name}; bundle exec rake db:version; true").include? "Current version:"
|
64
64
|
end
|
65
65
|
|
66
66
|
def migrate_database
|
67
|
-
|
67
|
+
Log.info "[ rails] Migrating the database"
|
68
68
|
base_image.command "cd #{@app_name}; bundle exec rake db:migrate"
|
69
69
|
end
|
70
70
|
|
71
71
|
def initialize_database
|
72
|
-
|
72
|
+
Log.info "[ rails] Setting up the database"
|
73
73
|
base_image.command "cd #{@app_name}; bundle exec rake db:setup"
|
74
74
|
end
|
75
75
|
|
@@ -12,18 +12,13 @@ module Conjure
|
|
12
12
|
@options = options
|
13
13
|
end
|
14
14
|
|
15
|
-
def run(command, options = {})
|
16
|
-
|
15
|
+
def run(command, options = {}, &block)
|
16
|
+
result = nil
|
17
17
|
session.open_channel do |channel|
|
18
18
|
channel.request_pty
|
19
19
|
channel.exec command do |c, success|
|
20
20
|
raise "Failed to execute command via SSH" unless success
|
21
|
-
|
22
|
-
yield data if block_given?
|
23
|
-
stdout << data
|
24
|
-
end
|
25
|
-
channel.on_extended_data { |c, type, data| stderr << data }
|
26
|
-
channel.on_request("exit-status") { |c, data| exit_status = data.read_long }
|
21
|
+
result = Result.new(channel, &block)
|
27
22
|
end
|
28
23
|
if options[:stream_stdin]
|
29
24
|
channel.on_process do
|
@@ -36,9 +31,9 @@ module Conjure
|
|
36
31
|
else
|
37
32
|
session.loop
|
38
33
|
end
|
39
|
-
|
34
|
+
result
|
40
35
|
end
|
41
|
-
|
36
|
+
|
42
37
|
def session
|
43
38
|
session_options = {
|
44
39
|
:auth_methods => ["publickey"],
|
@@ -58,8 +53,20 @@ module Conjure
|
|
58
53
|
ensure
|
59
54
|
system "stty -raw echo"
|
60
55
|
end
|
56
|
+
|
57
|
+
class Result
|
58
|
+
attr_accessor :stdout, :stderr, :status
|
59
|
+
def initialize(channel)
|
60
|
+
@stdout, @stderr = "", ""
|
61
|
+
channel.on_data do |c, data|
|
62
|
+
yield data if block_given?
|
63
|
+
@stdout << data
|
64
|
+
end
|
65
|
+
channel.on_extended_data { |c, type, data| @stderr << data }
|
66
|
+
channel.on_request("exit-status") { |c, data| @status = data.read_long }
|
67
|
+
end
|
68
|
+
end
|
61
69
|
end
|
62
70
|
|
63
|
-
Result = Struct.new(:stdout, :stderr, :status)
|
64
71
|
end
|
65
72
|
end
|
@@ -19,12 +19,12 @@ module Conjure
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def checkout_code
|
22
|
-
|
22
|
+
Log.info "[ repo] Checking out code from git"
|
23
23
|
git_shell.command "git clone -b #{@branch} #{@origin_url} #{code_path}"
|
24
24
|
end
|
25
25
|
|
26
26
|
def fetch_code_updates
|
27
|
-
|
27
|
+
Log.info "[ repo] Fetching code updates from git"
|
28
28
|
git_shell.command "cd #{code_path}; git reset --hard; git checkout #{@branch}; git pull"
|
29
29
|
end
|
30
30
|
|
data/lib/conjure/version.rb
CHANGED
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.5
|
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-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/conjure/service/docker_host.rb
|
114
114
|
- lib/conjure/service/docker_shell.rb
|
115
115
|
- lib/conjure/service/database.rb
|
116
|
+
- lib/conjure/log.rb
|
116
117
|
- lib/conjure/config.rb
|
117
118
|
- lib/conjure/version.rb
|
118
119
|
- lib/conjure/command.rb
|