-
Notifications
You must be signed in to change notification settings - Fork 88
feat(cloudflare): support prebuilt images in Container resource #1194
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?
feat(cloudflare): support prebuilt images in Container resource #1194
Conversation
fc3a0d1 to
473c416
Compare
|
@john-royal can you take a look at this? |
john-royal
left a comment
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.
Left some comments - happy to merge as-is but want to be sure the approach is correct.
| /** | ||
| * Use a prebuilt image instead of building one. | ||
| * Can be a string (image reference), RemoteImage resource, or Image resource. | ||
| * Mutually exclusive with `build` property. |
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.
If this is mutually exclusive with build, should we use a union type so you can't accidentally provide both?
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.
I opted with the runtime error at L316
| tag, | ||
| build: props.build, | ||
| }); | ||
| // In local dev mode, always build if build config is provided |
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.
What motivated this when build and image are meant to be mutually exclusive? Does it have to do with the build platform potentially being different?
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.
addressed in d6d8ea7
| if (isCloudflareRegistryLink(imageRef)) { | ||
| // Already in CF registry, create a lightweight Image reference | ||
| const imageName = extractNameFromImageRef(imageRef); | ||
| const imageTag = imageRef.includes(":") | ||
| ? imageRef.split(":").pop()!.split("@")[0] | ||
| : "latest"; | ||
|
|
||
| image = { | ||
| name: imageName, | ||
| tag: imageTag, | ||
| imageRef: imageRef, | ||
| repoDigest: imageRef.includes("@") ? imageRef : undefined, | ||
| builtAt: Date.now(), | ||
| }; | ||
| } else { | ||
| // External image - automatically push to CF registry | ||
| // Cloudflare Containers currently only support images from registry.cloudflare.com | ||
| image = await retagAndPushToCloudflare(imageRef, name, tag, api); | ||
| } | ||
| } else { | ||
| // It's an Image or RemoteImage resource | ||
| const sourceImage = props.image as Image | RemoteImage; | ||
| const sourceImageRef = sourceImage.imageRef; | ||
|
|
||
| // Check if it's already in CF registry | ||
| if (isCloudflareRegistryLink(sourceImageRef)) { | ||
| // Already in CF registry, use as-is | ||
| image = sourceImage as Image; | ||
| } else { | ||
| // Not in CF registry - automatically push to CF registry | ||
| // Cloudflare Containers currently only support images from registry.cloudflare.com | ||
| image = await retagAndPushToCloudflare(sourceImageRef, name, tag, api); | ||
| } | ||
| } |
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.
Could we use the RemoteImage resource here?
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.
my intent was to maintain the previous Image declaration from L235-
const image = await Image(id, {
name: `${api.accountId}/${name}`,
tag,
build: {
platform: props.build?.platform ?? "linux/amd64",
...props.build,
},
registry: {
server: "registry.cloudflare.com",
username: credentials.username || credentials.user!,
password: secret(credentials.password),
},
});
what would be the advantage of changing to RemoteImage ? I'm not sure what you mean
Summary
Changes
imageproperty toContainerProps(mutually exclusive withbuild)RemoteImageresources, andImageresourcesregistry.cloudflare.comimageorbuildis specified (but not both)Testing
Added 5 new tests covering:
Closes #1109