Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ Read more in [`docs/container.md`](docs/container.md).

The Dockerfile also contains additional internal build stages used to assemble those runtime images.

### Xpra Lifecycle Settings

The Xpra GUI container's shutdown behavior is configured by the lifecycle variables near the top of [`docker/start.sh`](docker/start.sh):

```bash
XPRA_EXIT_WITH_CHILDREN="${XPRA_EXIT_WITH_CHILDREN:-yes}"
XPRA_EXIT_WITH_WINDOWS="${XPRA_EXIT_WITH_WINDOWS:-yes}"
XPRA_SERVER_IDLE_TIMEOUT="${XPRA_SERVER_IDLE_TIMEOUT:-300}"
```

- `XPRA_EXIT_WITH_CHILDREN` stops Xpra when the launched application process exits. Default: yes
- `XPRA_EXIT_WITH_WINDOWS` stops Xpra when the application no longer has any windows open. Default: yes
- `XPRA_SERVER_IDLE_TIMEOUT` controls how many seconds Xpra can remain idle before stopping. Default: 300

Adjust these values in [`docker/start.sh`](docker/start.sh), or override the variables in the deployment environment, when an application needs different lifecycle behavior.

## FNAL Kerberos Defaults

This template assumes new applications will run in the `FNAL.GOV` Kerberos environment.
Expand Down
49 changes: 36 additions & 13 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
#!/usr/bin/env bash
set -Eeuo pipefail

################################ Configuration ################################
######## Edit these defaults or override them through the environment. ########

### Xpra connection settings.
# Xpra session name.
APP_NAME="${APP_NAME:-ap-python-starter-kit}"
# Xpra display number.
XPRA_DISPLAY="${XPRA_DISPLAY:-:100}"
# Xpra authentication method (if any).
XPRA_AUTH="${XPRA_AUTH:-none}"

### Xpra HTML client settings.
# Enable or disable Xpra's HTML client.
XPRA_HTML="${XPRA_HTML:-on}"
# Host and port where Xpra serves its HTML client.
XPRA_BIND_HOST="${XPRA_BIND_HOST:-0.0.0.0}"
XPRA_BIND_PORT="${XPRA_BIND_PORT:-14500}"
XPRA_HTML="${XPRA_HTML:-on}"
# HTML mode: no password needed, no native client auth.
XPRA_AUTH="${XPRA_AUTH:-none}"

### Application and logging settings.
# Command launched by Xpra.
APP_CMD="${APP_CMD:-python -m ap_python_starter_kit.main}"
# Paths for Xpra and application logs.
XPRA_LOG_FILE="${XPRA_LOG_FILE:-/tmp/xpra.log}"
APP_LOG_FILE="${APP_LOG_FILE:-/tmp/app.log}"

### Xpra lifecycle settings.
# Stop Xpra when the launched application process (APP_CMD) exits.
XPRA_EXIT_WITH_CHILDREN="${XPRA_EXIT_WITH_CHILDREN:-yes}"
# Stop Xpra when the application no longer has any windows open.
XPRA_EXIT_WITH_WINDOWS="${XPRA_EXIT_WITH_WINDOWS:-yes}"
# Stop Xpra after this many seconds of server idle time.
XPRA_SERVER_IDLE_TIMEOUT="${XPRA_SERVER_IDLE_TIMEOUT:-300}"

### Directory settings.
# Base directory used for writable runtime paths.
RUNTIME_BASE="${RUNTIME_BASE:-/tmp}"
# Runtime directories used by Xpra and the application user.
XDG_RUNTIME_DIR_DEFAULT="${XDG_RUNTIME_DIR:-${RUNTIME_BASE}/runtime-pyuser}"
XPRA_RUN_DIR_DEFAULT="${XPRA_RUN_DIR:-${RUNTIME_BASE}/xpra}"
USER_RUN_DIR_DEFAULT="${USER_RUN_DIR:-${RUNTIME_BASE}/user-1000}"
###############################################################################

cleanup() {
echo "[start.sh] shutting down"
xpra stop "${XPRA_DISPLAY}" >/dev/null 2>&1 || true
}

trap cleanup SIGINT SIGTERM EXIT

# Prefer writable runtime dirs when running as non-root (common in OpenShift/K8s).
# /run is often read-only for unprivileged containers.
RUNTIME_BASE="${RUNTIME_BASE:-/tmp}"
XDG_RUNTIME_DIR_DEFAULT="${XDG_RUNTIME_DIR:-${RUNTIME_BASE}/runtime-pyuser}"
XPRA_RUN_DIR_DEFAULT="${XPRA_RUN_DIR:-${RUNTIME_BASE}/xpra}"
USER_RUN_DIR_DEFAULT="${USER_RUN_DIR:-${RUNTIME_BASE}/user-1000}"

mkdir -p "${USER_RUN_DIR_DEFAULT}" "${XDG_RUNTIME_DIR_DEFAULT}" "${XPRA_RUN_DIR_DEFAULT}" /tmp/.X11-unix
chmod 700 "${USER_RUN_DIR_DEFAULT}" "${XDG_RUNTIME_DIR_DEFAULT}" "${XPRA_RUN_DIR_DEFAULT}" || true
if ! chmod 1777 /tmp/.X11-unix 2>/dev/null; then
Expand All @@ -46,9 +69,9 @@ xpra start "${XPRA_DISPLAY}" \
--html="${XPRA_HTML}" \
--auth="${XPRA_AUTH}" \
--daemon=no \
--exit-with-children=yes \
--exit-with-windows=yes \
--server-idle-timeout=300 \
--exit-with-children="${XPRA_EXIT_WITH_CHILDREN}" \
--exit-with-windows="${XPRA_EXIT_WITH_WINDOWS}" \
--server-idle-timeout="${XPRA_SERVER_IDLE_TIMEOUT}" \
--start-child="/bin/bash -lc '${APP_CMD} >>\"${APP_LOG_FILE}\" 2>&1'" \
--pulseaudio=no \
--notifications=no \
Expand Down
16 changes: 16 additions & 0 deletions docs/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ make run-gui APP_CMD="python -m ap_python_starter_kit.gui"

For the Xpra image, `APP_CMD` is the supported way to replace the default GUI command that [`docker/start.sh`](docker/start.sh) launches. This override support is specific to the Xpra path and does not apply to the CLI [`runtime`](Dockerfile:62) stage.

### Configure Xpra lifecycle behavior

The Xpra lifecycle settings are defined near the top of [`docker/start.sh`](docker/start.sh), alongside the other variables developers may want to change:

```bash
XPRA_EXIT_WITH_CHILDREN="${XPRA_EXIT_WITH_CHILDREN:-yes}"
XPRA_EXIT_WITH_WINDOWS="${XPRA_EXIT_WITH_WINDOWS:-yes}"
XPRA_SERVER_IDLE_TIMEOUT="${XPRA_SERVER_IDLE_TIMEOUT:-300}"
```

- `XPRA_EXIT_WITH_CHILDREN` stops Xpra when the launched application process exits.
- `XPRA_EXIT_WITH_WINDOWS` stops Xpra when the application has no windows left open.
- `XPRA_SERVER_IDLE_TIMEOUT` controls how many seconds Xpra can remain idle before stopping.

Edit the defaults in [`docker/start.sh`](docker/start.sh) for a project-wide change, or provide the variables through the deployment environment. The current `make run-gui` target does not forward these variables as make arguments.

Security note:

- Xpra HTML is configured with `--auth=none` (no password). Do not expose this port publicly.
Expand Down