Skip to content

Commit ffef4f1

Browse files
committed
fix: assign free ports
1 parent 180efd7 commit ffef4f1

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

build/installer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FROM alpine:latest
33

44
# Install tools needed by the installer script (Docker client and curl)
5-
RUN apk add --no-cache docker-cli docker-compose curl
5+
RUN apk add --no-cache docker-cli docker-compose curl nmap
66

77
# Copy the project templates into the image
88
COPY templates/ /templates/

build/installer/install.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,44 @@ if [ -d "$PROJECT_PATH" ]; then
2323
fi
2424
fi
2525

26+
set_free_port() {
27+
FREE_PORT_SITE=$(comm -23 <({ echo 80; seq 9080 9100; }) <(nmap --min-hostgroup 100 -p 80,9080-9100 -sS -n -T4 host.docker.internal | grep 'open' | awk '{print $1}' | cut -d'/' -f1) | head -n 1)
28+
FREE_PORT_SITE_HTTPS=$(comm -23 <({ echo 443; seq 8080 8100; }) <(nmap --min-hostgroup 100 -p 443,8080-8100 -sS -n -T4 host.docker.internal | grep 'open' | awk '{print $1}' | cut -d'/' -f1) | head -n 1)
29+
sed -i "s/80:80/${FREE_PORT_SITE}:80/g" compose.yaml
30+
sed -i "s/443:443/${FREE_PORT_SITE_HTTPS}:443/g" compose.yaml
31+
32+
URL_SITE=https://localhost
33+
34+
if [ "${FREE_PORT_SITE_HTTPS}" -ne 443 ]; then
35+
URL_SITE=${URL_SITE}:${FREE_PORT_SITE_HTTPS}
36+
fi
37+
}
38+
2639
echo "Creating new Stochastix project in './${PROJECT_NAME}'..."
2740
mkdir -p "$PROJECT_PATH/frankenphp/conf.d"
2841

2942
# Copy the template files from the image into the new project directory
30-
echo "Scaffolding project files..."
43+
echo "Preparing project files..."
3144
cp /templates/compose.yaml "${PROJECT_PATH}/compose.yaml"
3245
cp /templates/compose.override.yaml "${PROJECT_PATH}/compose.override.yaml"
3346
cp /templates/.editorconfig "${PROJECT_PATH}/.editorconfig"
3447
cp /templates/.gitattributes "${PROJECT_PATH}/.gitattributes"
3548
cp /templates/frankenphp/Caddyfile "${PROJECT_PATH}/frankenphp/Caddyfile"
3649
cp /templates/frankenphp/conf.d/20-app.dev.ini "${PROJECT_PATH}/frankenphp/conf.d/20-app.dev.ini"
3750

51+
echo
3852
echo "✅ Project files created."
39-
echo "🚀 Installing Stochastix... (This may take 3 to 10 minutes depending on your internet connection)"
53+
echo "🚀 Installing Stochastix..."
54+
echo
4055

4156
# Use the mounted Docker socket to run docker-compose on the host machine,
4257
# specifying the project directory for context.
4358
docker run --rm -it -v "${HOST_PWD}/${PROJECT_NAME}:/app" ghcr.io/phpquant/stochastix:latest php --version
44-
docker compose -p "${PROJECT_NAME}" -f "${PROJECT_PATH}/compose.yaml" up -d
59+
cd "${PROJECT_PATH}"
60+
set_free_port
61+
ABS_PATH="${HOST_PWD}/${PROJECT_NAME}" docker compose up -d
4562

4663
echo
4764
echo "✅ Stochastix is running!"
48-
echo "You can now access the UI at https://localhost."
65+
echo "You can now access the UI at ${URL_SITE}."
4966
echo

templates/compose.override.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
services:
22
php:
33
volumes:
4-
- ./:/app
5-
- ./var/log:/app/var/log
6-
- ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
7-
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
4+
- ${ABS_PATH:-.}/:/app
5+
- ${ABS_PATH:-.}/var/log:/app/var/log
6+
- ${ABS_PATH:-.}/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
7+
- ${ABS_PATH:-.}/frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
88
environment:
99
FRANKENPHP_WORKER_CONFIG: watch
1010
MERCURE_EXTRA_DIRECTIVES: demo
@@ -16,5 +16,5 @@ services:
1616

1717
messenger-worker:
1818
volumes:
19-
- ./:/app
20-
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
19+
- ${ABS_PATH:-.}/:/app
20+
- ${ABS_PATH:-.}/frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro

0 commit comments

Comments
 (0)