build(Makefile): work on make serve

This commit is contained in:
Sarah Vaupel 2024-09-11 00:37:36 +02:00
parent 6709d27732
commit 1f0cd1066a
6 changed files with 32 additions and 11 deletions

3
.gitignore vendored
View File

@ -13,6 +13,9 @@ cabal-dev/
.cache/
.stack/
.stack-work/
.dev-port-http
.dev-port-https
.bash_history
yesod-devel/
.cabal-sandbox
cabal.sandbox.config

View File

@ -167,17 +167,18 @@ well-known/.well-known:
.PHONY: serve-backend
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}
DEV_PORT_HTTP=`docker/backend/dev_port.pl 3000 | tee .dev-port-http` \
DEV_PORT_HTTPS=`docker/backend/dev_port.pl 3443 | tee .dev-port-https` \
$(MAKE) -- --containerized---serve-dev-backend DEV_PORT_HTTP=$${DEV_PORT_HTTP} DEV_PORT_HTTPS=$${DEV_PORT_HTTPS}
.PHONY: --serve-dev-backend
--serve-dev-backend:
--serve-dev-backend: start.sh
DEV_PORT_HTTP=`cat .dev-port-http` \
DEV_PORT_HTTPS=`cat .dev-port-https` \
./start.sh
.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)
stack build --fast --profile --library-profiling --executable-profiling --flag uniworx:-library-only --local-bin-path $$(pwd)/bin $(stackopts)
.PHONY: --lint-backend
--lint-backend:

View File

@ -24,6 +24,5 @@ RUN stack build yesod-bin
ENV FRADRIVE_MAKE_TARGET=serve-backend
ENTRYPOINT make -- ${FRADRIVE_MAKE_TARGET} STACK_ROOT=${STACK_ROOT} IN_CONTAINER=true
# export full develop port range
ENV DEV_PORT=3000
EXPOSE ${DEV_PORT}/tcp
EXPOSE 3000/tcp
EXPOSE 3443/tcp

19
docker/backend/dev_port.pl Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env perl
use strict;
use warnings;
my $port = $ARGV[0];
my $used_ports = `netstat -tulan`;
my %p=();
my $addr=qr((?:\d+.\d+.\d+.\d+|[0-9a-f:]+));
for(split m/\R/, $used_ports) {
if(m#$addr:(\d+)\s+$addr:(?:\d+|\*)\s+#) {
$p{$1}=1;
}
};
$port++ while $p{$port};
print $port

View File

@ -1 +0,0 @@
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

@ -41,7 +41,7 @@ then
yesod devel -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" $@ --copy-bins --local-bin-path $(pwd)/bin
stack exec -- yesod devel -p "$DEV_PORT_HTTP" -q "$DEV_PORT_HTTPS" $@
else
exit 1
fi