A static site from a bucket
A landing page, a menu, a blog, the front end of an app: pages that are files don’t need your machine to be running. Put them in a bucket and let your web portal serve the bucket. The portal then answers those pages itself, on its own address, to anyone, while the machine is suspended; what the bucket doesn’t have still reaches your service as before.
flowchart TD
browser["Browser"]
edge["AgentSpaces edge"]
auth["Auth service"]
bucket["The bucket (the machine may be suspended)"]
svc["Your service in the machine, behind sign-in as before"]
browser -- "GET https://<name>.agent-app.eu/menu/" --> edge
edge -- "sign-in paths (/_portal/, /oauth/, …)" --> auth
edge -- "GET or HEAD of a path the bucket has" --> bucket
edge -- "everything else" --> svc
Everything here is done from inside the machine, with space-env bucket:
space-env bucket create NAME [--max-bytes N] [--inline PREFIX]...
space-env bucket edit NAME [--max-bytes N] [--inline PREFIX]... [--no-inline]
[--not-found PATH | --no-not-found]
space-env bucket put NAME PATH [--prefix PREFIX] [--as PATH] [--type MIME] [--prune]
space-env bucket put NAME --tar - [--prefix PREFIX] [--prune]
space-env bucket diff NAME DIR [PREFIX]
space-env bucket ls NAME [PREFIX] [--json]
space-env bucket rm NAME PATH... | --prefix PREFIX
space-env bucket list [--json]
space-env bucket serve NAME | --off
space-env bucket delete NAMEEvery command and flag is also in the space-env reference.
What a bucket is
A bucket is a set of files that belongs to a project: every machine of the project can
use its buckets, by name. Each file has a path (index.html, assets/app.css) and is
public: anyone with its address can fetch it, signed in or not. Put nothing in a
bucket that you wouldn’t put on a public web page.
- A name is 1 to 63 characters of
a-z,0-9and-, starting with a letter or digit and not ending with-, unique in the project (serveis taken). A project has at most 100 buckets. - Paths are relative, separated by
/: no leading/, no empty,.or..parts, at most 1024 bytes (255 per part). There are no directories, only paths that share a prefix. - The content type comes from the path’s extension (
.html,.css,.svg, …), or from--typefor a single file. - Files are stored by content: a file that is already in the bucket is not uploaded again, under any path.
space-env bucket create site
space-env bucket listcreate, edit and list print each bucket’s name, what it stores, and the address of
its files on the storage host:
site 0 bytes in 0 files https://agentspaces-public.s3.nl-ams.scw.cloud/b/<bucket id>/Quota and limits
| Limit | |
|---|---|
| Storage of all your organization’s buckets | set by your plan; a plan without bucket storage refuses every upload (“your plan has no bucket storage”) |
| Storage of one bucket | --max-bytes N on create or edit; 0 (the default): only the plan’s limit |
| One file | 256 MiB |
| Buckets per project | 100 |
| Inline prefixes (below) | 16, each at most 200 bytes |
Storage counts what the bucket’s paths name: a file under two paths counts once, and a file you replace or remove stops counting at once (its bytes are deleted an hour later). Files that don’t fit are refused before they are uploaded, with what is stored and what the limit is:
space-env: buckets store 9800000 of 10000000 bytes; 450000 more don't fitspace-env bucket create shop --max-bytes 500000000
space-env bucket edit shop --max-bytes 0Upload
put takes one file, a directory, or a tar stream on standard input:
- A directory’s files keep their paths below it:
dist/assets/app.cssbecomesassets/app.css. Links are followed; hidden files are uploaded too. - A file keeps its name, or gets the path
--asgives it. --tar -reads a tar stream: its entries’ names are the paths (a leading./dropped; directories, links and devices skipped). Handy when the build runs elsewhere (ssh build tar -C dist -c . | space-env bucket put …) or when you want to pick files with tar’s own options.--prefix Pputs everything underP/, and limits--prunetoP/.--prunethen removes the bucket’s files (under the prefix) that weren’t in this upload, so the bucket ends up exactly like the directory.
Only files that changed go up: space-env sends each file’s SHA-256 first and uploads only those the bucket lacks. It prints what it did:
3 files: 1 uploaded (2048 bytes), 2 unchanged, 1 removedspace-env bucket put site dist/ --prune
space-env bucket put site menu.pdf --as files/menu.pdf
tar -C dist -c . | space-env bucket put site --tar - --prefix v2Before you put: diff
diff compares a directory with the bucket and changes nothing. It prints + path for a
file the bucket lacks, ~ path for one whose content differs, and - path for one only
the bucket has (which put --prune would remove):
space-env bucket diff site dist/+ assets/app.4f2a.js
~ index.html
- assets/app.91c0.jsLook and remove
ls lists the files (path, size, content type), optionally only those whose path starts
with a prefix; --json adds each one’s SHA-256 and time. rm removes paths, or every
path under --prefix:
space-env bucket ls site
space-env bucket ls site assets/
space-env bucket rm site old.html
space-env bucket rm site --prefix v2/Serve it from your web portal
The machine must be behind a web portal first
(space-env web-portal attach); otherwise serve says “this VM is behind
no web portal”. Then:
space-env bucket serve siteprints the web portal serves bucket site, and from then on the portal (on its own
address and on its custom domains) answers like this:
- The sign-in paths (
/_portal/,/oauth/, …) and the developer MCP path stay the auth service’s, as always. - A
GETorHEADof a path the bucket has is answered from the bucket, to anyone, without signing in and without resuming the machine. Search engines see the pages too./and every path ending in/answer with theindex.htmlunder it;/menuwithout a filemenubut withmenu/index.htmlredirects to/menu/.- Pages (HTML) come from the portal’s own address. They may be cached for 60 seconds, so a new version shows within a minute.
- CSS and JavaScript files up to 256 KiB come from the portal’s own address too, like
pages: a stylesheet in the page’s
<head>costs no extra trip to another host. - Those pages, CSS and JavaScript files the portal sends itself go out compressed (zstd or gzip) to browsers that accept it, when they are 256 bytes or more and compressing makes them smaller; files under 256 bytes are sent as they are.
- Everything else (images, fonts, downloads, larger CSS and JavaScript) is a redirect
to the file’s address on the storage host, which browsers follow and cache. Link to files
with relative paths or paths from the root (
/assets/app.css), never with the storage host’s address: that one changes with every new version of the file. /robots.txtcomes from the bucket when it has one. Without one, the portal answers that everything is disallowed, as for any portal: include arobots.txtif search engines should index the site.
- Everything else reaches your service in the machine exactly as it does without a
bucket:
POSTs and other methods, and every path the bucket doesn’t have. Sign-in, anonymous access and resuming work as before.
So the bucket is the front, and your service the back: a page from the bucket can call
/api/…, which the bucket doesn’t have, and those calls reach your service, signed in.
The bucket’s pages are the same for everyone (they get no
identity header): a page that shows who is signed in
asks your service from its JavaScript.
Warning
A bucket’s pages are public even on a portal without anonymous access: whoever knows a path gets its file. Keep what only signed-in users may see in your service.
space-env bucket serve --off makes the portal stop using the bucket (every request goes to
the machine again); deleting the bucket does the same. A portal serves one bucket; serve
with another name switches to it at once.
Inline prefixes
Only pages and small CSS and JavaScript come from the portal’s own address; other files are redirects. A file that a browser must load from the site’s own address (a service worker, a script that must be same-origin) needs an inline prefix: paths starting with it are served like pages (up to 4 MiB each; larger ones are redirected anyway).
space-env bucket edit site --inline sw.js --inline workbox/
space-env bucket edit site --no-inline--inline on edit replaces the prefixes the bucket had; --no-inline clears them.
A not-found page
Without more, a path the bucket doesn’t have goes to your service in the machine, which
resumes it if it sleeps; when nothing listens there, the visitor gets a plain not found.
A site without a service (a blog, a brochure) can name its own page for those paths
instead, such as the 404.html that Hugo and most site generators write:
space-env bucket edit site --not-found 404.htmlFrom then on a GET or HEAD of a path the bucket lacks is answered with that page and
status 404, compressed like any page, without resuming the machine. Those requests
no longer reach your service at all, so don’t set one when your service answers GET
requests itself (/api/…); POSTs and other methods still go to it. Give links in the
page paths from the root (/css/site.css, not css/site.css): it is shown at any depth.
If the bucket loses the file, paths it lacks go to the machine again.
--no-not-found takes the page away.
Worked example: deploy a build
A front end built with npm into dist/, an API on port 3000 in the same machine, which
is already behind a web portal (space-env web-portal attach --port 3000). Once:
space-env bucket create frontA deploy script, run after every build: it builds dist/ (with a dist/robots.txt),
shows what will change, uploads the changes and drops what the build no longer has, and
makes sure the portal serves the bucket (once is enough; again does no harm). It can run
while the site is live.
set -e
npm run build
space-env bucket diff front dist/
space-env bucket put front dist/ --prune
space-env bucket serve frontThe same with a tar stream (from a build that runs elsewhere, or to leave files out):
tar -C dist --exclude '*.map' -c . | space-env bucket put front --tar - --pruneUpload order matters little: new files go up before --prune removes old ones, but a
visitor in the middle of a deploy may get a new page that names a file not yet uploaded.
Builds that put a hash in their asset names (app.4f2a.js) avoid this, since old and new
files then live side by side until the prune.
Delete
space-env bucket delete shopremoves the bucket and every file in it; their addresses stop working, and a portal that served it sends every request to its machine again at once. There is no undo.