Compare commits

...

2 commits

Author SHA1 Message Date
Glenn Y. Rolland e6a6da7a78 feat: add more targets to makefile (ex: install)
Some checks failed
continuous-integration/drone/push Build is failing
2024-02-15 18:56:31 +01:00
Glenn Y. Rolland 1e63606f72 feat: Add support for --no-cache option 2024-02-15 18:56:15 +01:00
4 changed files with 57 additions and 15 deletions

View file

@ -1,6 +1,37 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2023 Glenn Y. Rolland <glenux@glenux.net>
# Copyright © 2023 Glenn Y. Rolland <glenux@glenux.net>
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)
ifeq ($(CURRENT_UID),0)
PREFIX=/usr
else
PREFIX=$(HOME)/.local
endif
all: build
prepare:
shards install
build:
shards build --error-trace
shards build --error-trace -Dpreview_mt
@echo SUCCESS
watch:
watchexec --restart --delay-run 3 -c -e cr make build
spec: test
test:
crystal spec --error-trace
install:
install \
-m 755 \
bin/docmachine \
$(PREFIX)/bin
.PHONY: spec test build all prepare install

View file

@ -20,6 +20,10 @@ module DocMachine::Build
config.action = action
end
opts.on("--no-cache", "Disable cache") do |_|
config.enable_cache = false
end
opts.on("-d", "--data-dir DIR", "Content directory") do |dir|
config.data_dir = dir
end
@ -29,7 +33,7 @@ module DocMachine::Build
end
opts.on("-m", "--multiple", "Allow multiple instances per dir" ) do |port|
config.multiple_instances = true
config.enable_multiple = true
end
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do

View file

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

View file

@ -29,7 +29,7 @@ module DocMachine::Build
Log.info { "action = #{@config.action}" }
self._pull_image()
self._avoid_duplicates() unless @config.multiple_instances
self._avoid_duplicates() unless @config.enable_multiple
end
private def _find_port(port_base)
@ -68,6 +68,7 @@ module DocMachine::Build
else Path[ENV["HOME"], ".cache", "docmachine"]
end
## Build cache if it doesnt exist
data_cache_file = data_cache_dir / "image.tar"
Log.info { "Checking cache #{data_cache_file}..." }
if ! File.exists? data_cache_file.to_s
@ -91,18 +92,23 @@ module DocMachine::Build
Log.info { "Cache already exist. Skipping." }
end
Log.info { "Loading #{@docker_image} image from cache..." }
docker_image_loaded = false
status = Process.run(
"docker",
["image", "load", "-i", data_cache_file.to_s],
output: STDOUT
)
if status.success?
Log.info { "done" }
if @config.enable_cache
Log.info { "Loading #{@docker_image} image from cache..." }
docker_image_loaded = false
status = Process.run(
"docker",
["image", "load", "-i", data_cache_file.to_s],
output: STDOUT
)
if status.success?
Log.info { "done" }
else
Log.error { "Unable to load cache image" }
exit 1
end
else
Log.error { "Unable to load cache image" }
exit 1
Log.info { "Loading #{@docker_image} image from local registry..." }
# FIXME: check that local image exists
end
end