From 7e988b1ee448027d92490f5c19366f6ffa410eda Mon Sep 17 00:00:00 2001 From: stellarshenson Date: Fri, 6 Feb 2026 11:53:30 +0100 Subject: [PATCH] chore: updated with the new way of localhost routing --- extra/traefik-host-based-routing/.env.default | 13 +++++ extra/traefik-host-based-routing/.env.example | 13 ----- extra/traefik-host-based-routing/README.md | 47 +++++++++---------- .../compose_override.yml | 4 +- extra/traefik-host-based-routing/start.sh | 20 ++++---- extra/traefik-host-based-routing/stop.sh | 18 +++---- 6 files changed, 53 insertions(+), 62 deletions(-) create mode 100644 extra/traefik-host-based-routing/.env.default delete mode 100644 extra/traefik-host-based-routing/.env.example diff --git a/extra/traefik-host-based-routing/.env.default b/extra/traefik-host-based-routing/.env.default new file mode 100644 index 0000000..5a827f6 --- /dev/null +++ b/extra/traefik-host-based-routing/.env.default @@ -0,0 +1,13 @@ +# Default environment variables for JupyterHub deployment +# Override in .env (not tracked by git) + +# Domain for Traefik routing +# Example: lab.example.com +BASE_HOSTNAME=localhost + +# JupyterHub subdomain prefix (set empty to serve at root domain) +JUPYTERHUB_PREFIX=jupyterhub. + +# Enable CIFS mount for shared storage (0=disabled, 1=enabled) +# Requires compose_cifs.yml to be configured with NAS credentials +ENABLE_CIFS=0 diff --git a/extra/traefik-host-based-routing/.env.example b/extra/traefik-host-based-routing/.env.example deleted file mode 100644 index c2b2a5c..0000000 --- a/extra/traefik-host-based-routing/.env.example +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables for JupyterHub deployment -# Copy to .env and customize - -# Domain for Traefik routing (required) -# Example: lab.example.com -BASE_HOSTNAME=localhost - -# JupyterHub hostname (remove jupyterhub. prefix to serve at root domain) -JUPYTERHUB_HOSTNAME=jupyterhub.${BASE_HOSTNAME} - -# Enable CIFS mount for shared storage (0=disabled, 1=enabled) -# Requires compose_cifs.yml to be configured with NAS credentials -ENABLE_CIFS=0 diff --git a/extra/traefik-host-based-routing/README.md b/extra/traefik-host-based-routing/README.md index 160cb54..c398916 100644 --- a/extra/traefik-host-based-routing/README.md +++ b/extra/traefik-host-based-routing/README.md @@ -12,13 +12,13 @@ Template for deploying stellars-jupyterhub-ds with local Traefik reverse proxy a 2. Generate certificates for your domain: ```bash - ./generate-certs.sh yourdomain.example.com + ./generate-certs.sh --cn "My DEV Certificate" --dns-altnames "*.example.com,example.com,*.localhost,localhost" ``` -3. Create `.env` and set your hostname: +3. Configure (optional): ```bash - cp .env.example .env - # Edit .env: BASE_HOSTNAME=yourdomain.example.com + # Create .env to override defaults from .env.default: + echo "BASE_HOSTNAME=example.com" > .env ``` 4. Start: @@ -34,13 +34,14 @@ Template for deploying stellars-jupyterhub-ds with local Traefik reverse proxy a compose_cifs.yml # Optional CIFS mount configuration start.sh # Clone/update + start services stop.sh # Stop services - generate-certs.sh # Certificate generation script + generate-certs.sh # Certificate generation (--help for usage) install_cert.sh # Linux certificate installer install_cert.bat # Windows certificate installer - .env.example # Example environment config + .env.default # Default environment config (always loaded) + .env # Local overrides (optional, gitignored) certs/ - tls.yml # Traefik TLS configuration - _.yourdomain.example.com/ # Generated wildcard cert + .tls.yml # Traefik TLS configuration (auto-generated) + / # Certificate folder (auto-generated) cert.pem # Certificate (import to browser) key.pem # Private key stellars-jupyterhub-ds/ # Cloned repository (gitignored) @@ -48,27 +49,25 @@ Template for deploying stellars-jupyterhub-ds with local Traefik reverse proxy a ## Configuration -Set `BASE_HOSTNAME` in `.env` for your domain. Edit `compose_override.yml` to customize: -- Ports (default: 80/443) -- Environment variables (idle culler, signup) -- Network name +Configure via `.env.default` (always loaded) and `.env` (optional overrides, gitignored): + +- `BASE_HOSTNAME` - domain for Traefik routing (default: `localhost`) +- `JUPYTERHUB_PREFIX` - JupyterHub subdomain prefix, set empty to serve at root domain (default: `jupyterhub.`) +- `ENABLE_CIFS` - enable CIFS shared mount, `0`/`1` (default: `0`) + +Edit `compose_override.yml` to customize ports (default: 80/443), environment variables (idle culler, signup), or network name. ### Optional CIFS Mount -To enable shared NAS storage for user containers: - 1. Edit `compose_cifs.yml` with your NAS credentials -2. Create `.env` from `.env.example`: - ```bash - cp .env.example .env - ``` -3. Set `ENABLE_CIFS=1` in `.env` +2. Set `ENABLE_CIFS=1` in `.env` ## Access After deployment: -- JupyterHub: https://jupyterhub.yourdomain.example.com/ -- Traefik: https://traefik.yourdomain.example.com +- JupyterHub: `https://${JUPYTERHUB_PREFIX}${BASE_HOSTNAME}/` (default: `jupyterhub.localhost`) +- Traefik: `https://traefik.${BASE_HOSTNAME}/` +- Localhost: `https://jupyterhub.localhost/`, `https://jupyterhub.app.localhost/` ### Certificate Installation @@ -76,12 +75,12 @@ Import the self-signed certificate to your browser for trusted HTTPS: **Linux:** ```bash -./install_cert.sh certs/_.yourdomain.example.com/ +./install_cert.sh certs// ``` **Windows:** ```cmd -install_cert.bat certs\_.yourdomain.example.com\ +install_cert.bat certs\\ ``` ## Commands @@ -94,5 +93,5 @@ install_cert.bat certs\_.yourdomain.example.com\ To view logs: ```bash -docker compose -f stellars-jupyterhub-ds/compose.yml -f compose_override.yml logs -f jupyterhub +docker compose --env-file .env.default -f stellars-jupyterhub-ds/compose.yml -f compose_override.yml logs -f jupyterhub ``` diff --git a/extra/traefik-host-based-routing/compose_override.yml b/extra/traefik-host-based-routing/compose_override.yml index 3625266..babccf6 100644 --- a/extra/traefik-host-based-routing/compose_override.yml +++ b/extra/traefik-host-based-routing/compose_override.yml @@ -57,7 +57,7 @@ services: - "traefik.http.middlewares.redirect-to-https.redirectscheme.permanent=true" # Dashboard: traefik.${BASE_HOSTNAME} - - "traefik.http.routers.dashboard.rule=Host(`traefik.${BASE_HOSTNAME}`) || Host(`traefik.localhost`)" + - "traefik.http.routers.dashboard.rule=Host(`traefik.${BASE_HOSTNAME}`) || HostRegexp(`^traefik(\\..+)?\\.localhost$`)" - "traefik.http.routers.dashboard.entrypoints=websecure" - "traefik.http.routers.dashboard.tls=true" - "traefik.http.routers.dashboard.service=api@internal" @@ -75,7 +75,7 @@ services: - "traefik.enable=true" # JupyterHub router (root path) - - "traefik.http.routers.jupyterhub-rtr.rule=Host(`${JUPYTERHUB_HOSTNAME}`) || Host(`jupyterhub.localhost`)" + - "traefik.http.routers.jupyterhub-rtr.rule=Host(`${JUPYTERHUB_PREFIX}${BASE_HOSTNAME}`) || HostRegexp(`^${JUPYTERHUB_PREFIX}(.*\\.)?localhost$`)" - "traefik.http.routers.jupyterhub-rtr.entrypoints=websecure" - "traefik.http.routers.jupyterhub-rtr.tls=true" - "traefik.http.routers.jupyterhub-rtr.service=jupyterhub-svc" diff --git a/extra/traefik-host-based-routing/start.sh b/extra/traefik-host-based-routing/start.sh index 0025a79..9f4bebb 100755 --- a/extra/traefik-host-based-routing/start.sh +++ b/extra/traefik-host-based-routing/start.sh @@ -10,16 +10,8 @@ REPO_URL="https://github.com/stellarshenson/stellars-jupyterhub-ds.git" REPO_DIR="stellars-jupyterhub-ds" REFRESH=false -# Default configuration (override via .env) -ENABLE_CIFS="${ENABLE_CIFS:-0}" - -# Create .env from example if missing -if [[ ! -f .env ]] && [[ -f .env.example ]]; then - cp .env.example .env - echo "Created .env from .env.example" -fi - -# Load environment variables +# Load defaults, then local overrides +source .env.default if [[ -f .env ]]; then source .env fi @@ -53,7 +45,11 @@ else fi # Build compose command with optional CIFS mount -COMPOSE_FILES="--env-file .env -f stellars-jupyterhub-ds/compose.yml -f compose_override.yml" +COMPOSE_FILES="--env-file .env.default" +if [[ -f .env ]]; then + COMPOSE_FILES="${COMPOSE_FILES} --env-file .env" +fi +COMPOSE_FILES="${COMPOSE_FILES} -f stellars-jupyterhub-ds/compose.yml -f compose_override.yml" if [[ "${ENABLE_CIFS}" == "1" ]]; then echo "CIFS mount enabled" COMPOSE_FILES="${COMPOSE_FILES} -f compose_cifs.yml" @@ -64,4 +60,4 @@ docker compose ${COMPOSE_FILES} pull docker pull stellars/stellars-jupyterlab-ds:latest docker compose ${COMPOSE_FILES} up -d --no-build -echo "Done. Access: https://${JUPYTERHUB_HOSTNAME:-localhost}/" +echo "Done. Access: https://${JUPYTERHUB_PREFIX:-jupyterhub.}${BASE_HOSTNAME:-localhost}/" diff --git a/extra/traefik-host-based-routing/stop.sh b/extra/traefik-host-based-routing/stop.sh index 19fead5..5362b45 100755 --- a/extra/traefik-host-based-routing/stop.sh +++ b/extra/traefik-host-based-routing/stop.sh @@ -5,22 +5,18 @@ set -e cd "$(dirname "$0")" -# Default configuration (override via .env) -ENABLE_CIFS="${ENABLE_CIFS:-0}" - -# Create .env from example if missing -if [[ ! -f .env ]] && [[ -f .env.example ]]; then - cp .env.example .env - echo "Created .env from .env.example" -fi - -# Load environment variables +# Load defaults, then local overrides +source .env.default if [[ -f .env ]]; then source .env fi # Build compose command with optional CIFS mount -COMPOSE_FILES="--env-file .env -f stellars-jupyterhub-ds/compose.yml -f compose_override.yml" +COMPOSE_FILES="--env-file .env.default" +if [[ -f .env ]]; then + COMPOSE_FILES="${COMPOSE_FILES} --env-file .env" +fi +COMPOSE_FILES="${COMPOSE_FILES} -f stellars-jupyterhub-ds/compose.yml -f compose_override.yml" if [[ "${ENABLE_CIFS}" == "1" ]]; then COMPOSE_FILES="${COMPOSE_FILES} -f compose_cifs.yml" fi