feat: Add support for --no-cache option
This commit is contained in:
parent
9d13f8216f
commit
1e63606f72
3 changed files with 25 additions and 14 deletions
|
@ -20,6 +20,10 @@ module DocMachine::Build
|
||||||
config.action = action
|
config.action = action
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("--no-cache", "Disable cache") do |_|
|
||||||
|
config.enable_cache = false
|
||||||
|
end
|
||||||
|
|
||||||
opts.on("-d", "--data-dir DIR", "Content directory") do |dir|
|
opts.on("-d", "--data-dir DIR", "Content directory") do |dir|
|
||||||
config.data_dir = dir
|
config.data_dir = dir
|
||||||
end
|
end
|
||||||
|
@ -29,7 +33,7 @@ module DocMachine::Build
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on("-m", "--multiple", "Allow multiple instances per dir" ) do |port|
|
opts.on("-m", "--multiple", "Allow multiple instances per dir" ) do |port|
|
||||||
config.multiple_instances = true
|
config.enable_multiple = true
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do
|
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do
|
||||||
|
|
|
@ -5,7 +5,8 @@ module DocMachine::Build
|
||||||
property action : String = "watch"
|
property action : String = "watch"
|
||||||
property enable_tty : Bool = false
|
property enable_tty : Bool = false
|
||||||
property port : Int32 = 5100
|
property port : Int32 = 5100
|
||||||
property multiple_instances : Bool = false
|
property enable_multiple : Bool = false
|
||||||
|
property enable_cache : Bool = false
|
||||||
|
|
||||||
def initialize(@parent : DocMachine::Config)
|
def initialize(@parent : DocMachine::Config)
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@ module DocMachine::Build
|
||||||
Log.info { "action = #{@config.action}" }
|
Log.info { "action = #{@config.action}" }
|
||||||
|
|
||||||
self._pull_image()
|
self._pull_image()
|
||||||
self._avoid_duplicates() unless @config.multiple_instances
|
self._avoid_duplicates() unless @config.enable_multiple
|
||||||
end
|
end
|
||||||
|
|
||||||
private def _find_port(port_base)
|
private def _find_port(port_base)
|
||||||
|
@ -68,6 +68,7 @@ module DocMachine::Build
|
||||||
else Path[ENV["HOME"], ".cache", "docmachine"]
|
else Path[ENV["HOME"], ".cache", "docmachine"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
## Build cache if it doesnt exist
|
||||||
data_cache_file = data_cache_dir / "image.tar"
|
data_cache_file = data_cache_dir / "image.tar"
|
||||||
Log.info { "Checking cache #{data_cache_file}..." }
|
Log.info { "Checking cache #{data_cache_file}..." }
|
||||||
if ! File.exists? data_cache_file.to_s
|
if ! File.exists? data_cache_file.to_s
|
||||||
|
@ -91,18 +92,23 @@ module DocMachine::Build
|
||||||
Log.info { "Cache already exist. Skipping." }
|
Log.info { "Cache already exist. Skipping." }
|
||||||
end
|
end
|
||||||
|
|
||||||
Log.info { "Loading #{@docker_image} image from cache..." }
|
if @config.enable_cache
|
||||||
docker_image_loaded = false
|
Log.info { "Loading #{@docker_image} image from cache..." }
|
||||||
status = Process.run(
|
docker_image_loaded = false
|
||||||
"docker",
|
status = Process.run(
|
||||||
["image", "load", "-i", data_cache_file.to_s],
|
"docker",
|
||||||
output: STDOUT
|
["image", "load", "-i", data_cache_file.to_s],
|
||||||
)
|
output: STDOUT
|
||||||
if status.success?
|
)
|
||||||
Log.info { "done" }
|
if status.success?
|
||||||
|
Log.info { "done" }
|
||||||
|
else
|
||||||
|
Log.error { "Unable to load cache image" }
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Log.error { "Unable to load cache image" }
|
Log.info { "Loading #{@docker_image} image from local registry..." }
|
||||||
exit 1
|
# FIXME: check that local image exists
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue