diff --git a/.gitignore b/.gitignore index 320302b1c..0c90b8a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ tunnel.log **/result-* .develop.cmd /.vscode +.ghc/ghci_history diff --git a/Makefile b/Makefile index 1ef34a0ed..ff73bd03e 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,6 @@ export CONTAINER_ATTACHED export CONTAINER_INIT export CONTAINER_CLEANUP -# export STACK_INIT="./utils/stack-work-init.sh" -# export STACK_CLEANUP="rm -f .stack-work.lock" - export SERVICE export SERVICE_VARIANT ?= $(SERVICE) export JOB @@ -68,7 +65,7 @@ help: clean: rm -rf develop -rm -rf node_modules .npm .cache assets/icons assets/favicons static well-known config/manifest.json - -rm -rf .job-* + -rm -rf .stack-work .stack-work.lock -rm -rf bin .Dockerfile develop -$(CONTAINER_COMMAND) container prune --force .PHONY: clean-all @@ -106,24 +103,23 @@ start: %-backend: SERVICE=backend %-backend: SERVICE_VARIANT=backend %-backend: CONTAINER_CMD=localhost/fradrive/backend -# %-backend: CONTAINER_INIT="$(STACK_INIT)" -# %-backend: CONTAINER_CLEANUP="$(STACK_CLEANUP)" %-backend: BASE_PORTS = "DEV_PORT_HTTP=3000" "DEV_PORT_HTTPS=3443" .PHONY: %-uniworxdb %-uniworxdb: SERVICE=backend %-uniworxdb: SERVICE_VARIANT=uniworxdb %-uniworxdb: CONTAINER_CMD=localhost/fradrive/backend -# %-uniworxdb: CONTAINER_INIT="$(STACK_INIT)" -# %-uniworxdb: CONTAINER_CLEANUP="$(STACK_CLEANUP)" + +.PHONY: %-ghci +%-ghci: SERVICE=backend +%-ghci: SERVICE_VARIANT=ghci +%-ghci: CONTAINER_CMD=localhost/fradrive/backend .PHONY: %-hoogle %-hoogle: SERVICE=backend %-hoogle: SERVICE_VARIANT=hoogle %-hoogle: BASE_PORTS = "HOOGLE_PORT=8081" %-hoogle: CONTAINER_CMD=localhost/fradrive/backend -# %-hoogle: CONTAINER_INIT="$(STACK_INIT)" -# %-hoogle: CONTAINER_CLEANUP="$(STACK_CLEANUP)" --start-hoogle: HOOGLE_PORT=`cat $(CONTAINER_FILE) | grep 'HOOGLE_PORT=' | sed 's/HOOGLE_PORT=//'` ; \ stack $(STACK_CORES) hoogle -- server --local --port $${HOOGLE_PORT} @@ -181,6 +177,16 @@ lint-%: CF_PREFIX = lint- lint-%: CONTAINER_ATTACHED = true lint-%: --act ; +.PHONY: shell-% +# HELP(shell-$SERVICE): launch (bash) shell inside a new $SERVICE container +shell-%: JOB=shell +shell-%: CF_PREFIX=shell- +shell-%: CONTAINER_ATTACHED=true +shell-%: --act ; +.PHONY: ghci +# HELP(ghci): launch new backend instance and enter interactive ghci shell +ghci: shell-ghci; + --act: --develop_containerized; --develop_%: PORTS = $(foreach PORT,$(BASE_PORTS),$(shell utils/next_free_port.pl $(PORT))) @@ -196,14 +202,13 @@ lint-%: --act ; $(MAKE) -- --$* CONTAINER_FILE=$${CONTAINER_FILE} CONTAINER_IDENT=$${CONTAINER_IDENT} JOB=$(JOB) .PHONY: rebuild-% -# HELP(rebuild-{backend,frontend,database,memcached,minio}): force-rebuild the stated docker image +# HELP(rebuild-{backend,frontend,database,memcached,minio}): force-rebuild a given container image rebuild-%: $(MAKE) -- --image-build SERVICE=$* NO_CACHE=--no-cache --image-build: ifeq "$(CONTAINER_CMD)" "localhost/fradrive/$(SERVICE)" rm -f .Dockerfile ln -s docker/$(SERVICE)/Dockerfile .Dockerfile - $(MAKE) .job-$(JOB) MOUNT_DIR=/mnt/fradrive; \ PROJECT_DIR=/mnt/fradrive; \ if [ "$(IN_CI)" == "true" ] ; then \ @@ -223,9 +228,7 @@ else : endif ---containerized: - $(MAKE) .job-$(JOB) - $(MAKE) -- --image-build +--containerized: --image-build DEVELOP=`cat develop/.current` ; \ ./utils/watchcontainerrun.sh "$(CONTAINER_COMMAND)" "$(CONTAINER_FILE)" "$(CONTAINER_INIT)" "$(CONTAINER_CLEANUP)" & \ CONTAINER_NAME=fradrive.$(CURR_DEV).$(CONTAINER_IDENT) ; \ @@ -250,7 +253,7 @@ endif $(CONTAINER_COMMAND) attach $${CONTAINER_ID} || : ; \ fi -# HELP(start-backend): start yesod-devel instance +# HELP(start-backend): start development instance --start-backend: export DEV_PORT_HTTP=`cat $(CONTAINER_FILE) | grep 'DEV_PORT_HTTP=' | sed 's/DEV_PORT_HTTP=//'`; \ export DEV_PORT_HTTPS=`cat $(CONTAINER_FILE) | grep 'DEV_PORT_HTTPS=' | sed 's/DEV_PORT_HTTPS=//'`; \ @@ -267,12 +270,12 @@ endif export RIBBON=$${RIBBON:-$${HOST:-localhost}} ; \ export APPROOT=$${APPROOT:-http://localhost:$${DEV_PORT_HTTP}} ; \ export AVSPASS=$${AVSPASS:-nopasswordset} ; \ - stack $(STACK_CORES) exec --local-bin-path $$(pwd)/bin -- yesod devel -p "$${DEV_PORT_HTTP}" -q "$${DEV_PORT_HTTPS}" + ./bin/uniworx # HELP(compile-backend): compile backend binaries --compile-backend: - stack build $(STACK_CORES) --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only $(--DEVELOPMENT) --local-bin-path $$(pwd)/bin + stack build $(STACK_CORES) --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only $(--DEVELOPMENT) --local-bin-path $$(pwd)/bin --copy-bins # HELP(dependencies-backend): (re-)build backend dependencies ---dependencies-backend: stack.yaml stack.yaml.lock package.yaml +--dependencies-backend: uniworx.cabal stack build $(STACK_CORES) --fast --only-dependencies # HELP(lint-backend): lint backend --lint-backend: @@ -280,9 +283,8 @@ endif # HELP(test-backend): test backend --test-backend: stack build $(STACK_CORES) --test --coverage --fast --flag uniworx:library-only $(--DEVELOPMENT) -.PHONY: .job-%: -.job-%: - ./utils/dirsymlink.pl ".job-$*" .stack-work +uniworx.cabal: + stack exec -- hpack --force # HELP(compile-frontend): compile frontend assets --compile-frontend: node_modules assets esbuild.config.mjs @@ -304,12 +306,20 @@ static: node_modules assets esbuild.config.mjs npm run build well-known: static; -# HELP(compile-uniworxdb): clear and fill database. requires running postgres +# HELP(compile-uniworxdb): clear and fill database. requires running postgres instance (use "make start-postgres" to start one) # TODO (db-m-$MIGRATION-backend): apply migration (see src/Model/Migration/Definition.hs for list of available migrations) --compile-uniworxdb: --compile-backend SERVER_SESSION_ACID_FALLBACK=${SERVER_SESSION_ACID_FALLBACK:-true} ; \ AVSPASS=${AVSPASS:-nopasswordset} ; \ - stack exec uniworxdb -- $(UNIWORXDB_OPTS) + ./bin/uniworxdb $(UNIWORXDB_OPTS) + +--shell-ghci: + stack exec -- ghci +# --main-is uniworx:exe:uniworx + +# HELP(shell-{backend,frontend,memcached,minio,postgres}): enter (bash) shell inside a new container of a given service +--shell-%: + /bin/bash # HELP(start-minio): start minio service @@ -336,21 +346,16 @@ log-%: .PHONY: enter # HELP: launch (bash) shell inside a currently running container. Use ./enter shell wrapper for more convenient usage, possibly with tab-completion in the future enter: --ensure-develop - $(MAKE) -- --shell + $(MAKE) -- --enter .PHONY: psql # HELP: enter psql (postgresql) cli inside a currently running database container psql: ENTRYPOINT=/usr/bin/psql -d uniworx psql: EXEC_OPTS=--user postgres psql: --ensure-develop - $(MAKE) -- --shell CONTAINER_FILE=develop/`cat develop/.current`/start-postgres + $(MAKE) -- --enter CONTAINER_FILE=develop/`cat develop/.current`/start-postgres -.PHONY: ghci -# HELP: launch new backend instance and enter interactive ghci shell (WIP) -ghci: ENTRYPOINT=stack ghci -ghci: --shell; - ---shell: +--enter: CONTAINER_ID=`cat $(CONTAINER_FILE) | grep 'CONTAINER_ID=' | sed 's/CONTAINER_ID=//'` ; \ $(CONTAINER_COMMAND) exec -it $(EXEC_OPTS) $${CONTAINER_ID} $(if $(ENTRYPOINT),$(ENTRYPOINT),/bin/bash) @@ -394,7 +399,5 @@ switch-develop: develop/.current: ls -1 develop | tail -n1 > develop/.current -stack.yaml.lock: --dependencies-backend; - .PHONY: --% .SUFFIXES: # Delete all default suffixes diff --git a/config/settings.yml b/config/settings.yml index 36e0d8576..582f6e640 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -120,7 +120,7 @@ auth-pw-hash: database: user: "_env:PGUSER:uniworx" password: "_env:PGPASS:uniworx" - host: "_env:PGHOST:host.docker.internal" + host: "_env:PGHOST:localhost" port: "_env:PGPORT:5432" # See config/test-settings.yml for an override during tests database: "_env:PGDATABASE:uniworx" @@ -180,7 +180,7 @@ smtp: limit: "_env:SMTPLIMIT:10" widget-memcached: - host: "_env:WIDGET_MEMCACHED_HOST:host.docker.internal" + host: "_env:WIDGET_MEMCACHED_HOST:localhost" port: "_env:WIDGET_MEMCACHED_PORT:11211" auth: [] limit: "_env:WIDGET_MEMCACHED_LIMIT:1024" @@ -189,7 +189,7 @@ widget-memcached: expiration: "_env:WIDGET_MEMCACHED_EXPIRATION:3600" session-memcached: - host: "_env:SESSION_MEMCACHED_HOST:host.docker.internal" + host: "_env:SESSION_MEMCACHED_HOST:localhost" port: "_env:SESSION_MEMCACHED_PORT:11211" auth: [] limit: "_env:SESSION_MEMCACHED_LIMIT:1024" @@ -199,7 +199,7 @@ session-memcached: # TODO: this one seems to be required! memcached: - host: "_env:MEMCACHED_HOST:host.docker.internal" + host: "_env:MEMCACHED_HOST:localhost" port: "_env:MEMCACHED_PORT:11211" auth: [] limit: "_env:MEMCACHED_LIMIT:1024" diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index 999c83c8c..54a0c5d55 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -18,12 +18,12 @@ RUN if [ "${PROJECT_DIR}" != "${MOUNT_DIR}" ] ; then cp -r "${MOUNT_DIR}"/* "${P RUN mkdir -p "${PROJECT_DIR}/.stack" ENV STACK_ROOT="${PROJECT_DIR}/.stack" -WORKDIR "${PROJECT_DIR}/.job-${JOB}" -ENV HOME="${PROJECT_DIR}/.job-${JOB}" +WORKDIR ${PROJECT_DIR} +ENV HOME=${PROJECT_DIR} RUN make -- --dependencies-backend STACK_ROOT=${STACK_ROOT} IN_CONTAINER=true JOB=${JOB} -RUN cd "${PROJECT_DIR}" && make .job-start -RUN cd "${PROJECT_DIR}/.job-start" && STACK_ROOT=${STACK_ROOT} stack install yesod-bin +RUN stack install yesod-bin +RUN stack install hpack ENV FRADRIVE_MAKE_TARGET=--start-backend ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} STACK_ROOT="${STACK_ROOT}" IN_CONTAINER=true CONTAINER_FILE="${CONTAINER_FILE}" JOB="${JOB}" diff --git a/docker/postgres/pg_hba.conf b/docker/postgres/pg_hba.conf index c11da7bfe..b826e433d 100644 --- a/docker/postgres/pg_hba.conf +++ b/docker/postgres/pg_hba.conf @@ -1,2 +1,3 @@ local all all trust -host all all 0.0.0.0/0 trust \ No newline at end of file +host all all 0.0.0.0/0 trust +host all all ::1/128 trust \ No newline at end of file diff --git a/stack.yaml b/stack.yaml index 3c331178f..c881ba7b1 100644 --- a/stack.yaml +++ b/stack.yaml @@ -10,6 +10,8 @@ rebuild-ghc-options: true #ghc-options: # "$everything": -fno-prof-auto +local-bin-path: ./bin + build: library-profiling: true executable-profiling: true diff --git a/utils/dirsymlink.pl b/utils/dirsymlink.pl index d81b66cff..b88d9c180 100755 --- a/utils/dirsymlink.pl +++ b/utils/dirsymlink.pl @@ -7,7 +7,7 @@ my ($shadowdir, @keepdirs) = @ARGV; mkdir($shadowdir); -system(qq#rm -f "$shadowdir"/* "$shadowdir"/.*#); +# system(qq#rm -f "$shadowdir"/* "$shadowdir"/.*#); for my $k(@keepdirs) { unlink("$shadowdir/$k");