Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

muelle.client

Source: src/muelle/client.py.

muelle-client: asks a muelle host to deploy or tear down a site and waits for
the result. Used by the composite action (action.yml); configured through
MUELLE_* environment variables so it can also run outside GitHub Actions.

Required: MUELLE_ENDPOINT, MUELLE_SITE, MUELLE_SECRET
Deploy:   MUELLE_SHA256 and either MUELLE_ARTIFACT_URL or MUELLE_ARTIFACT_ID
          (resolved against the GitHub API of the current repository)
Optional: MUELLE_ACTION (deploy | teardown | announce | abort), MUELLE_ENV (preview), MUELLE_BRANCH, MUELLE_SHA,
          MUELLE_TOKEN (sent for the artifact download), MUELLE_TIMEOUT (600),
          MUELLE_POLL_INTERVAL (3), MUELLE_DEPLOYMENTS (true: report GitHub
          Deployment state, authenticated with GH_TOKEN or MUELLE_TOKEN),
          MUELLE_ALLOW_INSECURE (false: allow http:// to non-loopback hosts)

The endpoint must be https://, except for loopback hosts: the body carries
the GITHUB_TOKEN used for the artifact download, and the HMAC signature
authenticates it without hiding it.

announce (a build started) and abort (it failed or was cancelled) only update
the host's listing: they do not wait, and a failure is a warning, never an
error, so they cannot break a build.

TLS uses the system trust store; point SSL_CERT_FILE at a CA bundle to trust
a private CA.

Stdlib only: action.yml runs it on a python set up by actions/setup-python.

ClientError

class ClientError(Exception)

GitHub

class GitHub
Context of the GitHub Actions run, empty outside of it.

GitHub.run_url

def run_url(self) -> str

GitHub.listed_run_url

def listed_run_url(self) -> str
run_url as sent to the host, which only links to github.com.

Settings

class Settings

check_endpoint

def check_endpoint(endpoint: str, allow_insecure: bool = False) -> None
Refuses endpoints that would send the token in cleartext.

settings_from_env

def settings_from_env(env: Mapping[str, str]) -> Settings
Reads and checks the MUELLE_* / GITHUB_* variables.

request_id

def request_id(s: Settings, now: int, nonce: str | None = None) -> str
Unique per request: the host accepts each id once.

build_payload

def build_payload(s: Settings, id: str, now: int) -> dict[str, Any]

github_environment

def github_environment(env: str, branch: str) -> dict[str, Any]
GitHub Deployment fields for a muelle environment.

Deployment

class Deployment
GitHub Deployment reporting; every call is best effort.

Deployment.create

def create(self, sha: str, env: str, branch: str) -> None

Deployment.set_state

def set_state(self, state: str, url: str = "") -> None

wait_for_result

def wait_for_result(
    endpoint: str,
    id: str,
    timeout: float,
    interval: float,
    http: Http = _http,
    clock: Callable[[], float] = time.monotonic,
    sleep: Callable[[float], None] = time.sleep,
) -> tuple[str, dict[str, Any]]
Polls the status file until success/failure; returns (state, status).

run

def run(s: Settings, http: Http = _http, now: Callable[[], float] = time.time, **wait_kw: Any) -> int

main

def main() -> int