build(Makefile): Rewrite target structured names.

This commit is contained in:
Stephan Barth 2024-11-01 07:05:29 +01:00
parent 4bbab689cf
commit efda54ad89

211
Makefile
View File

@ -7,17 +7,19 @@ export CONTAINER_COMMAND ?= podman
export CONTAINER_BGRUN ?= $(CONTAINER_COMMAND) run -dit --network=host --replace
export CONTAINER_FGRUN ?= $(CONTAINER_COMMAND) run -it --network=host --replace
export CONTAINER_NAME ?= $(FRADRIVE_SERVICE)
#export CONTAINER_NAME ?= $(FRADRIVE_SERVICE)
export ENTRYPOINT
export IN_CONTAINER ?= false
export IN_CI ?= false
export SINGLETON
export WATCH
export UNIWORXDB_OPTS ?= -cf
export CONTAINER_ID
export FRADRIVE_SERVICE
export SERVICE_VARIANT
export DEV_PORT_HTTP
export DEV_PORT_HTTPS
@ -89,12 +91,65 @@ release:
.PHONY: %-shell
# HELP: launch shell (bash) inside a currently running container
%-shell: --%-shell;
--%-shell:
--shell:
$(CONTAINER_COMMAND) exec -it $(EXEC_OPTS) fradrive.$(CURR_DEV).$* $(if $(ENTRYPOINT),$(ENTRYPOINT),/bin/bash)
compile-%: --%-compile;
##### GENERAL TARGETS #####
###########################
##############################################
##### SERVICE DEPENDENCIES AND VARIABLES #####
--frontend-%: FRADRIVE_SERVICE=frontend
--frontend-%: SERVICE_VARIANT=frontend
--frontend-%: SINGLETON = false
--frontend-%: WATCH = false
--frontend-%:
# TODO --containerized-% is not yet working; comment this in again as soon as it does
# $(MAKE) -- --containerized-static --containerized-well-known
$(MAKE) -- --$*
--backend-%: FRADRIVE_SERVICE=backend
--backend-%: SERVICE_VARIANT=backend
--backend-%: BASE_PORTS = "DEV_PORT_HTTP=3000" "DEV_PORT_HTTPS=3443"
--backend-%: SINGLETON = false
--backend-%:
$(MAKE) -- --frontend-compile
$(MAKE) -- --$*
--hoogle-%: FRADRIVE_SERVICE=backend
--hoogle-%: SERVICE_VARIANT=hoogle
--hoogle-%: BASE_PORTS = "HOOGLE_PORT=8081"
--hoogle-%: SINGLETON = true
--hoogle-%:
$(MAKE) -- --$*
# --uniworxdb was --db in old versions
--uniworxdb-%: FRADRIVE_SERVICE=backend
--uniworxdb-%: SERVICE_VARIANT=uniworxdb
--uniworxdb-%:
$(MAKE) -- --$*
--minio-%: FRADRIVE_SERVICE=minio
--minio-%: SERVICE_VARIANT=minio
--minio-%:
$(MAKE) -- --$*
--memcached-%: FRADRIVE_SERVICE=memcached
--memcached-%: SERVICE_VARIANT=memcached
--memcached-%:
$(MAKE) -- --$*
# --postgres was --database in old versions
--postgres-%: BASE_PORTS = "PGPORT=5432"
--postgres-%: SINGLETON = true
--postgres-%:
$(MAKE) -- --$*
##### SERVICE DEPENDENCIES AND VARIABLES #####
##############################################
############################################
##### UNIFIED FRONTEND/BACKEND TARGETS #####
@ -109,7 +164,7 @@ compile:
$(MAKE) compile-frontend
$(MAKE) compile-backend
compile-%: --develop
--compile-%: --checkvarsset --develop --%
.PHONY: lint
# HELP: lint frontend and backend
@ -122,31 +177,53 @@ test: start-database test-frontend test-backend i18n-check;
##### UNIFIED FRONTEND/BACKEND TARGETS #####
############################################
--checkvarsset:
@:
ifndef ($(FRADRIVE_SERVICE))
>&2 echo "Variable FRADRIVE_SERVICE is not set; this hints to an internal error in the Makefile unless you have manually requested a '--'-target"
exit 1
endif
ifndef ($(SERVICE_VARIANT))
>&2 echo "Variable SERVICE_VARIANT is not set; this hints to an internal error in the Makefile unless you have manually requested a '--'-target"
exit 1
endif
ifndef ($(DEVELOP))
>&2 echo "Variable DEVELOP is not set; this hints to an internal error in the Makefile unless you have manually requested a '--'-target"
exit 1
endif
ifndef ($(CONTAINER_FILE))
>&2 echo "Variable CONTAINER_FILE is not set; this hints to an internal error in the Makefile unless you have manually requested a '--'-target"
exit 1
endif
############################
##### FRONTEND TARGETS #####
.PHONY: %-frontend
%-frontend: FRADRIVE_SERVICE=frontend
%-frontend: --image-build --containerized---%-frontend;
#--frontend-%: --image-build --containerized---%-frontend;
--%-frontend: --containerized-static-frontend --containerized-well-known-frontend
#--%-frontend: --containerized-static-frontend --containerized-well-known-frontend
--start-frontend: static
#--frontend-start: static
# npm run start
ifeq ($(SERVICE_VARIANT), frontend)
--start: --checkvarsset
npm run start
# HELP(compile-frontend): compile frontend
--compile-frontend: static well-known;
--compile: static well-known --checkvarsset;
# HELP(lint-frontend): lint frontend
--lint-frontend: eslint.config.js
--lint: eslint.config.js --checkvarsset
npx -- eslint frontend/src $(FIX)
@echo Hooray! There are no hints.
# HELP(test-frontend): test frontend
--test-frontend: karma.conf.cjs
--test: karma.conf.cjs --checkvarsset
@echo Karma frontend tests are currently broken after npm update and have therefor been temporarily disabled.
# npx -- karma start --conf karma.conf.cjs $(WATCH)
endif
node_modules: package.json package-lock.json
npm ci --cache .npm --prefer-offline
@ -157,7 +234,7 @@ package-lock.json: package.json
assets: assets/favicons assets/icons;
assets/favicons:
./utils/faviconize.pl assets/favicon.svg long assets/favicons
assets/icons: node_modules utils/rename-fa.json
assets/icons: node_modules assets/icons-src/fontawesome.json
./utils/renamer.pl node_modules/@fortawesome/fontawesome-free/svgs/solid assets/icons-src/fontawesome.json assets/icons/fradrive
./utils/renamer.pl node_modules/@fortawesome/fontawesome-free/svgs/regular assets/icons-src/fontawesome.json assets/icons/fradrive
cp assets/icons-src/*.svg assets/icons/fradrive
@ -172,42 +249,43 @@ well-known: static;
###########################
##### BACKEND TARGETS #####
.PHONY: %-backend
%-backend: FRADRIVE_SERVICE=backend
%-backend: --image-build --containerized---%-backend;
--start-backend:
ifeq ($(SERVICE_VARIANT), backend)
--start: --checkvarsset
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=//'`; \
stack --work-dir=.stack-work-run $(--DEVELOPMENT) exec -- yesod devel -p "$${DEV_PORT_HTTP}" -q "$${DEV_PORT_HTTPS}"
--start-hoogle-backend:
endif
ifeq ($(SERVICE_VARIANT), hoogle)
--start:
HOOGLE_PORT=`cat $(CONTAINER_FILE) | grep 'HOOGLE_PORT=' | sed 's/HOOGLE_PORT=//'` ; \
echo "${HOOGLE_PORT}" ; \
stack --work-dir=.stack-work-doc hoogle -- server --local --port $${HOOGLE_PORT}
endif
# HELP(compile-backend): compile backend
--compile-backend:
ifeq ($(SERVICE_VARIANT), backend)
--compile: --checkvarsset
stack build --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only $(--DEVELOPMENT) --local-bin-path $$(pwd)/bin
# HELP(lint-backend): lint backend
--lint-backend:
--lint: --checkvarsset
stack build --test --fast --work-dir=.stack-work-test --flag uniworx:library-only $(--DEVELOPMENT) uniworx:test:hlint
# HELP(test-backend): test backend
--test-backend:
--test: --checkvarsset
stack build --test --coverage --fast --work-dir=.stack-work-test --flag uniworx:library-only $(--DEVELOPMENT)
endif
# TODO: better name
.PHONY: db
# HELP: clear and fill database. requires running postgres
db: FRADRIVE_SERVICE=backend
db: CONTAINER_NAME=uniworxdb
db: compile-frontend --image-build --containerized---db;
# HELP(uniworxdb): clear and fill database. requires running postgres
uniworxdb: --frontend-compile --backend-imagebuild-containerized-uniworxdb-start;
# TODO (db-m-$MIGRATION-backend): apply migration (see src/Model/Migration/Definition.hs for list of available migrations)
--db-backend: .stack --compile-backend
ifeq ($(SERVICE_VARIANT), uniworxdb)
--start: .stack
SERVER_SESSION_ACID_FALLBACK=${SERVER_SESSION_ACID_FALLBACK:-true} ; \
AVSPASS=${AVSPASS:-nopasswordset} ; \
stack $(--DEVELOPMENT) exec uniworxdb -- $(UNIWORXDB_OPTS)
endif
.PHONY: .stack
.stack:
@ -226,13 +304,13 @@ db: compile-frontend --image-build --containerized---db;
############################
##### DATABASE TARGETS #####
--containerized---db: CONTAINER_NAME=uniworxdb
--containerized---db: --containerized-db-backend;
--containerized-%-database: FRADRIVE_SERVICE=database
--containerized-%-database: CONTAINER_NAME=database
--containerized-%-database: docker/database/initdb.sh docker/database/pg_hba.conf docker/database/postgresql.conf docker/database/schema.sql --image-build
$(MAKE) -- --image-run-$*-database
ifeq ($(SERVICE_VARIANT), postgres)
--containerized-%: docker/database/initdb.sh docker/database/pg_hba.conf docker/database/postgresql.conf docker/database/schema.sql --image-build
$(MAKE) -- --imagerun-$*
else
--containerized-%:
$(MAKE) -- --imagerun-$*
endif
.PHONY: psql
# HELP: enter psql (postgresql) cli inside a currently running database container
@ -247,38 +325,42 @@ psql: --database-shell;
#############################
##### CONTAINER TARGETS #####
--containerized-%-frontend: FRADRIVE_SERVICE=frontend
--containerized-%-frontend: CONTAINER_NAME=frontend
--containerized-%-frontend: --image-build
$(MAKE) -- --image-run-$*-frontend
--containerized-%-backend: FRADRIVE_SERVICE=backend
--containerized-%-backend: CONTAINER_NAME?=backend
--containerized-%-backend: --image-build
$(MAKE) -- --image-run-$*-backend
--containerized-%-hoogle: FRADRIVE_SERVICE=backend
--containerized-%-hoogle: CONTAINER_NAME=hoogle
--containerized-%-hoogle: --image-build
$(MAKE) -- --image-run-$*-hoogle-backend
#--containerized-%-frontend: FRADRIVE_SERVICE=frontend
#--containerized-%-frontend: SERVICE_VARIANT=frontend
#--containerized-%-frontend: --image-build
# $(MAKE) -- --image-run-$*-frontend
#
#--containerized-%-backend: FRADRIVE_SERVICE=backend
#--containerized-%-backend: SERVICE_VARIANT?=backend
#--containerized-%-backend: --image-build
# $(MAKE) -- --image-run-$*-backend
#--containerized-%-hoogle: FRADRIVE_SERVICE=backend
#--containerized-%-hoogle: SERVICE_VARIANT=hoogle
#--containerized-%-hoogle: --image-build
# $(MAKE) -- --image-run-$*-hoogle-backend
# --containerized-%-minio: FRADRIVE_SERVICE=minio
# --containerized-%-minio: --image-build
# $(MAKE) -- --image-run-$*-minio
--containerized---start-minio:
ifeq ($(SERVICE_VARIANT), minio)
--containerized-start:
UPLOAD_S3_PORT=`cat $(CONTAINER_FILE) | grep 'UPLOAD_S3_PORT=' | sed 's/UPLOAD_S3_PORT=//'`; \
MINIO_DIR=`mktemp` ; \
./utils/watchcontainerrun.sh "$(CONTAINER_COMMAND)" "$(CONTAINER_FILE)" "" "rm -rf $${MINIO_DIR}" & \
CONTAINER_ID=`$(CONTAINER_BGRUN) --name fradrive.$(CURR_DEV).minio $(MINIO_IMAGE) -- server $${MINIO_DIR} --address=:$${UPLOAD_S3_PORT}` ; \
printf "CONTAINER_ID=$${CONTAINER_ID}\nUPLOAD_S3_PORT=$${UPLOAD_S3_PORT}\nMINIO_DIR=$${MINIO_DIR}" >> $(CONTAINER_FILE)
endif
# --containerized-%-memcached: FRADRIVE_SERVICE=memcached
# --containerized-%-memcached: --image-build
# $(MAKE) -- --image-run-$*-memcached
--containerized---start-memcached:
ifeq ($(SERVICE_VARIANT), memcached)
--containerized-start:
MEMCACHED_PORT=`cat $(CONTAINER_FILE) | grep 'MEMCACHED_PORT=' | sed 's/MEMCACHED_PORT=//'`; \
./utils/watchcontainerrun.sh "$(CONTAINER_COMMAND)" "$(CONTAINER_FILE)" & \
CONTAINER_ID=`$(CONTAINER_BGRUN) --name fradrive.$(CURR_DEV).memcached $(MEMCACHED_IMAGE) --port=$${MEMCACHED_PORT}` ; \
printf "CONTAINER_ID=$${CONTAINER_ID}\nMEMCACHED_PORT=$${MEMCACHED_PORT}" >> $(CONTAINER_FILE)
endif
.PHONY: image-rebuild
# HELP(image-rebuild-{backend,frontend,database,memcached,minio}): force-rebuild the stated docker image
@ -296,42 +378,21 @@ image-rebuild-%:
$(CONTAINER_COMMAND) build $(NO_CACHE) -v $(PWD):$${MOUNT_DIR} --env IN_CONTAINER=true --build-arg MOUNT_DIR=$${MOUNT_DIR} --build-arg PROJECT_DIR=$${PROJECT_DIR} --tag fradrive/$(FRADRIVE_SERVICE) --file $(PWD)/.Dockerfile ; \
fi
--image-run-%: CONTAINER_NAME ?= $(FRADRIVE_SERVICE)
--image-run-%: docker/$(FRADRIVE_SERVICE)/Dockerfile
--imagerun-%: --checkvarsset docker/$(FRADRIVE_SERVICE)/Dockerfile
MOUNT_DIR=/mnt/fradrive; \
if [ "$(IN_CONTAINER)" == "true" ] ; then \
$(MAKE) -- $* ; \
else \
if [ -z "$(CONTAINER_FILE)" ] ; then \
$(CONTAINER_FGRUN) -v $(PWD):$${MOUNT_DIR} --env IN_CONTAINER=true --env FRADRIVE_MAKE_TARGET=$* --env CONTAINER_FILE=$(CONTAINER_FILE) --env CONTAINER_FILE_CONTENT=$(CONTAINER_FILE_CONTENT) --env WATCH=$(WATCH) --name fradrive.$(CURR_DEV).$(CONTAINER_NAME) localhost/fradrive/$(FRADRIVE_SERVICE) ; \
$(CONTAINER_FGRUN) -v $(PWD):$${MOUNT_DIR} --env IN_CONTAINER=true --env FRADRIVE_MAKE_TARGET=$* --env CONTAINER_FILE=$(CONTAINER_FILE) --env CONTAINER_FILE_CONTENT=$(CONTAINER_FILE_CONTENT) --env WATCH=$(WATCH) --name fradrive.$(CURR_DEV).$(SERVICE_VARIANT) localhost/fradrive/$(FRADRIVE_SERVICE) ; \
else \
./utils/watchcontainerrun.sh "$(CONTAINER_COMMAND)" "$(CONTAINER_FILE)" & \
CONTAINER_ID=`$(CONTAINER_BGRUN) -v $(PWD):$${MOUNT_DIR} --env IN_CONTAINER=true --env FRADRIVE_MAKE_TARGET=$* --env CONTAINER_FILE=$(CONTAINER_FILE) --env CONTAINER_FILE_CONTENT=$(CONTAINER_FILE_CONTENT) --env WATCH=$(WATCH) --name fradrive.$(CURR_DEV).$(CONTAINER_NAME) localhost/fradrive/$(FRADRIVE_SERVICE)` ; \
CONTAINER_ID=`$(CONTAINER_BGRUN) -v $(PWD):$${MOUNT_DIR} --env IN_CONTAINER=true --env FRADRIVE_MAKE_TARGET=$* --env CONTAINER_FILE=$(CONTAINER_FILE) --env CONTAINER_FILE_CONTENT=$(CONTAINER_FILE_CONTENT) --env WATCH=$(WATCH) --name fradrive.$(CURR_DEV).$(SERVICE_VARIANT) localhost/fradrive/$(FRADRIVE_SERVICE)` ; \
echo "CONTAINER_ID=$${CONTAINER_ID}" >> "$(CONTAINER_FILE)"; \
fi \
fi
# TODO: move starts below to respective entries, or leave together?
start-database: BASE_PORTS = "PGPORT=5432"
start-database: SINGLETON = true
start-memcached: BASE_PORTS = "MEMCACHED_PORT=11211"
start-memcached: SINGLETON = true
start-minio: BASE_PORTS = "UPLOAD_S3_PORT=9000"
start-minio: SINGLETON = true
start-backend: BASE_PORTS = "DEV_PORT_HTTP=3000" "DEV_PORT_HTTPS=3443"
start-backend: SINGLETON = false
start-backend: compile-frontend
start-hoogle: BASE_PORTS = "HOOGLE_PORT=8081"
start-hoogle: SINGLETON = true
start-frontend: SINGLETON = false
start-frontend: WATCH = false
# HELP(start-database): start postgres server
# HELP(start-memcached): start memcached server
@ -441,4 +502,4 @@ i18n-check: --image-run---i18n-check
flock -en $@ true
.PHONY: --%
.SUFFIXES: # Delete all default suffixes
.SUFFIXES: # Delete all default suffixes