feat: e2b template aliases, --e2b-template-aliases and GET /templates/aliases/{alias} - #56
Merged
Merged
Conversation
…/aliases/{alias}
The SDKs create "base" when no template is named, and pools are keyed by
image, so Sandbox.create() found no pool. An alias file maps a templateID
to a pool image: create claims from the aliased pool; every reply keeps
templateID as the pool image and fills alias with its first alias, as
e2b pairs a template id with its name; the list filter accepts either
spelling; the template list carries each image's aliases; and
GET /templates/aliases/{alias} answers the SDK's alias check. The api key
file reader now serves both files.
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
Drop-in phase A, PR A3: template aliases.
Why. The e2b SDKs create the template
basewhen none is named, and pools here are keyed by image, soSandbox.create()found no pool and got503.The table.
--e2b-template-aliasesnames a file ofalias pool-imagelines.#comments are ignored.e2bAPIKeysbecamee2bFileLines(path, what)and reads both files. It passes the path throughfilepath.Cleanfor gosec now that the path is a parameter.Behavior.
templateIDas the pool image and fillsaliaswith the image's first alias in sort order. That covers create, get, list, connect, resume and fork. e2b pairs a template id with its name, the SDKs mapaliastoname, and a storedtemplateIDstill creates the same sandbox.templatefilter accepts the alias or the image, as the spec says ("template ID or alias").GET /templatesfills each image'saliases.GET /templates/aliases/{alias}answers the spec'sTemplateAliasResponse,{"templateID": "<pool image>", "public": true}, or404./health.Template.existsand the Python SDK'sTemplate.alias_existsread 200 as true and 404 as false.docs/e2b-compat.md: the new flag row, the create and template rows, the alias route row, and the read-path note.Closure and budget
Head to merge:
4a900075c80662c1fcb99c5e1d2fb1df7e645c01, on master518de6d.New exported identifiers and their consumers:
Options.TemplateAliases:NewServer, andcmd/sandbox-apiserversets it.TemplateAliasResponse:templateAlias.New unexported code: the
aliasesandimageAliasesmaps onServer,aliasOf,poolImage,templateAlias,e2bFileLines, and theE2BAliasesFileoption.Comment lines per file (added / removed):
Options.TemplateAliasesgets its godoc.TemplateAliasResponsegets its godoc.Imports:
pkg/e2bcompatimports onlypkg/scalefrom cocoonstack, and stays on encoding/json v1.Hot path
[].Hardware
Setup:
acfca8bwith ane2b-rt:24.04pool, warm 4.518de6d(main), and this head with--e2b-template-aliasesnamingbase ghcr.io/cocoonstack/sandbox/e2b-rt:24.04.curlran on the node.Sandbox.create()with no template, thengetInfo,listandTemplate.existsgetInfoandlistgive{templateId: "ghcr.io/cocoonstack/sandbox/e2b-rt:24.04", name: "base"}, andexistsgivesbasetrue, unknown false:RESULT PASSServiceBusyError ... no warm sandbox available for template "base"RESULT PASSSandbox.create(),get_info,list,Template.alias_existstemplate_idis the image,namebase,alias_existstrue/false:RESULT PASSServiceBusyException: 503 ... "base"RESULT PASS×3GET /templates/aliases/base200 {"templateID":"ghcr.io/cocoonstack/sandbox/e2b-rt:24.04","public":true}; unknown404; no key401404, no routetemplateID: base{"templateID":"ghcr.io/cocoonstack/sandbox/e2b-rt:24.04","alias":"base"}./templatesgives[{"templateID": "<image>", "aliases": ["base"]}]. The list filter finds it bybaseand by the image.Review and gates
/simplify:
getDetaildelegates to the newgetDetailWithinstead of duplicating it.templateIDas the image withaliasfilled, on every reply, create included. The first draft reported the alias astemplateIDand was changed before this PR opened.names, which no SDK reads./code, the changed files read in full: local variables named
namesshadowed the importednamespackage and are renamedaliasNames.Mutations, each caught by a test:
Gates:
make lint: 8/80 issues.on darwin and on linux.make fmt-check: ok.asl: 0 findings on both platforms.go mod tidy -diff: clean.go test -race: 11 ok.