Skip to content

Support CF Images binding#14027

Closed
penalosa wants to merge 2 commits intowithastro:mainfrom
penalosa:penalosa/astro-cf-images-binding
Closed

Support CF Images binding#14027
penalosa wants to merge 2 commits intowithastro:mainfrom
penalosa:penalosa/astro-cf-images-binding

Conversation

@penalosa
Copy link
Copy Markdown
Contributor

Changes

This adds a cloudflare-binding Image Service option to the Astro Cloudflare adapter. This is to support using Cloudflare images on deployments which may not have Cloudflare Images enabled on the zone (i.e. workers.dev). It's a new type rather than a replacement of the existing cloudflare image service so as not to break backwards compat (given an IMAGES binding is required in the user's wrangler.json config file.

I'm not sure if this is the right approach! Very open to changing it, but this seemed like the only way to have access to the Images binding while transforming an image. The transform() hook on an Image Service looked perfect, but I couldn't figure out how to get the Images binding accessible there.

Testing

This has been tested manually with a deployed site using a local build of the adapter.

Docs

  • This will need docs, but I wanted to align on appproach first

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jun 30, 2025

⚠️ No Changeset found

Latest commit: 01bee65

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Jun 30, 2025
@ascorbic
Copy link
Copy Markdown
Contributor

ascorbic commented Jul 1, 2025

Thanks for this. We're looking to see the best way to access the binding in the image service so it can be implemented more neatly.

@alexanderniebuhr
Copy link
Copy Markdown
Member

@penalosa, thank you for this contribution. It appears to be a fantastic addition to the adapter. I conducted an initial review of the code, and overall, it seems to be in good shape. However, I’d like to explore the possibility of enhancing its integration, which would allow us to utilize the bindings more efficiently. I’ll address this matter tomorrow morning, in European time.

On a related note, could you please provide information regarding the compatibility of the IMAGES binding with both wrangler dev and platformProxy? I’m aware that the ASSETS binding is compatible with both, iirc.

@alexanderniebuhr alexanderniebuhr self-assigned this Jul 1, 2025
@penalosa
Copy link
Copy Markdown
Contributor Author

@alexanderniebuhr it's supported by wrangler dev, but not by getPlatformProxy(), it seems. I've put up a PR to Wrangler to get that fixed: cloudflare/workers-sdk#9954

@alexanderniebuhr
Copy link
Copy Markdown
Member

As already said on Discord, after trying it myself I don't seem to have a good way to access the bindings in the transform() hook. We might be able to make that possible in the future, but for now I would like to ship this as it is. @ascorbic How do we handle this. I guess this needs a Docs PR and then does it need to wait for a minor or not?

@ascorbic
Copy link
Copy Markdown
Contributor

This needs a changeset, and if possible tests

@alexanderniebuhr
Copy link
Copy Markdown
Member

I'll take this over. I want to make this the new default option. And deprecate some other options.

@penalosa
Copy link
Copy Markdown
Contributor Author

@alexanderniebuhr can this PR be closed then? Thanks for handling this!

@ascorbic
Copy link
Copy Markdown
Contributor

I think Alex will use this PR. I've already cherry-picked it into our environment API branch, so I'm expecting it will use this.

@alexanderniebuhr
Copy link
Copy Markdown
Member

@penalosa yeah sorry for being a bit quite here. I will use this PR to ship this.

@penalosa
Copy link
Copy Markdown
Contributor Author

@alexanderniebuhr is there anything I can do to help this move along?

@ascorbic
Copy link
Copy Markdown
Contributor

@alexanderniebuhr if you prefer, we can leave this as it's already in the next branch. That said, it might still be good to get it in. What do you think is outstanding to get this in?

@alexanderniebuhr
Copy link
Copy Markdown
Member

I would like to find a way to make this as similar as possible to the next branch. For users it should not be a breaking update once we use the workerd runtime. I think the change I want here is to utilize platformProxy in dev instead of our sharp implementation. I will finalize this this week!

@alexanderniebuhr
Copy link
Copy Markdown
Member

Okay sorry for the late reply. I have checked this once again, and I think it makes most sense to wait for v6. There is not really any good solution when running the dev server in node runtime. I'll close this PR for now. @penalosa thanks again for the initial implementation and pointing us to use this binding in the v6 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants