diff --git a/.gitignore b/.gitignore index 350a4de3e..fb7530896 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index 88173918c..ffaccd8d0 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index 98f9f00f7..84be254aa 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -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 \ No newline at end of file +EXPOSE 3000/tcp +EXPOSE 3443/tcp \ No newline at end of file diff --git a/docker/backend/dev_port.pl b/docker/backend/dev_port.pl new file mode 100755 index 000000000..0d8faa0db --- /dev/null +++ b/docker/backend/dev_port.pl @@ -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 \ No newline at end of file diff --git a/docker/backend/dev_port.sh b/docker/backend/dev_port.sh deleted file mode 100644 index 1008a5f0a..000000000 --- a/docker/backend/dev_port.sh +++ /dev/null @@ -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' \ No newline at end of file diff --git a/start.sh b/start.sh index ae78372e9..223bdfe0b 100755 --- a/start.sh +++ b/start.sh @@ -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