diff --git a/Makefile b/Makefile index a041e569d..483ec63b4 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,15 @@ -# TODO: make dockerized-% usage the default behaviour, i.e. hide undockerized targets +CONTAINER_COMMAND ?= podman +IN_CONTAINER ?= false +IN_CI ?= false + +export CONTAINER_COMMAND +export IN_CONTAINER +export IN_CI db ?= -cf -CONTAINER_RUNNER ?= podman +########################### +##### GENERAL TARGETS ##### .PHONY: help help: @@ -27,119 +34,81 @@ release: git commit -m "chore(release): ${VERSION}" git push -.PHONY: build -build: frontend-build backend-build +##### GENERAL TARGETS ##### +########################### -.PHONY: dockerized-build -dockerized-build: dockerized-frontend-build dockerized-backend-build -.PHONY: dockerized-frontend-% -dockerized-frontend-%: FRADRIVE_SERVICE=frontend -dockerized-frontend-%: --docker-build-frontend-% --docker-run-frontend-%; +############################################ +##### UNIFIED FRONTEND/BACKEND TARGETS ##### -.PHONY: dockerized-backend-% -dockerized-backend-%: FRADRIVE_SERVICE=backend -dockerized-backend-%: --docker-build-backend-% --docker-run-backend-%; - -#.PHONY: start -#start: frontend-build -# $(MAKE) --jobs=2 frontend-watch backend-start +.PHONY: compile +compile: compile-frontend compile-backend .PHONY: lint -lint: frontend-lint backend-lint +lint: lint-frontend lint-backend .PHONY: test -test: frontend-test backend-test i18n-check +test: test-frontend test-backend i18n-check -.PHONY: backend-% -backend-%: --backend-%-dev; +##### UNIFIED FRONTEND/BACKEND TARGETS ##### +############################################ -# TODO: dockerify -.PHONY: backend-%-prod # TODO deprecated in favor of bins; remove -backend-%-prod: --backend-%-prod; -# TODO: dockerify -# TODO: this creates more binaries than just bin/uniworx as side effect! Document or change behaviour? -bin/uniworx: --backend-build-prod -bin/uniworxdev: --backend-build-dev +############################ +##### FRONTEND TARGETS ##### -# TODO replace with bin/uniworxdev -.PHONY: --backend-%-dev ---backend-%-dev: stackopts=--flag uniworx:dev ---backend-%-dev: --backend-%; +.PHONY: %-frontend +%-frontend: FRADRIVE_SERVICE=frontend +%-frontend: --image-build --%-frontend; -# TODO deprecated in favor of binary targets -.PHONY: --backend-%-prod ---backend-%-prod: stackopts=--flag uniworx:-dev ---backend-%-prod: --backend-%; +.PHONY: --%-frontend +--%-frontend: node_modules well-known; -.PHONY: --backend-build ---backend-build: - stack build --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only --copy-bins --local-bin-path $$(pwd)/bin $(stackopts) - -.PHONY: --backend-lint ---backend-lint: - stack build --test --fast --flag uniworx:library-only uniworx:test:hlint $(stackopts) - -.PHONY: backend-dependencies -backend-dependencies: - stack build --fast --only-dependencies $(stackopts) - -.PHONY: --backend-test ---backend-test: - stack build --test --coverage --fast --flag uniworx:library-only $(stackopts) - -.PHONY: i18n-check -i18n-check: - ./missing-translations.sh - @echo No missing translations. - -.PHONY: database -database: .stack-work.lock bin/uniworxdb - export SERVER_SESSION_ACID_FALLBACK=$${SERVER_SESSION_ACID_FALLBACK:-true} - export AVSPASS=$${AVSPASS:-nopasswordset} - stack exec uniworxdb -- $(db) - -# TODO: same behaviour as bin/uniworx! Merge or tweak targets! -bin/uniworxdb: .stack-work.lock - stack build --fast --flag uniworx:-library-only --copy-bins\ --local-bin-path\ $$(pwd)/bin\ --flag\ uniworx:-dev - -.PHONY: frontend-% -frontend-%: node_modules well-known --frontend-%; - -.PHONY: --frontend-build ---frontend-build: +.PHONY: --compile-frontend +--compile-frontend: npx -- webpack --progress $(WATCH) .PHONY: --frontend-watch --frontend-watch: WATCH=--watch ---frontend-watch: --frontend-build +--frontend-watch: --compile-frontend; -.PHONY: --frontend-lint ---frontend-lint: eslint.config.js +.PHONY: --lint-frontend +--lint-frontend: eslint.config.js npx -- eslint frontend/src $(FIX) @echo Hooray! There are no hints. -.PHONY: --frontend-test ---frontend-test: karma.conf.cjs +.PHONY: --test-frontend +--test-frontend: karma.conf.cjs @echo Karma frontend tests are currently broken after npm update and have therefor been temporarily disabled. # npx -- karma start --conf karma.conf.cjs $(WATCH) -.PHONY: --frontend-test-watch ---frontend-test-watch: WATCH=--single-run false ---frontend-test-watch: --frontend-test +.PHONY: --test-frontend-watch +--test-frontend-watch: WATCH=--single-run false +--test-frontend-watch: --test-frontend; node_modules: package.json package-lock.json + $(MAKE) -- --image-run---node_modules +.PHONY: --node_modules +--node_modules: package.json package-lock.json npm ci --cache .npm --prefer-offline package-lock.json: package.json + $(MAKE) -- --image-run---package-lock.json +.PHONY: --package-lock.json +--package-lock.json: package.json npm install --cache .npm --prefer-offline -assets/icons: node_modules +assets: node_modules + $(MAKE) -- --image-run---assets +.PHONY: --assets/icons +--assets: node_modules ./utils/renamer.pl node_modules/@fortawesome/fontawesome-free/svgs/solid utils/rename-fa.json assets/icons/fradrive ./utils/renamer.pl node_modules/@fortawesome/fontawesome-free/svgs/regular utils/rename-fa.json assets/icons/fradrive -well-known: node_modules assets/icons well-known/.well-known +well-known: node_modules assets well-known/.well-known + $(MAKE) -- --image-run---well-known +.PHONY: --well-known +--well-known: node_modules assets well-known/.well-known npx webpack --progress # mark well-known directory as clean after successful webpack run: touch well-known/.well-known @@ -147,42 +116,107 @@ well-known: node_modules assets/icons well-known/.well-known well-known/.well-known: # no-op target -# TODO: remove, as no npmrc is needed anymore -# .npmrc: -# @# Using @echo instead of echo to avoid printing secret token to stdout -# @echo '@fortawesome:registry=https://npm.fontawesome.com/' > .npmrc -# @echo "//npm.fontawesome.com/:_authToken=$(FONTAWESOME_NPM_AUTH_TOKEN)" >> .npmrc +##### FRONTEND TARGETS ##### +############################ -%.lock: - [ -e $@ ] || touch $@ - flock -en $@ true + +########################### +##### BACKEND TARGETS ##### + +.PHONY: %-backend +%-backend: FRADRIVE_SERVICE=backend +%-backend: --image-build --%-backend-dev; + +.PHONY: %-backend-prod +%-backend-prod: FRADRIVE_SERVICE=backend +%-backend-prod: --image-build --%-backend-prod; + +.PHONY: --%-backend-dev +--%-backend-dev: FRADRIVE_SERVICE=backend +--%-backend-dev: stackopts=--flag uniworx:dev +--%-backend-dev: --image-build --%-backend; + +.PHONY: --backend-%-prod +--%-backend-prod: FRADRIVE_SERVICE=backend +--%-backend-prod: stackopts=--flag uniworx:-dev +--%-backend-prod: --image-build --%-backend; + +.PHONY: --compile-backend +--compile-backend: + stack build --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only --copy-bins --local-bin-path $$(pwd)/bin $(stackopts) + +.PHONY: --lint-backend +--lint-backend: + stack build --test --fast --flag uniworx:library-only uniworx:test:hlint $(stackopts) + +.PHONY: --test-backend +--test-backend: + stack build --test --coverage --fast --flag uniworx:library-only $(stackopts) + +# TODO: maybe deprecated +.PHONY: database +database: .stack .stack-work.lock compile-backend-prod + export SERVER_SESSION_ACID_FALLBACK=$${SERVER_SESSION_ACID_FALLBACK:-true} + export AVSPASS=$${AVSPASS:-nopasswordset} + stack exec uniworxdb -- $(db) + +.stack: stack.yaml stack.yaml.lock +.stack: + $(MAKE) -- --image-run---.stack +--.stack: stack.yaml stack.yaml.lock + stack build --fast --only-dependencies $(stackopts) .stack-work.lock: [ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en .stack-work.lock "$0" "$@" || : -.develop.env: - [ ! -z "$(CI)" -o ! -z "$$PORT_OFFSET" ] || ( echo "Not in develop!" 2>&1 ; exit 1 ) +##### BACKEND TARGETS ##### +########################### -# .PHONY: --stack-work-% -# --stack-work-%: .stack-work.lock -# [[ -d .stack-work && -d .stack-work-$* ]] && (echo ".stack-work collides with .stack-work-$*, please resolve manually" 1>&2; exit 1) || : -# [[ ! -d .stack-work-$* ]] || mv .stack-work-$* .stack-work -# -# .PHONY: --stack-krow-% -# --stack-krow-%: -# [[ ! -d .stack-work-$* ]] || ( echo ".stack-work-$* already exists, please resolve manually" 1>&2 ; exit 1 ) -# mv .stack-work .stack-work-$* -# flock -u .stack-work.lock true -# watch: -# while true; do \ -# -# start: frontend-build frontend-build-watch yesod-start -# run-s frontend:build --parallel "frontend:build:watch" "yesod:start" +############################# +##### CONTAINER TARGETS ##### ---docker-build-%: +.PHONY: --containerized-%-frontend +--containerized-%-frontend: FRADRIVE_SERVICE=frontend +--containerized-%-frontend: --image-build --image-run-%-frontend; + +.PHONY: --containerized-%-backend +--containerized-%-backend: FRADRIVE_SERVICE=backend +--containerized-%-backend: --image-build --image-run-%-backend; + +.PHONY: image-rebuild +image-rebuild-%: + $(MAKE) -- --image-build FRADRIVE_SERVICE=$* NO_CACHE=--no-cache +.PHONY: --image-build +--image-build: rm -f .Dockerfile ln -s docker/$(FRADRIVE_SERVICE)/Dockerfile .Dockerfile - $(CONTAINER_RUNNER) build -v $(PWD):/tmp/fradrive --tag $(FRADRIVE_SERVICE) --file $(PWD)/.Dockerfile ---docker-run-%: - $(CONTAINER_RUNNER) run -v $(PWD):/tmp/fradrive --env FRADRIVE_MAKE_TARGET=$* $(FRADRIVE_SERVICE) \ No newline at end of file + MOUNT_DIR=/mnt/fradrive; \ + PROJECT_DIR=/mnt/fradrive; \ + if [ "$(IN_CI)" == "true" ] ; then \ + PROJECT_DIR=/fradrive; \ + fi; \ + $(CONTAINER_COMMAND) build $(NO_CACHE) -v $(PWD):$${MOUNT_DIR} --build-arg MOUNT_DIR=$${MOUNT_DIR} --build-arg PROJECT_DIR=$${PROJECT_DIR} --tag $(FRADRIVE_SERVICE) --file $(PWD)/.Dockerfile + +.PHONY: --image-run-% +--image-run-%: +ifeq ($(IN_CONTAINER),true) + $(MAKE) -- $* +else + $(CONTAINER_COMMAND) run -v $(PWD):/mnt/fradrive --env FRADRIVE_MAKE_TARGET=$* $(FRADRIVE_SERVICE) +endif + +##### CONTAINER TARGETS ##### +############################# + + +.PHONY: i18n-check +i18n-check: --image-run---i18n-check +.PHONY: --i18n-check +--i18n-check: + ./missing-translations.sh + @echo No missing translations. + +%.lock: + [ -e $@ ] || touch $@ + flock -en $@ true \ No newline at end of file diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile index 61a6eba6e..777fe153b 100644 --- a/docker/frontend/Dockerfile +++ b/docker/frontend/Dockerfile @@ -16,15 +16,15 @@ RUN n 20.17.0 # locally these two should be identical, so that compilation results are written out into the file dir. # in CI-pipelines these two should be different, so that the container caches the compilation results. -ARG MOUNT_DIR=/bindmount/fradrive +ARG MOUNT_DIR=/mnt/fradrive ARG PROJECT_DIR=/fradrive RUN mkdir -p ${PROJECT_DIR} RUN if [ "${PROJECT_DIR}" != "${MOUNT_DIR}"]; then cp -r ${MOUNT_DIR}/* ${PROJECT_DIR} ; fi WORKDIR ${PROJECT_DIR} ENV HOME=${PROJECT_DIR} -RUN make node_modules -RUN make well-known +RUN make node_modules IN_CONTAINER=true +RUN make well-known IN_CONTAINER=true -ENV FRADRIVE_MAKE_TARGET=frontend-watch -ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} CHROME_BIN=${CHROME_BIN} +ENV FRADRIVE_MAKE_TARGET=watch-frontend +ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} IN_CONTAINER=true CHROME_BIN=${CHROME_BIN}