build(Makefile): work on serving

This commit is contained in:
Sarah Vaupel 2024-09-09 16:21:11 +02:00
parent 609db460f6
commit 6709d27732
5 changed files with 56 additions and 31 deletions

View File

@ -1,14 +1,12 @@
CONTAINER_COMMAND ?= podman
IN_CONTAINER ?= false
IN_CI ?= false
SHELL=bash SHELL=bash
export CONTAINER_COMMAND export CONTAINER_COMMAND ?= podman
export IN_CONTAINER export IN_CONTAINER ?= false
export IN_CI export IN_CI ?= false
export WATCH
db ?= -cf export db ?= -cf
export DEV_PORT_HTTP
export DEV_PORT_HTTPS
########################### ###########################
##### GENERAL TARGETS ##### ##### GENERAL TARGETS #####
@ -44,7 +42,10 @@ release:
##### UNIFIED FRONTEND/BACKEND TARGETS ##### ##### UNIFIED FRONTEND/BACKEND TARGETS #####
.PHONY: serve .PHONY: serve
serve: serve-frontend serve-backend serve:
$(MAKE) serve-database &
$(MAKE) serve-frontend &
$(MAKE) serve-backend
.PHONY: compile .PHONY: compile
compile: compile-frontend compile-backend compile: compile-frontend compile-backend
@ -164,8 +165,14 @@ well-known/.well-known:
--%-prod-backend: stackopts=--flag uniworx:-dev --%-prod-backend: stackopts=--flag uniworx:-dev
--%-prod-backend: --image-build --containerized-%-backend; --%-prod-backend: --image-build --containerized-%-backend;
.PHONY: --serve-backend .PHONY: serve-backend
--serve-backend: .stack-work.lock serve-backend:
export DEV_PORT_HTTP=`netstat -tulan | perl -le 'use strict;use warnings;my %p=();my $addr=qr((?:\d+.\d+.\d+.\d+|[0-9a-f:]+));while(<>){ if(m#$addr:(\d+)\s+$addr:(?:\d+|\*)\s+#) { $p{$1}=1 }}; my $port = 3000; $port++ while $p{$port}; print $port'` ; \
export DEV_PORT_HTTPS=`netstat -tulan | perl -le 'use strict;use warnings;my %p=();my $addr=qr((?:\d+.\d+.\d+.\d+|[0-9a-f:]+));while(<>){ if(m#$addr:(\d+)\s+$addr:(?:\d+|\*)\s+#) { $p{$1}=1 }}; my $port = 3443; $port++ while $p{$port}; print $port'` ; \
echo "bisschen mehr: ${DEV_PORT_HTTP}" ; \
$(MAKE) -- --containerized---serve-dev-backend DEV_PORT_HTTP=${DEV_PORT_HTTP} DEV_PORT_HTTPS=${DEV_PORT_HTTPS}
.PHONY: --serve-dev-backend
--serve-dev-backend:
./start.sh ./start.sh
.PHONY: --compile-backend .PHONY: --compile-backend
@ -187,6 +194,9 @@ database: .stack .stack-work.lock compile-backend-prod
export AVSPASS=$${AVSPASS:-nopasswordset} export AVSPASS=$${AVSPASS:-nopasswordset}
stack exec uniworxdb -- $(db) stack exec uniworxdb -- $(db)
.PHONY: serve-database
serve-database: --containerized-database
.PHONY: .stack .PHONY: .stack
.stack: stack.yaml stack.yaml.lock .stack: stack.yaml stack.yaml.lock
.stack: .stack:
@ -204,6 +214,13 @@ database: .stack .stack-work.lock compile-backend-prod
############################# #############################
##### CONTAINER TARGETS ##### ##### CONTAINER TARGETS #####
.PHONY: --containerized-database
--containerized-database: FRADRIVE_SERVICE=database
--containerized-database: --image-build
if [ "$(IN_CONTAINER)" == "false" ] ; then \
$(CONTAINER_COMMAND) run fradrive/$(FRADRIVE_SERVICE) ; \
fi
.PHONY: --containerized-%-frontend .PHONY: --containerized-%-frontend
--containerized-%-frontend: FRADRIVE_SERVICE=frontend --containerized-%-frontend: FRADRIVE_SERVICE=frontend
#--containerized-%-frontend: --image-build --image-run-%-frontend; #--containerized-%-frontend: --image-build --image-run-%-frontend;

View File

@ -19,9 +19,11 @@ RUN mkdir -p /.stack
ENV STACK_ROOT=/.stack ENV STACK_ROOT=/.stack
RUN make .stack STACK_ROOT=${STACK_ROOT} IN_CONTAINER=true RUN make .stack STACK_ROOT=${STACK_ROOT} IN_CONTAINER=true
RUN stack build yesod-bin
ENV FRADRIVE_MAKE_TARGET=backend-build ENV FRADRIVE_MAKE_TARGET=serve-backend
ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} STACK_ROOT=${STACK_ROOT} IN_CONTAINER=true ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} STACK_ROOT=${STACK_ROOT} IN_CONTAINER=true
# export full develop port range # export full develop port range
EXPOSE TODO/tcp ENV DEV_PORT=3000
EXPOSE ${DEV_PORT}/tcp

View File

@ -0,0 +1 @@
netstat -tulan | perl -le 'use strict;use warnings;my %p=();my $addr=qr((?:\d+.\d+.\d+.\d+|[0-9a-f:]+));while(<>){ if(m#$addr:(\d+)\s+$addr:(?:\d+|*)\s+#) { $p{$1}=1 }}; my $port = 3000; $port++ while $p{$port}; print $port'

View File

@ -1,14 +1,19 @@
FROM postgres:12 FROM registry.uniworx.de/fradrive/fradrive/postgres:12
# Allow for connecting to database without password authentication # Allow for connecting to database without password authentication
ENV POSTGRES_HOST_AUTH_METHOD=trust ENV POSTGRES_HOST_AUTH_METHOD=trust
RUN cp /mnt/fradrive/docker/database/schema.sql /schema.sql && chown postgres:postgres /schema.sql
RUN cp /mnt/fradrive/docker/database/initdb.sh /etc/fradrive-db && chmod 755 /etc/fradrive-db
USER postgres USER postgres
# postgresql.conf and postgres_hba.conf resulted in error (Invalid data directory or sth); using -o/--options in initdb.sh instead # postgresql.conf and postgres_hba.conf resulted in error (Invalid data directory or sth); using -o/--options in initdb.sh instead
# COPY --chown=postgres:postgres --chmod=644 ./postgresql.conf /etc/postgresql/12/main/postgresql.conf # COPY --chown=postgres:postgres --chmod=644 ./postgresql.conf /etc/postgresql/12/main/postgresql.conf
# COPY --chown=postgres:postgres --chmod=644 ./pg_hba.conf /etc/postgresql/12/main/pg_hba.conf # COPY --chown=postgres:postgres --chmod=644 ./pg_hba.conf /etc/postgresql/12/main/pg_hba.conf
COPY ./schema.sql /schema.sql # ADD ./schema.sql /schema.sql
COPY --chmod=755 ./initdb.sh /etc/fradrive-db # ADD --chmod=755 ./initdb.sh /etc/fradrive-db
ENTRYPOINT /etc/fradrive-db ENTRYPOINT /etc/fradrive-db
EXPOSE $DEV_PORT_HTTP/tcp
EXPOSE $DEV_PORT_HTTPS/tcp

View File

@ -19,29 +19,29 @@ export COOKIES_SECURE=${COOKIES_SECURE:-false}
export ALLOW_DEPRECATED=${ALLOW_DEPRECATED:-true} export ALLOW_DEPRECATED=${ALLOW_DEPRECATED:-true}
export ENCRYPT_ERRORS=${ENCRYPT_ERRORS:-false} export ENCRYPT_ERRORS=${ENCRYPT_ERRORS:-false}
export RIBBON=${RIBBON:-${__HOST:-localhost}} export RIBBON=${RIBBON:-${__HOST:-localhost}}
export APPROOT=${APPROOT:-http://localhost:$((${PORT_OFFSET:-0} + 3000))} export APPROOT=${APPROOT:-http://localhost:$DEV_PORT_HTTP}
export AVSPASS=${AVSPASS:-nopasswordset} export AVSPASS=${AVSPASS:-nopasswordset}
unset HOST unset HOST
export PORT_OFFSET=$(((16#$(sha256sum <<<"$(hostname -f):''${basePath}" | head -c 16)) % 1000)) # export PORT_OFFSET=$(((16#$(sha256sum <<<"$(hostname -f):''${basePath}" | head -c 16)) % 1000))
move-back() { # move-back() {
mv -vT .stack-work .stack-work-run # mv -vT .stack-work .stack-work-run
[[ -d .stack-work-build ]] && mv -vT .stack-work-build .stack-work # [[ -d .stack-work-build ]] && mv -vT .stack-work-build .stack-work
} # }
if [[ -d .stack-work-run ]]; then # if [[ -d .stack-work-run ]]; then
[[ -d .stack-work ]] && mv -vT .stack-work .stack-work-build # [[ -d .stack-work ]] && mv -vT .stack-work .stack-work-build
mv -vT .stack-work-run .stack-work # mv -vT .stack-work-run .stack-work
trap move-back EXIT # trap move-back EXIT
fi # fi
if ! [ -z "$(which yesod)" ] if ! [ -z "$(which yesod)" ]
then then
yesod devel -p $((${PORT_OFFSET:-0} + 3000)) -q $((${PORT_OFFSET:-0} + 3443)) $@ yesod devel -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@
elif ! [ -z "$(which stack)" ] elif ! [ -z "$(which stack)" ]
then then
stack exec -- yesod devel -p $((${PORT_OFFSET:-0} + 3000)) -q $((${PORT_OFFSET:-0} + 3443)) $@ stack exec -- yesod devel -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@ --copy-bins --local-bin-path $(pwd)/bin
else else
exit 1 exit 1
fi fi