DeployKit

Deploying

Options, progress, readiness and capabilities.

import { Effect } from "effect"
import { Deploykit } from "@deploykit/core"

const publish = Effect.gen(function* () {
  const deploykit = yield* Deploykit.Deploykit
  return yield* deploykit.deploy(appId, artifact, options)
  // or straight from a directory:
  // return yield* deploykit.deployDirectory(appId, "./build", options)
})

deploy returns once the host has created the deployment and given it an id. The build usually carries on after that, so wait for it.

What happens during a deploy

  1. Validate. Paths, sizes and options are checked. Unsupported options fail here, before any network call.
  2. Hash. Each file is hashed the way the host expects.
  3. Negotiate. deploykit asks the host which files it already has, and skips those.
  4. Upload. Missing files are uploaded in parallel, within the memory and disk budgets.
  5. Create. The host creates the deployment. This is the one step that's never retried.

Options

These work on every provider.

OptionTypeWhat it does
target"production" | "preview"Where to deploy. Defaults to production.
onProgress(event) => voidProgress updates. See below.
signalAbortSignalCancel the call. Promise API only; see Lifecycle.

Provider-specific options are on the Vercel and Cloudflare pages. A provider that doesn't support an option rejects it before uploading anything, rather than ignoring it.

Progress

The callback returns an Effect.

const publish = Effect.gen(function* () {
  const deploykit = yield* Deploykit.Deploykit
  return yield* deploykit.deploy(appId, artifact, {
    onProgress: event => Effect.logInfo("deploy progress", event)
  })
})
EventFieldsSent
Hashingdone, totalWhile hashing files
Uploadingdone, total, bytesAs the host confirms uploads
ThrottledretryAfterMs?When the host rate-limits
CreateddeploymentIdOnce, when the deployment exists

bytes counts only bytes the host confirmed, excluding files it already had and repeated attempts. The callback must be quick: each call is cut off after 100 ms, and its errors are ignored. Progress isn't a receipt. Save the Deployment that deploy returns.

Waiting until it's ready

A deployment goes pending → deploying → deployed or failed. Poll getDeployment until the status is final.

import { Effect, Schedule } from "effect"
import { Deploykit, Provider } from "@deploykit/core"

const waitUntilReady = (appId: string, deploymentId: string) =>
  Effect.gen(function* () {
    const deploykit = yield* Deploykit.Deploykit
    return yield* deploykit.getDeployment(appId, deploymentId).pipe(
      Effect.repeat({
        until: d => Provider.isTerminal(d.status),
        schedule: Schedule.spaced("1 second")
      }),
      Effect.timeout("5 minutes")
    )
  })

A failed deployment may have a reason from the host.

Checking it serves

deployed means the host finished, not that the URL answers yet. waitUntilServing polls the URL until it returns a 2xx, for up to 60 seconds.

import { Platform } from "@deploykit/core"

const check = Platform.waitUntilServing(ready.url!, { timeoutMs: 60_000 })
OptionDefaultWhat it does
timeoutMs60000Overall deadline, including every request
accept2xx(status) => boolean for success
fetchglobal fetchCustom transport; must honour the abort signal

It resolves with the status it accepted, or fails with NotServingError (with the last status seen and waitedMs). It doesn't follow redirects, so a login page never counts as success. After this, run your own checks: only you know what "working" means for your app.

Capabilities

Providers differ. Check before offering a feature:

const caps = Effect.map(Deploykit.Deploykit, deploykit => deploykit.capabilities)
Fieldtrue meansVercelPages
deferredActivationYou can stage now and go live laterYesNo
reconciliationYou can recover a lost responseYesNo
previewDeploymentstarget: "preview" worksYesWith previewBranch
adoptByNamefindAppByName worksYesYes
accessModesWhich access settings workAllNone

listDeployments, deleteDeployment and rollback also have capability flags. The current HTTP adapters implement them; a custom provider can omit them. See deployment management.

Calling something unsupported fails with UnsupportedError.

Last updated on

On this page