Fix bug on deployment + add colors
This commit is contained in:
parent
2d2c872c3d
commit
418330c4df
1 changed files with 21 additions and 23 deletions
|
@ -3,6 +3,8 @@ require "option_parser"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
require "colorize"
|
require "colorize"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Pushokku
|
class Pushokku
|
||||||
alias Options = {
|
alias Options = {
|
||||||
config_file: String,
|
config_file: String,
|
||||||
|
@ -49,6 +51,7 @@ class Pushokku
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_config(config_file : String) : Config
|
def load_config(config_file : String) : Config
|
||||||
|
puts "Loading configuration...".colorize(:yellow)
|
||||||
if ! File.exists? config_file
|
if ! File.exists? config_file
|
||||||
STDERR.puts "ERROR: Unable to read configuration file '#{config_file}'"
|
STDERR.puts "ERROR: Unable to read configuration file '#{config_file}'"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -73,6 +76,7 @@ class Pushokku
|
||||||
Process.run "docker", ["tag", image, tag_name_version]
|
Process.run "docker", ["tag", image, tag_name_version]
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
|
app: app,
|
||||||
version: version,
|
version: version,
|
||||||
tag_name_version: tag_name_version
|
tag_name_version: tag_name_version
|
||||||
}
|
}
|
||||||
|
@ -86,35 +90,29 @@ class Pushokku
|
||||||
# | gzip \
|
# | gzip \
|
||||||
# | ssh "$HOST_REMOTE" "gunzip | docker load"
|
# | ssh "$HOST_REMOTE" "gunzip | docker load"
|
||||||
|
|
||||||
|
|
||||||
pipe1_reader, pipe1_writer = IO.pipe(true)
|
pipe1_reader, pipe1_writer = IO.pipe(true)
|
||||||
pipe2_reader, pipe2_writer = IO.pipe(true)
|
pipe2_reader, pipe2_writer = IO.pipe(true)
|
||||||
|
|
||||||
p3_out = IO::Memory.new
|
p3_out = IO::Memory.new
|
||||||
p3_err = IO::Memory.new
|
|
||||||
puts "Pushing image...".colorize(:yellow)
|
puts "Pushing image...".colorize(:yellow)
|
||||||
p3 = Process.new "ssh", [host, "gunzip | docker load"],
|
p3 = Process.new "ssh", [host, "gunzip | docker load"],
|
||||||
input: pipe2_reader, output: p3_out, error: p3_err
|
input: pipe2_reader, output: p3_out, error: STDERR
|
||||||
|
|
||||||
p2_err = IO::Memory.new
|
|
||||||
p2 = Process.new "gzip",
|
p2 = Process.new "gzip",
|
||||||
input: pipe1_reader,
|
input: pipe1_reader,
|
||||||
output: pipe2_writer,
|
output: pipe2_writer,
|
||||||
error: p2_err
|
error: STDERR
|
||||||
|
|
||||||
p1_err = IO::Memory.new
|
|
||||||
p1 = Process.new "docker", ["save", tag_name_version],
|
p1 = Process.new "docker", ["save", tag_name_version],
|
||||||
output: pipe1_writer,
|
output: pipe1_writer,
|
||||||
error: p1_err
|
error: STDERR
|
||||||
|
|
||||||
status = p1.wait
|
status = p1.wait
|
||||||
pipe1_writer.close
|
pipe1_writer.close
|
||||||
if status.success?
|
if status.success?
|
||||||
puts "Docker image successfully exported"
|
puts "-----> Docker image successfully exported"
|
||||||
else
|
else
|
||||||
STDERR.puts "Error when exporting docker image!"
|
STDERR.puts "Error (code #{status.exit_status}) when exporting docker image!"
|
||||||
STDERR.puts "- exit status: #{status.exit_status}"
|
|
||||||
STDERR.puts "- err: #{p1_err}"
|
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,28 +120,28 @@ class Pushokku
|
||||||
pipe1_reader.close
|
pipe1_reader.close
|
||||||
pipe2_writer.close
|
pipe2_writer.close
|
||||||
if ! status.success?
|
if ! status.success?
|
||||||
STDERR.puts "Error when gzipping image!"
|
STDERR.puts "Error (code #{status.exit_status}) when gzipping image!"
|
||||||
STDERR.puts "- exit status: #{status.exit_status}"
|
|
||||||
STDERR.puts "- err: #{p2_err}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
status = p3.wait
|
status = p3.wait
|
||||||
pipe2_reader.close
|
pipe2_reader.close
|
||||||
if status.success?
|
if status.success?
|
||||||
puts "Docker image successfully imported on #{host}"
|
puts "-----> Docker image successfully imported on #{host}"
|
||||||
# puts "- out : #{p3_out}"
|
|
||||||
else
|
else
|
||||||
STDERR.puts "Error when importing docker image!"
|
STDERR.puts "Error (code #{status.exit_status}) when importing docker image!"
|
||||||
STDERR.puts "- exit status: #{status.exit_status}"
|
|
||||||
STDERR.puts "- err: #{p3_err}"
|
|
||||||
end
|
end
|
||||||
puts "Image pushed successfully!".colorize(:green)
|
puts "Image pushed successfully!".colorize(:green)
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_deploy(host, app, version)
|
def image_deploy(host, app, version)
|
||||||
puts "Deploying image...".colorize(:yellow)
|
puts "Deploying image #{app}:#{version}...".colorize(:yellow)
|
||||||
Process.run "ssh", [host, "dokku tags:deploy #{app} #{version}"]
|
status = Process.run "ssh", [host, "dokku tags:deploy #{app} #{version}"],
|
||||||
|
output: STDOUT, error: STDOUT
|
||||||
|
if status.success?
|
||||||
puts "Image deployed successfully!".colorize(:green)
|
puts "Image deployed successfully!".colorize(:green)
|
||||||
|
else
|
||||||
|
STDERR.puts "Error (code #{status.exit_status}) when deploying image!"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run(args)
|
def self.run(args)
|
||||||
|
@ -153,7 +151,7 @@ class Pushokku
|
||||||
# env_config = App.get_config(config, opts["environment"])
|
# env_config = App.get_config(config, opts["environment"])
|
||||||
image_meta = app.image_tag(opts["docker_compose_yml"], config["service"], config["app"])
|
image_meta = app.image_tag(opts["docker_compose_yml"], config["service"], config["app"])
|
||||||
app.image_push(config["host"], image_meta["tag_name_version"])
|
app.image_push(config["host"], image_meta["tag_name_version"])
|
||||||
app.image_deploy(config["host"], config["app"], image_meta["tag_name_version"])
|
app.image_deploy(config["host"], image_meta["app"], image_meta["version"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue