diff --git a/compute/configuration.mdx b/compute/configuration.mdx index 8aba156..1c28c73 100644 --- a/compute/configuration.mdx +++ b/compute/configuration.mdx @@ -106,7 +106,7 @@ env: ## Set variables from a whole ConfigMap or Secret -On `general-purpose` workloads, you can turn every key of a ConfigMap or Secret into an environment variable. To do so with flags, pass `--env-from-configmap` or `--env-from-secret` as `NAME` or `NAME:PREFIX_`. The following command loads every key from `api-config` with the prefix `APP_`, and every key from `api-secrets` without a prefix: +You can turn every key of a ConfigMap or Secret into an environment variable. To do so with flags, pass `--env-from-configmap` or `--env-from-secret` as `NAME` or `NAME:PREFIX_`. The following command loads every key from `api-config` with the prefix `APP_`, and every key from `api-secrets` without a prefix: ```bash datumctl compute deploy WORKLOAD_NAME \ @@ -135,8 +135,6 @@ envFrom: name: api-secrets ``` -The `unikernel` runtime class doesn't support `envFrom`. On `unikernel` workloads, set each variable with `valueFrom` instead. - ## Mount a ConfigMap or Secret as files To mount a ConfigMap or Secret as files with flags, pass `--configmap` or `--secret` as `NAME:/mount/path`. Each key becomes a file in the mount directory. The following command mounts `api-config` at `/etc/api` and `api-secrets` at `/etc/api-secrets`: @@ -322,7 +320,7 @@ spec: minReplicas: 1 ``` -To use this example on the `unikernel` class, change `runtime.class` to `unikernel` and remove the `envFrom` entry. +To use this example on the `unikernel` class, change `runtime.class` to `unikernel`. ## Limits diff --git a/compute/instance-shell.mdx b/compute/instance-shell.mdx index aff38fa..3d1ec74 100644 --- a/compute/instance-shell.mdx +++ b/compute/instance-shell.mdx @@ -10,7 +10,7 @@ A shell session connects you to a container of a running Instance, so you can ru Compute is in preview, and the `v1alpha` API can change. -Shell sessions are available for `general-purpose` Instances only. A `general-purpose` Instance runs in its own virtual machine, so a shell session reaches a real container through that isolation boundary. `unikernel` Instances don't have a shell, so the **Shell** tab and `datumctl compute exec` aren't available for them. For more about the two classes, see [Choose a runtime class](/compute/runtimes/overview). +A `general-purpose` Instance runs in its own virtual machine, so a shell session reaches a real container through that isolation boundary. `datumctl compute exec` also works on `unikernel` Instances, but it can run only programs that your image includes, and a `unikernel` image has no shell unless you add one. The portal **Shell** tab is for `general-purpose` Instances. For more about the two classes, see [Choose a runtime class](/compute/runtimes/overview). ## How a session works @@ -62,7 +62,7 @@ Select **Close shell** to end the session and stop the command. Leaving the page ## datumctl -`datumctl compute exec` runs a command, interactively or once, in a container of a running `general-purpose` Instance. +`datumctl compute exec` runs a command, interactively or once, in a container of a running Instance. ### Before you begin @@ -74,7 +74,7 @@ Select **Close shell** to end the session and stop the command. Leaving the page ``` For more on installing and upgrading plugins, see [Using plugins](/datumctl/plugins/using-plugins). -- Deploy a `general-purpose` workload with at least one `Available` Instance. For more information, see [Run a container image](/compute/runtimes/general-compute). +- Deploy a workload with at least one `Available` Instance. On a `unikernel` workload, the image must include the program that you run, such as a shell. For more information, see [Run a container image](/compute/runtimes/general-compute) or [Build and deploy a unikernel](/compute/runtimes/unikernels). ### Open an interactive shell diff --git a/compute/limitations-and-roadmap.mdx b/compute/limitations-and-roadmap.mdx index c0f0c24..f9a1fb7 100644 --- a/compute/limitations-and-roadmap.mdx +++ b/compute/limitations-and-roadmap.mdx @@ -21,7 +21,7 @@ The Compute preview has the following limitations. For limitations of each [runt - Raw devices, GPUs, and custom virtual machine images aren't available. - Instances with more than one container aren't supported. Run one container per workload. - Health probes, such as readiness and liveness checks, aren't available. An Instance is ready when its containers are running. -- You can't suspend, resume, or snapshot Instances. You can open a shell or run a command in a running `general-purpose` Instance; see [Instance shell sessions](/compute/instance-shell). +- You can't suspend, resume, or snapshot Instances. You can open a shell or run a command in a running Instance; see [Instance shell sessions](/compute/instance-shell). - A workload's runtime class and network can't change after you create it. ### Placement and scaling diff --git a/compute/runtimes/overview.mdx b/compute/runtimes/overview.mdx index d87ce99..b069661 100644 --- a/compute/runtimes/overview.mdx +++ b/compute/runtimes/overview.mdx @@ -22,7 +22,7 @@ The following table compares the two classes: | Startup time | Several seconds, mostly spent booting a kernel and pulling the image. | A fraction of a second after the image is pulled. | | Overhead per Instance | Higher | Very low | | Root filesystem | The image filesystem. | Held in memory, so the unpacked image size counts against the Instance's 2 GiB of memory. | -| Environment variables from a whole ConfigMap or Secret (`envFrom`) | Supported | Not supported. Use `env[].valueFrom` for each key instead. | +| Environment variables from a whole ConfigMap or Secret (`envFrom`) | Supported | Supported | | ConfigMap and Secret volumes | Supported | Supported | | Disk volumes | Not supported | Not supported | | Private registry credentials (`imagePullSecrets`) | Supported | Supported | @@ -34,7 +34,7 @@ The following table compares the two classes: Choose `general-purpose` in the following cases: - You want to run an existing container image without repackaging it. -- Your app needs `envFrom`, extra Linux capabilities, setuid binaries, or a large filesystem. +- Your app needs extra Linux capabilities, setuid binaries, or a large filesystem. Choose `unikernel` in the following cases: diff --git a/compute/runtimes/unikernels.mdx b/compute/runtimes/unikernels.mdx index 9cb52f5..e2e236d 100644 --- a/compute/runtimes/unikernels.mdx +++ b/compute/runtimes/unikernels.mdx @@ -160,7 +160,6 @@ In addition to the [limitations that apply to all of Compute](/compute/limitatio - Images must be packaged with `datumctl compute build`, and must target x86_64. - The root filesystem is held in memory. The unpacked image counts against the Instance's 2 GiB of memory. -- Environment variables from a whole ConfigMap or Secret (`envFrom`) aren't supported. Use `env[].valueFrom` for each key. - Linux capabilities can't be added, and container security context settings have no effect. - Crash details are limited. An Instance whose program exits at startup can stay `Starting` instead of reporting a crash. If an Instance stays `Starting` for more than a few minutes, run `datumctl compute build --analyze` on the image. diff --git a/compute/troubleshooting.mdx b/compute/troubleshooting.mdx index 17eb244..9a617cb 100644 --- a/compute/troubleshooting.mdx +++ b/compute/troubleshooting.mdx @@ -36,7 +36,7 @@ The following table lists common errors and states, what they mean, and how to f | Error or reason | Meaning | What to do | | --- | --- | --- | | `must include a registry` | The image reference has no registry host. | Use a full reference, such as `docker.io/library/redis:7`. | -| `... are not supported by the "CLASS" runtime class` | The workload uses a feature that its runtime class doesn't offer, such as a `disk` volume on either class, or `envFrom` or added capabilities on `unikernel`. | Remove the feature, or deploy a new workload with a class that offers it. See [Choose a runtime class](/compute/runtimes/overview). | +| `... are not supported by the "CLASS" runtime class` | The workload uses a feature that its runtime class doesn't offer, such as a `disk` volume on either class, or added capabilities on `unikernel`. | Remove the feature, or deploy a new workload with a class that offers it. See [Choose a runtime class](/compute/runtimes/overview). | | `resources: Forbidden: not implemented` | The workload sets CPU or memory for a container. | Remove `resources`, and set `runtime.resources.instanceType` to `datumcloud/d1-standard-2`. | | `permission to use the network was denied` | You don't have permission to attach workloads to the network. | Ask a project administrator for the **Network Admin** role. | | `permission to get ... was denied` | You can't read a ConfigMap or Secret that the workload references. | Ask for read access to the object, or reference another object. | diff --git a/guides/migrate-from-vercel.mdx b/guides/migrate-from-vercel.mdx index 02332bb..8ae6628 100644 --- a/guides/migrate-from-vercel.mdx +++ b/guides/migrate-from-vercel.mdx @@ -1,7 +1,7 @@ --- title: "Migrate from Vercel to Compute" sidebarTitle: "Migrate from Vercel" -description: "Move a Node server-rendered app from Vercel to a Datum Compute workload: containerize it, move environment variables into a Secret, deploy, switch your domain, and replace Vercel-only features." +description: "Move a Node server-rendered app from Vercel to a Datum Compute workload: package it as a unikernel, move environment variables into a Secret, deploy, switch your domain, and replace Vercel-only features." --- {/* Draft. Source: the migrate-from-vercel-to-datum-compute recipe (agents.datum.net/recipes), rewritten against the current Compute, ALB and datumctl pages. @@ -11,14 +11,16 @@ description: "Move a Node server-rendered app from Vercel to a Datum Compute wor Compute is in preview, and the `v1alpha` API can change. -This guide moves a Node server-rendered app from Vercel to a Compute workload on the `general-purpose` runtime. When you finish, your app runs as a container with its secrets, a public URL, a rollback path, and deploys from CI. +This guide moves a Node server-rendered app from Vercel to a Compute workload on the `unikernel` runtime class. When you finish, your app runs as a unikernel with its secrets, a public URL, a rollback path, and deploys from CI. + +A unikernel is a single-purpose virtual machine that carries only the operating system code your app uses. It starts in a fraction of a second. You write an ordinary Dockerfile, and `datumctl compute build` packages it into an image that Compute can boot. For more information, see [Build and deploy a unikernel](/compute/runtimes/unikernels). ## How Vercel concepts map to Compute | Vercel | Datum | | --- | --- | | Project | A Datum project, plus one workload for each app and environment | -| Build on push | You build and push a container image, for example in GitHub Actions | +| Build on push | You build and push a unikernel image with `datumctl compute build`, for example in GitHub Actions | | Deployment | A rollout to a new image tag | | Environment variables | A Secret, imported with `--env-from-secret` | | `vercel.app` URL | A `*.datumproxy.net` URL that `deploy` prints | @@ -33,15 +35,18 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on - Install `datumctl` and the `compute` plugin, and log in. For more information, see [Compute commands](/datumctl/compute/overview). - Enable Compute for your project. Compute turns on the first time you run a `datumctl compute` command in the project. For more information, see [Limits and quotas](/compute/limits-and-quotas#enable-compute). - Use an app that runs as a long-lived Node server. Your framework needs a server build, not a Vercel-only build output. +- Use compute plugin v0.12.0 or later, which adds `datumctl compute logs`. To upgrade, run `datumctl plugin upgrade compute`. +- Install the `alb` plugin with `datumctl plugin install alb`. You use it to attach a domain and to set basic authentication. +- Run Docker with BuildKit enabled, and log in to your registry with `docker login`. `datumctl compute build` uses your local Docker credentials. - Choose a place to push images. For a private registry, see [Use images from a private registry](/compute/configuration#use-images-from-a-private-registry). ## Migrate the app - - Vercel builds your app for you. On Compute, you provide the image. The following Dockerfile builds an Astro app with the Node adapter. Adjust the build output paths and the `CMD` for your framework: + + Vercel builds your app for you. On Compute, you provide the image. The following `Dockerfile.datum` builds an Astro app with the Node adapter. `datumctl compute build` uses `Dockerfile.datum` if it exists, and `Dockerfile` otherwise. Adjust the build output paths and the `CMD` for your framework: - ```dockerfile + ```dockerfile Dockerfile.datum FROM node:22-slim AS builder WORKDIR /app COPY package*.json ./ @@ -54,10 +59,9 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on ENV NODE_ENV=production ENV PORT=4321 ENV HOST="::" - COPY --from=builder --chown=node:node /app/dist ./dist - COPY --from=builder --chown=node:node /app/node_modules ./node_modules - COPY --from=builder --chown=node:node /app/package.json ./ - USER node + COPY --from=builder /app/dist ./dist + COPY --from=builder /app/node_modules ./node_modules + COPY --from=builder /app/package.json ./ EXPOSE 4321 CMD ["node", "./dist/server/entry.mjs"] ``` @@ -68,15 +72,24 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on - **Serve plain HTTP on one port.** The load balancer terminates TLS. You pass the port as `--http-port` when you deploy. - **Keep secrets out of the image.** Add `.env*` to `.dockerignore`. Secrets arrive at runtime from a Secret. - **Tag every build with a new, unique tag.** Datum doesn't replace an Instance when the image tag is unchanged, so a moved tag does nothing. + - **Keep the final image small.** A unikernel holds its root filesystem in memory, and the unpacked image counts against the Instance's 2 GiB of memory. Run `npm prune --omit=dev`, as the Dockerfile does, and copy only what the server needs. + - **Include everything the app loads.** The final stage needs Node, its shared libraries, and any native modules. A native module such as `sharp` loads shared libraries at runtime. + + Check the image for compatibility before you push it. The analysis reports a missing library, a wrong architecture, or an entrypoint that needs a shell the image doesn't include: + + ```bash + datumctl compute build --analyze . + ``` - Build and push the image. On Apple Silicon, build for `linux/amd64`: + To apply the Dockerfile changes that the report suggests, run `datumctl compute build --fix .`. The analysis can't detect libraries that your app loads at runtime with `dlopen`, so copy those files into the image yourself. + + Build always targets `linux/amd64`, so you don't need `--platform` on Apple Silicon. Build the image and push it to your registry: ```bash - docker buildx build --platform linux/amd64 \ - -t ghcr.io/ORG/APP:v1.0.0 --push . + datumctl compute build --push --output ghcr.io/ORG/APP:v1.0.0 . ``` - A new GitHub Container Registry package is private, and Datum pulls without credentials unless you configure a pull Secret. Either make the package public in the GitHub package settings, or follow the private registry steps in [Configuration](/compute/configuration#use-images-from-a-private-registry). + A new GitHub Container Registry package is private, and the workload pulls the image anonymously unless you configure a pull Secret. Either make the package public in the GitHub package settings, or follow the private registry steps in [Configuration](/compute/configuration#use-images-from-a-private-registry). @@ -92,7 +105,7 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on Drop the Vercel-only variables, such as `VERCEL`, `VERCEL_URL`, and `VERCEL_ENV`. If your code reads them, replace them with your own variables. - Create a Secret named `APP-secrets` in the `default` namespace, with one key for each variable. For the steps, see [Secrets](/operations/secrets#create-a-secret-with-datumctl). Create it with `datumctl apply`, then check for leftover Vercel placeholders. The following command prints key names only, never values: + Create a Secret named `APP-secrets` in the `default` namespace, with one key for each variable. For the steps, see [Secrets](/operations/secrets#create-a-secret-with-datumctl). Use the same names for the keys as for the variables. Create it with `datumctl apply`, then check for leftover Vercel placeholders. The following command prints key names only, never values: ```bash datumctl get secret APP-secrets -n default -o json \ @@ -105,22 +118,45 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on - Run the command from a folder outside your repository. It writes a `workload.yaml` file into the current folder, which you shouldn't commit: - - ```bash - datumctl compute deploy APP \ - --image=ghcr.io/ORG/APP:v1.0.0 \ - --location=us-central-1 \ - --http-port=4321 \ - --runtime-class=general-purpose \ - --env="HOST=::" \ - --env-from-secret=APP-secrets \ - --yes - ``` + A deploy writes a `workload.yaml` file into the current folder, which you shouldn't commit. Create an empty folder outside your repository, and run the deploy from there. Choose one of the following paths: + + + + Use the image that you built and pushed in the previous steps. This path needs no source files, so you can run it from the empty folder: + + ```bash + datumctl compute deploy APP \ + --image=ghcr.io/ORG/APP:v1.0.0 \ + --location=us-central-1 \ + --http-port=4321 \ + --runtime-class=unikernel \ + --env="HOST=::" \ + --env-from-secret=APP-secrets \ + --yes + ``` + + + This path replaces the separate build and push. `--build` needs your app's source and its `Dockerfile.datum` or `Dockerfile`, so pass the path to your app's root folder. Run the command from the empty folder, and replace `PATH_TO_APP` with that path, such as `../my-app`: + + ```bash + datumctl compute deploy APP \ + --build=PATH_TO_APP \ + --image=ghcr.io/ORG/APP:v1.0.0 \ + --location=us-central-1 \ + --http-port=4321 \ + --runtime-class=unikernel \ + --env="HOST=::" \ + --env-from-secret=APP-secrets \ + --yes + ``` + + Without a value, `--build` uses the current folder, which builds the wrong app if you run the command from the empty folder. The command builds the image, applies the same fixes as `--fix`, which can rewrite your Dockerfile, pushes the image, and deploys it pinned by digest. + + + + `unikernel` is the default runtime class, and naming it makes the choice clear to anyone who reads the command later. A workload keeps its runtime class. To change it, deploy under a new name and destroy the old workload. The last line of the output is the public URL. For the locations that your project can use, see [Placement and scaling](/compute/placement-and-scaling#locations). - - Use `general-purpose` for a standard container image. The `unikernel` runtime needs `datumctl compute build` instead of `docker build`. A workload keeps its runtime class. To change it, deploy under a new name and destroy the old workload. @@ -133,7 +169,7 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on While a rollout runs, the edge can return an HTML error page instead of your app. Poll a health route until it returns `200` before you judge the result. - A new `*.datumproxy.net` hostname might not resolve on your machine right away. Look it up through a public resolver and pin the address: + A new `*.datumproxy.net` hostname might not resolve on your machine right away. Look it up through a public resolver and pin the address. If your machine has no IPv6 route, the request fails with no status code. Pin an IPv4 address from `dig +short A $H @1.1.1.1` instead: ```bash H=HOSTNAME.datumproxy.net @@ -163,7 +199,7 @@ This guide moves a Node server-rendered app from Vercel to a Compute workload on - Vercel deploys on every push. On Compute, build and push the image in your pipeline, then run `datumctl compute deploy` with the new tag. Log in as a service account. For the workflow, see [GitHub Actions](/datumctl/cicd/github-actions), and for service accounts, see [Service accounts](/projects/service-accounts). + Vercel deploys on every push. On Compute, build and push the image in your pipeline with `datumctl compute build --push`, then run `datumctl compute deploy` with the new tag. Log in as a service account. For the workflow, see [GitHub Actions](/datumctl/cicd/github-actions), and for service accounts, see [Service accounts](/projects/service-accounts). A common pattern is a push to `main` that deploys staging, and a published release that deploys production with the release tag. Don't run `destroy` in the pipeline, because it removes the URL and the load balancer settings. @@ -201,7 +237,7 @@ read -s -p "Password: " password && echo printf '%s' "$password" | datumctl alb auth set APP --user admin --password-stdin ``` -Basic authentication protects every route on the load balancer, including health routes, and webhooks that call the URL get `401`. To protect a single route, use a `SecurityPolicy`. For both methods, see [Basic authentication](/alb/authentication/basic-auth). +The credentials can take up to a minute to take effect, and a correct password returns `401` until then. Basic authentication protects every route on the load balancer, including health routes, and webhooks that call the URL get `401`. To protect a single route, use a `SecurityPolicy`. For both methods, see [Basic authentication](/alb/authentication/basic-auth). ## Replace Vercel-only features @@ -216,7 +252,7 @@ Check each feature that your app uses. The examples use Astro and Node, and the | Vercel Cron | Replace it with a GitHub Actions `schedule` workflow that calls a protected endpoint with a bearer secret. Compute has no scheduler. | | BotID | It works only behind Vercel's edge. Replace it, for example with a honeypot field, a minimum form-fill time, and a rate limit for each IP address. | | Runtime Cache (`@vercel/functions`) | Use another cache driver. An in-memory driver is fine for one replica. Invalidation reaches only the Instance that receives it, so use a shared store before you scale out. | -| Image Optimization | The `sharp` image service of Astro works in the container. | +| Image Optimization | The `sharp` image service of Astro can work in the unikernel, but `--analyze` can't confirm it, because `sharp` loads its libraries at runtime. After you deploy, request a page or route that resizes an image with `sharp`, and check that it returns the image. | | `VERCEL_*` variables | Remove them. Read your own variables or the request hostname instead. | @@ -228,20 +264,23 @@ Check each feature that your app uses. The examples use Astro and Node, and the - Preview URLs for each branch aren't available. - Vercel-managed features such as Edge and Serverless Functions, ISR and its cache, Analytics, and Web Vitals have no direct equivalent. Check each one that your app uses. - With more than one replica, the cache and any in-memory state are no longer shared. Add a shared store before you scale out. +- The unikernel holds its root filesystem in memory, and Instances have 1 vCPU and 2 GiB of memory. If your app needs more memory or a large filesystem, it doesn't fit. For all limits, see [Unikernel limitations](/compute/runtimes/unikernels#limitations). - Use scoped tokens in the Secret, not personal ones, before you move real traffic. ## Troubleshooting | Symptom | Cause and fix | | --- | --- | -| The app starts but never answers | The server is bound to `0.0.0.0`. Redeploy with the app listening on `::`, for example with `--env="HOST=::"`. | +| The app starts but never answers, and the edge returns `503` | The server is bound to `0.0.0.0`. Redeploy with the app listening on `::`, for example with `--env="HOST=::"`. | | `Unsupported value` for a location | Datum rejects locations that your project can't use, and the error lists the ones that it accepts. Use one of those. | | The image won't pull | The registry package is private. Make it public, or configure a pull Secret. | +| The workload doesn't boot a plain `docker build` image | The unikernel runtime class needs an image built with `datumctl compute build`. Rebuild and push the image with that command. | | The Secret has `[SENSITIVE]` values | `vercel env pull` can't export Sensitive variables. Get the real values, then run the placeholder check again. | +| The Instance stays `Starting` | The program exited at startup, and the unikernel doesn't report crash details. Run `datumctl compute build --analyze .` to find a missing library, a wrong architecture, or a missing shell. Also check that the app can start with its variables set. | | An HTML error page right after a deploy | The rollout is still in progress. Poll a health route until it returns `200`. | -| `401` on every URL | Basic authentication is on. Send credentials, or remove it with `datumctl alb auth`. | +| `401` on every URL | Basic authentication is on. Send credentials, or remove it with `datumctl alb auth unset APP`. | | A Secret change has no effect | Instances read a Secret only at start. Run `datumctl compute restart APP`. | -| A redeploy of the same tag does nothing | Datum doesn't replace an Instance for an unchanged tag. Use a new tag. | +| A redeploy of the same tag does nothing | Datum doesn't replace an Instance for an unchanged tag. Use a new tag. With `--build`, the deploy pins the image by digest, but a new tag keeps rollbacks clear. | For other problems, see [Compute troubleshooting](/compute/troubleshooting).