Skip to content

tdfs4ds.deployment

tdfs4ds.deployment

Write a ready-to-run Docker folder for the tdfs4ds gateway.

:func:create_docker_deployment turns the configuration of the running session (models, embeddings, vector store, MCP, feature store) into a folder holding a docker-compose.yml, a Dockerfile, a .env, the environments the login page offers, start scripts and a README. Nothing is started and nothing is sent to a database.

Rules that shape the code:

  • The database credentials of the person who runs it are never written. People log in on the gateway's page with their own account. A service account for the /v1 API is written only when asked for, under variable names the environments file points to.
  • A secret of the session (API key, token, ...) is written only with consent. Without it the line is commented and listed as missing.
  • The classification of "is this a secret?" is config._is_secret, never a second list.
  • Pure ASCII output; LF line endings except start.ps1 (CRLF).

logger module-attribute

logger = logging.getLogger(__name__)

__all__ module-attribute

__all__ = ['create_docker_deployment']

CHROMA_IMAGE module-attribute

CHROMA_IMAGE = 'chromadb/chroma:1.5.9'

LOGMECHS module-attribute

LOGMECHS = ('TD2', 'LDAP', 'TDNEGO', 'JWT')

_PLACEHOLDER module-attribute

_PLACEHOLDER = '<set-this>'

_DROP_PASSTHROUGH_PREFIXES module-attribute

_DROP_PASSTHROUGH_PREFIXES = ('TD_',)

_KEEP_TD module-attribute

_KEEP_TD = ('TD_REQUEST_TIMEOUT',)

_DROP_SERVE module-attribute

_DROP_SERVE = True

_DROP_ALWAYS module-attribute

_DROP_ALWAYS = ('SKILLS_FOLDER', 'INSTALL_AGENT', 'CHROMA_PATH', 'CHROMA_MODE', 'CHROMA_HOST', 'CHROMA_PORT')

_FILE_PATH_SETTINGS module-attribute

_FILE_PATH_SETTINGS = ('INSTRUCT_MODEL_CA_BUNDLE', 'MCP_SERVER_CA_BUNDLE', 'VECTOR_STORE_AUTH_PEM_FILE')

_LF_FILES module-attribute

_LF_FILES = ('Dockerfile', 'docker-compose.yml', '.env', '.dockerignore', '.gitignore', 'start.sh', 'README.md', 'state/environments.json', 'config/check_hosts.py')

_CHECK_HOSTS module-attribute

_CHECK_HOSTS = '"""Can the gateway container reach the databases? Run by start.ps1 -Check / start.sh --check."""\nimport json\nimport os\nimport socket\n\npaths = [os.environ.get("TDFS4DS_SERVE_ENVIRONMENTS", "/config/environments.yaml"),\n         os.environ.get("TDFS4DS_SERVE_ENVIRONMENTS_STATE", "/state/environments.json")]\nhosts = {}\nfor path in paths:\n    if not os.path.isfile(path):\n        continue\n    try:\n        text = open(path, encoding="utf-8").read()\n        if path.endswith((".yaml", ".yml")):\n            import yaml\n            data = yaml.safe_load(text)\n        else:\n            data = json.loads(text)\n    except Exception as exc:\n        print("cannot read %s: %s" % (path, exc))\n        continue\n    if isinstance(data, dict):\n        data = data.get("environments", [])\n    for env in data or []:\n        if isinstance(env, dict) and env.get("host"):\n            hosts[env["host"]] = env.get("label") or env.get("id")\nif not hosts:\n    print("no environment found")\nfor host, label in sorted(hosts.items()):\n    try:\n        socket.create_connection((host, 1025), 5).close()\n        print("OK       %s (%s) port 1025" % (host, label))\n    except Exception as exc:\n        print("FAILED   %s (%s) port 1025: %s" % (host, label, exc))\n'

_find_docker

_find_docker()

Path of docker(.exe) or None. Same lookup as start.ps1.

_pypi_has_version

_pypi_has_version(version, timeout=10)

True / False when PyPI answers, None when it cannot be reached.

_tcp_reachable

_tcp_reachable(host, port=1025, timeout=3)

_run_config_check

_run_config_check()

Failed checks of the running session, as [(label, hint)]. Never raises.

_assistant_warnings

_assistant_warnings()

What the deployed assistant will lack, from the session's settings (pure reads).

_compose_config_ok

_compose_config_ok(folder, docker)

(True, '') or (False, message) for docker compose config -q in folder.

_ask

_ask(*args, **kw)

_ask_insisting

_ask_insisting(*args, **kw)

_confirm

_confirm(*args, **kw)

_slug

_slug(text)

_yaml_module

_yaml_module()

_redact

_redact(value)

_render_value

_render_value(value, secret)

One .env value. A docker compose env_file interpolates $, so quote with ''.

_validate_environments

_validate_environments(envs)

Return a list of problems (empty = valid).

_is_secret_name

_is_secret_name(name)

_normalise_environment

_normalise_environment(e)

_current_environment

_current_environment(label_default, prompt)

_read_remembered

_read_remembered(path)

_merge_environments

_merge_environments(groups)

Concatenate, renaming a repeated id with a numeric suffix only when the host differs.

_dockerfile

_dockerfile(source, version, wheel_name)

_compose

_compose(source, version, port, chroma, context_path, wheel_name)

_start_ps1

_start_ps1(port)

_start_sh

_start_sh(port)

_readme

_readme(port, source, version, chroma, environments, wheel_name, secrets_written)

_session_entries

_session_entries()

{ATTR: value} of the running session, from export_config (one classification).

_local_to_container_url

_local_to_container_url(value)

_proxy_entries

_proxy_entries()

create_docker_deployment

create_docker_deployment(path='tdfs4ds-docker', *, environments=None, remembered=None, include_secrets='ask', source='pypi', version=None, port=8000, chroma='server', prompt=True, check=True, overwrite=False, force=False, wheel=None, min_profile=None)

Write a Docker folder that runs the tdfs4ds gateway. Starts nothing.

Parameters

path : str or Path Folder to create (tdfs4ds-docker). environments : list of dict, optional Environments to offer on the login page (id, label, host, logmechs, encrypt, database, databases_readonly, chroma, env, api_key_var, service_user_var, service_password_var). The connection of the running session is added first. remembered : str or Path, optional A gateway state/environments.json whose environments are merged in. include_secrets : {'ask', True, False} Whether secrets of the session (API keys, tokens) are written to .env. 'ask' asks (and means False without prompt). Without consent a secret is written as a commented placeholder and listed in missing. source : {'pypi', 'wheel', 'checkout'} How the image gets tdfs4ds: the published package, a wheel copied into the folder, or the source checkout as build context. version : str, optional tdfs4ds version (default: the running one). port : int Port published on 127.0.0.1. chroma : {'server', 'local'} 'server' adds a Chroma service; 'local' keeps files in /data. prompt : bool Ask questions (notebook or terminal). False = defaults, nothing asked. check : bool Check environments, hosts (TCP 1025), the session configuration and docker compose config before writing. overwrite : bool Replace existing files (an existing .env is patched, not replaced). force : bool Write even when a check found a problem. min_profile : {'analyst', 'scientist', 'engineer', 'admin'}, optional Written as min_profile on every environment without one: everybody who logs on gets at least this profile (the pages and actions the app offers; their database rights are unchanged). 'admin' for a personal computer; None keeps the database roles only. wheel : str or Path, optional Wheel to use with source='wheel' (default: dist/ of the checkout).

Returns

dict path, files, preview (redacted), missing, warnings, problems, written, next_steps.

_ascii

_ascii(text)

_source_checkout

_source_checkout()

The source checkout this package runs from (setup.py next to the package), or None.

_write_text

_write_text(path, text, crlf=False)

_write_tree

_write_tree(folder, files, certs, wheel_path, *, existing_env=False, env_updates=None, env_lines=None, consent=False, generated=None, extra_vars=None)

_patch_env

_patch_env(target, new_text, updates, gateway, consent, generated, extra_vars)

Update an existing .env in place: keep comments and hand-added lines.

_print_summary

_print_summary(report)

main

main(argv=None)