-
Notifications
You must be signed in to change notification settings - Fork 53
Use Docker API for managing docker resources #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
export type NetworkProps = Required<Pick<Network, "Name">>; | ||
|
||
export const Network = Resource( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to provide "@example" snippets. Claude does a good job at this
alchemy/src/docker/api/network.ts
Outdated
try { | ||
await docker.network({ id: props.Name }).remove(); | ||
} catch { | ||
} finally { | ||
try { | ||
await docker.network({ id: props.Name }).inspect(); | ||
} catch {} | ||
} | ||
return this.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you want to swallow errors
scripts/generate-docker-types.ts
Outdated
const contractUrl = | ||
"https://docs.docker.com/reference/api/engine/version/v1.50.yaml"; | ||
|
||
const contract = await fetch( | ||
`https://converter.swagger.io/api/convert?url=${contractUrl}`, | ||
).then((res) => res.json()); | ||
|
||
const nodes = await run(contract); | ||
await Bun.write("alchemy/src/docker/api/types.ts", astToString(nodes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we generate docs too?
alchemy/src/docker/api/api.ts
Outdated
const GET = async < | ||
T extends ClientPathsWithMethod<typeof client, "get">, | ||
Init extends MaybeOptionalInit<paths[T], "get">, | ||
>( | ||
path: T, | ||
...init: InitParam<Init> | ||
): Promise<MethodResponse<typeof client, "get", T>> => { | ||
// @ts-ignore: dyncamically inferred on usage | ||
const { data, error, response } = await client.GET(path, ...init); | ||
|
||
if (error) { | ||
throw new Error( | ||
`Failed to GET ${path}: ${response?.status} ${response?.statusText}: ${JSON.stringify(error, null, 2)}`, | ||
); | ||
} | ||
|
||
return data as NonNullable<MethodResponse<typeof client, "get", T>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
alchemy/src/docker/api/api.ts
Outdated
|
||
return { | ||
containers: {}, | ||
network: (nameOrId: PickPathParam<"/networks/{id}", "get", "id">) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to return methods outside of the resource lifecycle handler because functions cannot be serialized.
When a resource is skipped, we don't invoke your function and instead return the persisted state data.
A wrapper function can then implement methods like network
that use the data
@sam-goodwin sorry, I am just getting started, code is not final, will look into generating docs later, first implementing the api client. |
No description provided.