Repository navigation
Serve downloads and updates from Cloudflare - #35
Merged
Merged
Conversation
GitHub sent the disk image slowly, at times about 20 KB a second, so downloads and updates could take minutes. The Worker now serves each release from the outbound-downloads R2 bucket at /download/, keeps it in the cache where it was asked for, and falls back to the GitHub release for any file not in the bucket. release.sh uploads both files there before it makes the GitHub release, and new appcast items point at the site.
A storage or cache error now sends the download on to GitHub instead of failing, and so does any Outbound-v name the bucket doesn't have, so a hand-made version name still works. A download resumed part way gets the rest from storage when the cache doesn't have it. Files are cached for a day rather than a year, and release.sh takes only versions like 1.9 or 1.9.1 and won't put up a version the bucket already has. The responses also carry the site's HSTS and nosniff headers.
A range storage can't serve, or a resume on a file that changed, now gets the whole file instead of a trip to GitHub, and a failing cache falls through to storage. Only plain downloads fill the cache. release.sh now refuses a version the appcast already offers rather than one the bucket has, so a release that stopped part way can be run again, and a Wrangler hiccup can't let a file be replaced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub sends Outbound's disk image slowly from here: today it managed about 128 KB/s, and at one point 20 KB/s, so a 5.9 MB download or update could take minutes. This serves releases from the site's own storage on Cloudflare instead.
What changes
/downloadnow goes on to/download/Outbound-v1.9.dmg. That route streams the file from the private R2 bucketoutbound-downloadsand keeps it for a day in Cloudflare's cache where it was asked for. Resumed downloads get the rest, whether from the cache or from storage. Some part-of-file requests get the whole file from storage instead: a range storage can't serve, or a resume on a file that has changed since it began. A cache error falls through to storage. A file that isn't in the bucket, or a storage error, sends the download on to the file's GitHub release.https://outbound.edbn.me/download/Outbound-v1.9.dmg. Its signature and length are unchanged, since it is the same file.release.shuploads the dmg and zip to the bucket before it makes the GitHub release, and writes new appcast items with the site's URL. Before building, it checks three things: that Wrangler can reach the bucket, that the version looks like 1.9 or 1.9.1, and that the appcast doesn't already offer that version. A release that stopped before the appcast step can simply be run again./downloadeven without JavaScript.wrangler.jsoncbinds the bucket asDOWNLOADSand names the edbn.me account, so Wrangler doesn't have to ask which account to use.Already done on Cloudflare
outbound-downloadsis created. It is private, with no public URL, so nothing reaches it but the Worker.Tested
/downloadsends the browser on to the 1.9 dmg, and the bytes match GitHub's.If-Rangethat matches.If-Range, a range starting past the end, a two-piece range or a junk range each get the whole file with a 200.wrangler dev --remotepreview with a temporary test object that was deleted afterwards.HEADthere reports the 1.9 dmg's true size.HEADreturns the size and type, and responses carry HSTS and nosniff.Outbound-v2.0-beta.dmg, redirects to GitHub. Other names get a 404.release.shturns down2,2.0-betaand1.9.0.1, and turns down 1.9, 1.8.1 and 1.8 because the appcast already offers them. It lets 2.0 and 1.9.1 through.wrangler dev --remotepreview with the real bucket): 5.9 MB in 2.4 to 3.5 s. GitHub, in the same minute, sent 3.8 MB in 30 s and didn't finish.After merging, check that
https://outbound.edbn.me/downloadgives the dmg quickly and that the appcast shows the new 1.9 URL.