ipfs / service-worker-gateway

[WIP EXPERIMENT] IPFS Gateway implemented in Service Worker
https://inbrowser.link
Other
23 stars 7 forks source link

CI: set up auto-deployment of helia-service-worker gateway with nginx config #20

Closed SgtPooki closed 6 months ago

SgtPooki commented 7 months ago

from @lidel

we recently started naming things in a boring way where they describe what they do (trustless-gateway.link, delegated-ipfs.dev./routing/v1 etc :smile:) so maybe we could mention why this gateway is special right in the name: .ipfs.in-service-worker.tld .ipfs.in-sw.tld *.ipfs.in-browser.tld (not feeling strongly, just brainstorming)

we should get one and set up CI to dogfood and autodeploy https://github.com/ipfs-shipyard/helia-service-worker-gateway to .ipfs.in-service-worker.tld (latest release) and .ipfs.staging.in-service-worker.tld (staging branch for experimentation)

@SgtPooki, @aschmahmann any preference on the name and tld?

lidel commented 7 months ago

cc @2color as this is something we will use to educate people on the difference between HTTP servers like ipfs.io doing all the IPFS work on the backend and covering all the cost, and service worker approach, where we are doing IPFS work (trustless retrieval from multiple providers, local hash verification) on the client.

To give a more solid proposal, how does in-service-worker.dev sound? Pitch: if the goal is to use this to educate developers, explicit is better. It does not bury the lede, is self-explanatory how it is different from other gateways and that SW is the mechanism, and the name composes nicely with .ipfs. and .ipns. subdomains.

2color commented 7 months ago

Let's do it. I'd vote for the shorter variant: ipfs.in-sw.xyz or .dev

SgtPooki commented 7 months ago

I personally think in-sw is a little vague, though I would like typing that more.

I prefer a more explicit in-service-worker visually, but I think if someone is using in-sw, they will be familiar with what sw actually means, so maybe it's not an issue.

SgtPooki commented 7 months ago

@lidel could we do in-browser.ipfs.io?

that could cause confusion, but could be nice?

https://specs-ipfs-tech.ipns.in-browser.ipfs.io/ https://specs-ipfs-tech.ipns.ipfs.io/

lidel commented 7 months ago

I am afraid we can't do subdomain of ipfs.io because that would defeat the origin isolation (no isolation on ipfs.io, because it has a path gateway at ipfs.io/ipfs/). General rule of thumb is to not reuse domains.

I'd say let's go with @2color's suggestion and pick short https://specs-ipfs-tech.ipns.in-sw.dev.

@ns4plabs are you able to get in-sw.dev the same way we got delegated-ipfs.dev ?

2color commented 7 months ago

Since this is going to be targeted at users, I'm a bit wary of the .dev TLD. What about .xyz?

Another idea is to use the inbrowser.xyz which would work well as CID.ipfs.inbrowser.xyz; it's memorable and self explanatory.

lidel commented 6 months ago

Thank you for all suggestions. We did traditional naming bikeshed :upside_down_face: during colo today and ended up buying

Tomorrow I'll be now working on system for building and deploying to both, along with wildcard certs. Would be nice if we had CI here update production, but we can also live with semi-manual deployment process.

Below are my initial thoughts, but better ideas are welcome:

lidel commented 6 months ago

Ok, I've been successful with

Things will start working in browser once we set up TLS for HTTPS, because many Web APIs are not enabled on insecure contexts, for now you can test with curl:

$ curl http://cid.ipfs.inbrowser.link 
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>Helia bundle by Webpack</title>

    <link
      rel="stylesheet"
      href="https://unpkg.com/tachyons@4.10.0/css/tachyons.min.css"
    />
    <link rel="stylesheet" href="https://unpkg.com/ipfs-css@0.12.0/ipfs.css" />
  <link rel="icon" href="/favicon.ico"><script defer src="main.js"></script><script defer src="sw.js"></script></head>
  <body>
    <div id="root" class="montserrat f5"></div>
  </body>
</html>

Details for posterity / review

DNS is configured like this (omitted irrelevant records):

;; CNAME Records
_dnslink.inbrowser.link.    60  IN  CNAME   _dnslink.helia-service-worker-gateway.on.fleek.co. ; this DNSLink defines the source of truth for root and all subdomains
inbrowser.link. 60  IN  CNAME   gateway-int.ipfs.io. ; note: cloudflare flattens this to make it work
*.ipfs.inbrowser.link.  60  IN  CNAME   inbrowser.link. ; catch-all wildcard for IPFS subdomain gateway
*.ipns.inbrowser.link.  60  IN  CNAME   inbrowser.link. ; catch-all wildcard for IPNS subdomain gateway

;; TXT Records
inbrowser.link. 60  IN  TXT "dnslink=/ipns/inbrowser.link" ; this TXT is returned on all _dnslink.*.ip[fn]s. subdomains thanks to wildcard CNAMEs

Making request to any domain under http://inbrowser.link, http://*.ipfs.inbrowser.link or http://*.ipns.inbrowser.link returns the same payload from fleek:

  1. Our gateway infra at gateway-int.ipfs.io reads Host header and resolves DNSlink based on the value, for example, if we have Host: cid.ipfs.inbrowser.link (subdomain request)...
  2. .. it resolves dnslink form _dnslink.cid.ipfs.inbrowser.link thanks to *.ipfs CNAME, and reads dnslink=/ipns/inbrowser.link from the main domain
  3. that recursive DNSLink triggers read from _dnslink.inbrowser.link which thanks to CNAME to _dnslink.helia-service-worker-gateway.on.fleek.co returns final CID managed by Fleek

This comes with interesting maintenance benefits:

Remaining work

SgtPooki commented 6 months ago

For end goal: my preference would be to create separate Fleek project that builds from production branch, and use it for .link, and have .dev for main branch builds.

I definitely prefer this approach. we could also have an automated PR (release-please style) that auto-updates on releases of "main" with a checklist of things to test against the .dev url; then merge would just ff prod to main HEAD

For now, it would be nice to have .dev for manual deployments too (but I can also deploy to my digitalocean box)

lidel commented 6 months ago

Adin reported some POPs struggle to get data from Fleek:

$ curl -I https://inbrowser.link/
HTTP/1.1 504 Gateway Time-out
Server: openresty
Date: Tue, 27 Feb 2024 15:07:41 GMT
Content-Type: text/html
Content-Length: 164
Connection: keep-alive
X-IPFS-LB-POP: gateway-bank1-sv15
X-BFID: cfd48b6b097b9e0f45810a2936bf26f6
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

After more pressing bugs are tackled, we will switch production at .link to setup similar to dist.ipfs.tech (cluster + manual dnslink update), fleek will be only used for dev and PR previews.

lidel commented 6 months ago

@SgtPooki @aschmahmann @2color FYSA we no longer depend on Fleek for publishing and pinning inbrowser.link and inbrowser.dev.


Example:

Follow-up work is to stabilize .link and only deploy releases there: