Skip to content

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

msanchezdev
Copy link

No description provided.

@msanchezdev msanchezdev marked this pull request as draft June 22, 2025 04:40

export type NetworkProps = Required<Pick<Network, "Name">>;

export const Network = Resource(
Copy link
Owner

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

Comment on lines 21 to 30
try {
await docker.network({ id: props.Name }).remove();
} catch {
} finally {
try {
await docker.network({ id: props.Name }).inspect();
} catch {}
}
return this.destroy();
Copy link
Owner

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

Comment on lines 6 to 53
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));
Copy link
Owner

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?

Comment on lines 61 to 64
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>>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!


return {
containers: {},
network: (nameOrId: PickPathParam<"/networks/{id}", "get", "id">) => ({
Copy link
Owner

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

@msanchezdev
Copy link
Author

@sam-goodwin sorry, I am just getting started, code is not final, will look into generating docs later, first implementing the api client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants