develop #3

Merged
glenux merged 35 commits from develop into master 2024-06-02 07:08:41 +00:00
3 changed files with 12 additions and 4 deletions
Showing only changes of commit 9d13f8216f - Show all commits

View file

@ -28,6 +28,10 @@ module DocMachine::Build
config.port = port.to_i
end
opts.on("-m", "--multiple", "Allow multiple instances per dir" ) do |port|
config.multiple_instances = true
end
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do
config.enable_tty = true
end

View file

@ -5,6 +5,7 @@ module DocMachine::Build
property action : String = "watch"
property enable_tty : Bool = false
property port : Int32 = 5100
property multiple_instances : Bool = false
def initialize(@parent : DocMachine::Config)
end

View file

@ -11,7 +11,8 @@ module DocMachine::Build
Log = DocMachine::Build::Log.for("run")
def initialize(@config : DocMachine::Build::Config)
@basehash = Digest::SHA256.hexdigest(@config.data_dir)[0..6]
data = "#{@config.data_dir}:#{@config.port}"
@basehash = Digest::SHA256.hexdigest(data)[0..6]
@docker_name = "docmachine-#{@basehash}"
@docker_image = "glenux/docmachine:latest"
@docker_opts = [] of String
@ -27,8 +28,8 @@ module DocMachine::Build
Log.info { "docker_image = #{@docker_image}" }
Log.info { "action = #{@config.action}" }
self._avoid_duplicates()
self._pull_image()
self._avoid_duplicates() unless @config.multiple_instances
end
private def _find_port(port_base)
@ -48,13 +49,15 @@ module DocMachine::Build
end
private def _avoid_duplicates
Log.info { "Multiple Instances: stopping duplicate containers (for #{@docker_name})" }
docker_cid = %x{docker ps -f "name=#{@docker_name}" -q}.strip
Log.info { "docker_name: #{@docker_name}" }
Log.info { "docker_cid: #{docker_cid}" }
Log.info { "Multiple Instances: docker_name: #{@docker_name}" }
Log.info { "Multiple Instances: docker_cid: #{docker_cid || "-"}" }
if !docker_cid.empty?
Process.run("docker", ["kill", @docker_name])
Process.run("docker", ["rm", @docker_name])
end
end