actions icon indicating copy to clipboard operation
actions copied to clipboard

Provide example using cloudflare pages

Open hadley opened this issue 1 year ago • 4 comments

It's similar to netlify (including deploy previews), but has unlimited bandwidth and build-in analytics. @wch has been experimenting with it so can provide more details.

hadley avatar Jul 18 '22 17:07 hadley

The only limit that does not look good is 500 builds per month. E.g. if we are deploying the dev sites of all packages for every CI run, then that does not seem like a lot. https://developers.cloudflare.com/pages/platform/limits/

Nevertheless, we can have support for it, 500 is plenty for a lot of people.

gaborcsardi avatar Jul 18 '22 18:07 gaborcsardi

I'm pretty sure that limit is if you use their CI system to build the site. That used to be a requirement, but just a couple months ago they added the ability to upload static files directly. https://blog.cloudflare.com/cloudflare-pages-direct-uploads/

What I'm doing is building the site using GitHub Actions, then deploying it as a set of static files to Cloudflare Pages. https://developers.cloudflare.com/pages/framework-guides/deploy-anything/

This is what I use in my GHA workflow (after building the site):

      - name: Publish to Cloudflare Pages
        uses: cloudflare/[email protected]
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages publish _site/ --project-name=my_project --commit-dirty=true

The pricing is good. Free for unlimited traffic. https://www.cloudflare.com/plans/developer-platform/#overview (Follow the link, then click on "Cloudflare Pages" on the left)

wch avatar Jul 18 '22 18:07 wch

Now that I think about it a bit more, I'm unsure whether the direct upload counts as a build. Probably a good idea to ask them at https://community.cloudflare.com/

wch avatar Jul 18 '22 18:07 wch

@gaborcsardi yeah, I don't think we'd plan to use it for package sites (since GitHub pages already does seem), but having deploy previews is useful for books, and it avoids the potentially large cost overruns that we have with netlify. For that usage, I think 500 builds/deploys a month is likely to be plenty.

hadley avatar Jul 18 '22 22:07 hadley

So, it turns out that the example for this is exactly the same as the example for GH Pages. Once you connect CF Pages to a GH repo, their app is watching that repo, and it will automatically pick up the branch and directory you selected.

E.g. https://actions-61h.pages.dev/ is deployed from the regular pkgdown workflow: https://github.com/r-lib/actions/blob/v2-branch/examples/pkgdown.yaml

I'll document this in the README of the examples.

gaborcsardi avatar May 08 '24 14:05 gaborcsardi

And yes, it seems that deploying a static site is also a build, even though the build command is exit 0. But they count it as a build.

They do have a preview system. I haven't tried, but I imagine that they'll build PRs against that target branch, so you'll get previews automatically.

gaborcsardi avatar May 08 '24 14:05 gaborcsardi