From 80e4c45a66be9106a916029fdc9a86cee604869e Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Fri, 11 Oct 2024 13:00:22 +0200 Subject: [PATCH] build(Makefile): introduce log targets, use separate stack-work-dirs for better caching --- Makefile | 41 ++++++++++++++++++++----------------- hoogle.sh | 4 ++-- start.sh | 4 ++-- utils/watchrun-container.sh | 5 ----- utils/watchrun.sh | 6 +++++- 5 files changed, 31 insertions(+), 29 deletions(-) delete mode 100755 utils/watchrun-container.sh diff --git a/Makefile b/Makefile index 5f40064c8..4382ae0e5 100644 --- a/Makefile +++ b/Makefile @@ -49,13 +49,12 @@ help: utils/makehelp.pl Makefile ; \ fi -.PHONY: clean +.PHONY: clean% # HELP: remove all compilation results in the directory but leave containers and images unharmed clean: rm -rf node_modules .npm .cache assets/icons assets/favicons static well-known rm -rf .stack .stack-work .stack-work-build .stack-work-run .stack-work-test .stack-work-doc - rm -rf bin/ .Dockerfile .dev-port-http .dev-port-https -.PHONY: clean-all + rm -rf bin/ .Dockerfile develop/ # HELP: like clean but with container and image prune clean-all: clean $(CONTAINER_COMMAND) system prune --all --force --volumes @@ -203,15 +202,15 @@ serve-backend: # HELP(compile-backend): compile backend --compile-backend: - stack build --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only --local-bin-path $$(pwd)/bin $(stackopts) + stack build --fast --work-dir .stack-work-build --profile --library-profiling --executable-profiling --flag uniworx:-library-only --local-bin-path $$(pwd)/bin $(stackopts) # HELP(lint-backend): lint backend --lint-backend: - stack build --test --fast --flag uniworx:library-only uniworx:test:hlint $(stackopts) + stack build --test --fast --work-dir .stack-work-test --flag uniworx:library-only uniworx:test:hlint $(stackopts) # HELP(test-backend): test backend --test-backend: - stack build --test --coverage --fast --flag uniworx:library-only $(stackopts) + stack build --test --coverage --fast --workdir .stack-work-test --flag uniworx:library-only $(stackopts) # HELP(db-cf-backend): clear and fill database. requires running postgres # TODO (db-m-$MIGRATION-backend): apply migration (see src/Model/Migration/Definition.hs for list of available migrations) @@ -346,8 +345,10 @@ start-minio: SINGLETON = true start-backend: BASE_PORTS = "DEV_PORT_HTTP=3000" "DEV_PORT_HTTPS=3443" start-backend: SINGLETON = false +start-hoogle: BASE_PORT = "HOOGLE_PORT=8081" start-frontend: SINGLETON = false +start-frontend: WATCH = true start-%: FRADRIVE_SERVICE = % start-%: PORTS = $(foreach PORT,$(BASE_PORTS),$(shell utils/next_free_port.pl $(PORT))) @@ -359,10 +360,9 @@ start-%: --ensure-develop CONTAINER_FILE=$(DEVELOP)/$* ; \ else \ DEVDIR=$(DEVELOP)/$*; \ - mkdir -p $${DEVDIR}; \ I=`ls $${DEVDIR} | sort -n | tail -n1`; \ echo "$${I}"; \ - CONTAINER_FILE=$${DEVDIR}/$$(($${I}+1)); \ + CONTAINER_FILE=$${DEVDIR}-$$(($${I}+1)); \ fi ; \ echo "$(PORTS)" | sed 's/ /\n/g' > $${CONTAINER_FILE} ; \ $(MAKE) -- --containerized---start-$* CONTAINER_FILE=$${CONTAINER_FILE} @@ -370,7 +370,10 @@ start-%: --ensure-develop --start-backend: start.sh DEV_PORT_HTTP=`cat $(CONTAINER_FILE) | grep 'DEV_PORT_HTTP=' | sed 's/DEV_PORT_HTTP=//'`; \ DEV_PORT_HTTPS=`cat $(CONTAINER_FILE) | grep 'DEV_PORT_HTTPS=' | sed 's/DEV_PORT_HTTPS=//'`; \ - ./utils/watchrun-container.sh "$(CONTAINER_FILE)" ./start.sh + ./utils/watchrun.sh "$(CONTAINER_FILE)" ./start.sh +--start-hoogle: hoogle.sh + HOOGLE_PORT=`cat $(CONTAINER_FILE) | grep 'HOOGLE_PORT=' | sed 's/HOOGLE_PORT=//'` ; \ + ./utils/watchrun.sh "$(CONTAINER_FILE)" ./hoogle.sh --containerized---start-database: FRADRIVE_SERVICE=database # port forwarding is disabled in --network=host mode; nevertheless it is stated here for documentation reasons @@ -392,17 +395,17 @@ start-%: --ensure-develop # TODO: find way to stop a single container, e.g. by removing the file .PHONY: stop-% stop-%: --stop-% - $(MAKE) stop-container CONTAINER_FILE=TODO -.PHONY: --stop-minio ---stop-minio: - MINIO_DIR=`cat $(DEVELOP)/minio` - rm -rf $${MINIO_DIR} - -stop-container-by-id: - podman stop $(CONTAINER_ID) + rm -rf $(DEVELOP)/$* stop-container-by-file: - CONTAINER_ID=`grep 'CONTAINER_ID=' $(CONTAINER_FILE) | sed 's/CONTAINER_ID=//'` ; \ - $(MAKE) stop-container-by-id CONTAINER_ID=$${CONTAINER_ID} + rm $(CONTAINER_FILE) +stop-container-by-id: + $(CONTAINER_COMMAND) stop $(CONTAINER_ID) +# CONTAINER_ID=`grep 'CONTAINER_ID=' $(CONTAINER_FILE) | sed 's/CONTAINER_ID=//'` ; \ +# $(MAKE) stop-container-by-id CONTAINER_ID=$${CONTAINER_ID} + +.PHONY: log-% +log-%: + $(CONTAINER_COMMAND) logs `cat develop/$(CURRENT_DEVELOP)/$* | grep CONTAINER_ID= | sed 's/^CONTAINER_ID=//'` ##### CONTAINER TARGETS ##### ############################# diff --git a/hoogle.sh b/hoogle.sh index 1dff74ea2..3d1c10408 100755 --- a/hoogle.sh +++ b/hoogle.sh @@ -2,7 +2,7 @@ set -e -# SPDX-FileCopyrightText: 2022 Gregor Kleen +# SPDX-FileCopyrightText: 2022-2024 Sarah Vaupel , Gregor Kleen # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -19,4 +19,4 @@ if [[ -d .stack-work-doc ]]; then trap move-back EXIT fi -stack hoogle -- ${@:-server --local --port $((${PORT_OFFSET:-$(((16#$(echo \"fradrive $(whoami)\" | sha256sum | head -c 16)) % 1000))} + 8081))} +stack hoogle -- ${@:-server --local --work-dir .stack-work-doc --port $HOOGLE_PORT} diff --git a/start.sh b/start.sh index 223bdfe0b..528a39c49 100755 --- a/start.sh +++ b/start.sh @@ -38,10 +38,10 @@ unset HOST if ! [ -z "$(which yesod)" ] then - yesod devel -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@ + yesod devel --work-dir .stack-work-run -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@ elif ! [ -z "$(which stack)" ] then - stack exec -- yesod devel -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@ + stack exec -- yesod devel --work-dir .stack-work-run -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@ else exit 1 fi diff --git a/utils/watchrun-container.sh b/utils/watchrun-container.sh deleted file mode 100755 index 9c31324ce..000000000 --- a/utils/watchrun-container.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -STOPSCRIPT="make stop-container-by-id CONTAINFER_FILE=${CONTAINER_FILE} ; $3" - -./utils/watchrun.sh "$1" "$2" \ No newline at end of file diff --git a/utils/watchrun.sh b/utils/watchrun.sh index 343c92149..338982577 100755 --- a/utils/watchrun.sh +++ b/utils/watchrun.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +#UTILPATH=`echo "$0" | sed 's/\/[^\/]+$//'` +UTILPATH=${0%/*} + FILENAME=$1 STARTSCRIPT=$2 STOPSCRIPT=$3 @@ -8,6 +11,7 @@ touch "$FILENAME" ( while [ -e "$FILENAME" ] ; do + sleep 1 inotifywait -e ATTRIB -t 10 "$FILENAME" > /dev/null 2&>/dev/null done @@ -16,4 +20,4 @@ $STOPSCRIPT kill `cat /tmp/pidwrapper` ) & -/mnt/fradrive/utils/runwrapper.sh "$STARTSCRIPT" +$UTILPATH/runwrapper.sh "$STARTSCRIPT"