Repository navigation
Container exec mode: sprites as containers on Docker or Kubernetes - #24
Merged
Merged
Conversation
SPRITZER_EXEC=container makes each sprite a container: a pod per sprite
in spritzer's namespace on Kubernetes, or a container through the Docker
socket. Exec runs the real command over the existing framed WebSocket
(stdin, env, dir, exit code) and kills it if the client disconnects.
Services follow wisp's guest API, outside at /v1/sprites/{id}/services
and inside through sprite-env on /.sprite/api.sock, and outlive the exec
that started them. The sprite URL (/s/<name> and <name>.<domain>)
proxies HTTP and WebSocket to the http_port service or 8080. The
filesystem API reads and writes the container's files. Checkpoints
answer 501 in this mode (#23).
The spritzer binary doubles as the in-sprite agent, copied in from
SPRITZER_AGENT_IMAGE, and spritzer reaches it only by exec, so no port
in a sprite has to be routable from spritzer.
The interpreter stays the default; its code and tests are untouched.
e2e/ holds the acceptance, run by scripts/e2e-docker.sh and
scripts/e2e-k3d.sh (just e2e-docker, just e2e-real) and by CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Opt-in
SPRITZER_EXEC=container. Each sprite is a container: a podsprite-<name>in spritzer's namespace on Kubernetes, or a containerspritzer-<name>through the Docker socket. The interpreter stays the default;internal/sprite,ws.go,config.goand every existing test are untouched.StreamStdinEOFcloses it),envanddir, the real exit code. Repeatedcmdparams are an argv; a singlecmdholding a command line runs under/bin/sh -c. A client that disconnects before exit has its process group killed./v1/sprites/{id}/services/...is forwarded verbatim to the agent (PUT creates and starts, streaming NDJSON for?duration; start, stop, restart, logs, signal, DELETE). From inside,sprite-env services ...talks to the same agent on/.sprite/api.sock, andPUT /v1/tasksis accepted for the box's keep-awake loop. Services outlive the exec, restart on crash, start again at container restart./s/<name>/...and<name>.<SPRITZER_URL_DOMAIN>, proxies HTTP and WebSocket to thehttp_portservice, else 8080.GET /v1/spriteslists sprites; a restarted spritzer adopts existing ones.The spritzer binary is also the in-sprite agent (
spritzer agent,sprite-env,x-exec,x-relay,x-fs,x-kill), copied into each sprite fromSPRITZER_AGENT_IMAGE(an init container on Kubernetes, a named volume on Docker). spritzer reaches it only by exec, so nothing inside a sprite has to be routable, which is what makes Docker Desktop and a cluster the same code path. Kubernetes needs onlypodsandpods/execin the namespace;deploy/k8s/container-mode.yamlhas the RBAC and Deployment.Env:
SPRITZER_EXEC,SPRITZER_RUNTIME(docker | kubernetes, auto),SPRITZER_SPRITE_IMAGE(defaultnode:22-bookworm),SPRITZER_AGENT_IMAGE(defaultghcr.io/intentius/spritzer:<version>),SPRITZER_NAMESPACE,SPRITZER_URL_DOMAIN,SPRITZER_CREATE_TIMEOUT.Acceptance
e2e/real_test.go, run byjust e2e-real(throwaway k3d cluster, spritzer deployed in-cluster with its RBAC, port-forwarded) andjust e2e-docker, and by the new CI job on both. It creates a sprite, runsuname -aand a multi-line bash script (stderr, exit 3, env, dir), pipes stdin, checks a disconnected exec is killed, startspython3 -m http.server 8080as a service withsprite-envfrom inside, fetches it through/s/<name>and the host-routed URL, again 3s after the exec ended, then destroys the sprite and checks with kubectl that the pod is gone. Local k3d run (k3s v1.33.6, arm64):Related issues
Closes #22. Follow-up: #23 (checkpoints in container mode). Consumer: arugula-salad/studio#29.
Checklist
gofmtcleangolangci-lintpasses (darwin and GOOS=linux; windows builds)go test -race ./...passesmkdocs build --strictpasses## [Unreleased]