Skip to Content
Docs

Deploy and Update

Deploy reviewed application images to a Site Worker, verify the result, and return to a previous image.

Deploy a Site application by building and pushing an image, then saving that image selection on its Site Worker. Pushing an image alone does not update the Worker.

In this guide, a release is a versioned GitHub Release of your application repository, such as v1.2.0. A deployment updates a Site Worker to run an application image. Publishing a release deploys it only when automatic deployment is enabled.

Start with the Quickstart to create the Site and its first Worker. This guide updates that existing deployment.

If a Site update also requires changes to Service-managed components, follow Coordinate Worker Deployments and Service Releases to plan deployment order and recovery.

Prepare and Review the Code

Develop and test the application locally, including protected routes and sign-in when the Site uses authentication. For the Astro starter, check the production build in Worker mode:

Terminal
DEPLOYMENT=WORKER yarn build

Review the application changes through your repository's pull request process. Keep site-auth.local.json and other local credentials out of commits and images.

The starter's Publish workflow runs on pushes to main. If you release from another branch, set on.push.branches in .github/workflows/publish.yaml and baseBranch in .changeset/config.json to match.

For Publish to open the Version Packages pull request, go to the GitHub repository's Settings > Actions > General. Under Workflow permissions, enable Allow GitHub Actions to create and approve pull requests and save. If organization policy blocks this setting, deploy manually with the CLI.

If your repository uses Changesets and the Publish workflow, retain its release preparation convention:

  1. Run yarn changeset on the application branch. Select the package, version increase, and summary, then include the generated .changeset/ file in the application pull request.
  2. Review and merge that pull request into the configured release branch. The workflow creates or updates the Version Packages pull request.
  3. Review and merge Version Packages to update the package version and changelog. Build the deployment image from the reviewed release commit.

Choose how to deploy:

Deployment Method Use
Your repository includes .github/workflows/deploy.yaml, named Deploy a release. Deploy a Published Release
You want to configure your own GitHub workflow. Deploy from GitHub
You want to deploy manually with the CLI. Deploy an Application Image

Earlier Publish workflows only attach a tarball to a GitHub Release. They do not build application images or deploy them.

Deploy an Application Image

Complete the Worker CLI setup. Replace my-config with the configuration for the intended tenant and my-site-web with the existing Site Worker ID. Local image builds require Docker; selecting an already pushed image does not.

Before updating, inspect the Worker and record its current pinned application image reference and saved configuration version. You need them to roll back. See Understand the Site Binding for the different deployment selections.

From the application repository root at the reviewed commit, build and push a uniquely tagged image. Replace 1.2.0 with your release version or another unique build tag:

Terminal
ctxl workers images push my-site-web \
  --context . \
  --tag 1.2.0 \
  --config-id my-config \
  --pretty

This builds the application's Dockerfile for linux/amd64 and prints an image reference with its registry digest. It prepares the image without saving or deploying a Worker.

Copy the returned reference into the template's IMAGE option, replacing the placeholder inside the quotes:

Terminal
ctxl workers update my-site-web \
  --option 'IMAGE=<returned-image-reference>' \
  --config-id my-config \
  --pretty

The update retains the saved managed template, Site binding, other options, and runtime settings. It saves a new Worker configuration version and starts deployment with the selected image pinned to its digest. Record the returned version and pinned image reference. Reusing a tag does not change the image pinned in an earlier Worker configuration.

Use --option IMAGE=... for this managed Worker. The --image flag selects a single-image Worker and cannot be combined with --managed. For a combined build, push, and update, use the Quickstart's --build . update; it builds the Site application's Dockerfile.

Deploy from GitHub

For a repository with the generated contextual-deploy.env at its root, use this step in the shared GitHub workflow after checkout. The Action reads the Worker ID, size, managed template, build directory, and Site binding from the file. The GitHub Connection must cover the repository. Use the target tenant ID for the repository variable CONTEXTUAL_ORGANIZATION if you set up the repository yourself.

YAML
- uses: ContextualIO/deploy-workers-action@v1
  with:
    organization: ${{ vars.CONTEXTUAL_ORGANIZATION }}
    folders: .

For a repository without the generated file, add contextual-deploy.env with the Worker settings listed below, or supply the equivalent worker, worker-size, and args inputs to the Action. Create the Site and any Auth Profile it needs in the target tenant before deployment.

The Action uses v<version> from package.json as the image tag. Give each changed build a new version because the Action reuses previously pushed tags. It creates a missing Worker or updates an existing one. After the deployment job finishes, verify the deployed Site.

Deploy a Published Release

These steps apply to repositories with the Worker-enabled Publish workflow in .github/workflows/publish.yaml and Deploy a release in .github/workflows/deploy.yaml. If those workflows are absent, use the CLI procedure above or the custom GitHub workflow.

Check the root contextual-deploy.env in the release commit. Both repository creation and ZIP download generate this file with the following settings:

Setting Generated value
CONTEXTUAL_WORKER The Deployed Worker ID chosen during initialization.
CONTEXTUAL_WORKER_SIZE small, the size to use when creating the Worker.
CONTEXTUAL_DEPLOY_ARGS The selected --managed template and version, --build . to build the application's Dockerfile, and --option SITE_ID=... to bind the saved Site.

Create repository also sets the following GitHub Actions variables. If you uploaded the ZIP to GitHub yourself, connect the repository and add these variables before using the workflows:

Repository variable Value
CONTEXTUAL_ORGANIZATION The target tenant identifier.
CONTEXTUAL_DEPLOYMENT_TYPE WORKER to skip the legacy tarball build.
CONTEXTUAL_TEMPLATE_BRANCH The starter branch used to initialize the source, for template updates.

Keep the Worker settings in the generated file. Set the optional repository variable CONTEXTUAL_DEPLOY_ON_RELEASE=true only if you want publication to trigger deployment.

Check the release branch and GitHub Actions permissions, then prepare the release with Changesets. After you merge Version Packages, Publish builds and pushes the application image for CONTEXTUAL_WORKER, then publishes the release v<version> from package.json. A failed image build prevents that release from being published. With CONTEXTUAL_DEPLOY_ON_RELEASE=true, the workflow then deploys it; check the deployment job and verify the deployed Site.

To deploy a release manually, check the Worker ID, managed template and version, and SITE_ID in the selected tag's contextual-deploy.env before running the workflow. Deploy a release checks out that tag, and values in its file take precedence over the corresponding Action inputs. An older tag can target a different Worker or restore an earlier template or Site binding.

  1. In the repository's Actions tab, select Deploy a release, then Run workflow.
  2. Enter the existing release tag, such as v1.2.0, and run the workflow.
  3. Wait for the deployment job to finish, then verify the deployed Site.

The workflow reuses images under the release's version tag when available. If an image is missing, the Action can build it from that release. For an earlier version, see compatibility checks and image-only rollback.

CONTEXTUAL_DEPLOYMENT_TYPE controls the release workflow's legacy build. The separate DEPLOYMENT=WORKER setting controls the Astro build mode and is set by the starter Dockerfile. Do not add --tag to CONTEXTUAL_DEPLOY_ARGS: both release workflows use v<version> from package.json, so deployment can reuse the image that Publish built.

Verify the Deployment

Follow Deploy and Verify to check readiness, expected content, and sign-in and sign-out at the Public Worker URL. Repeat the browser checks at any custom domain in use.

Use Inspect and Verify for CLI inspection and Worker Troubleshooting when the expected image or behavior does not appear.

Return to a Previous Image

Before rolling back, check that the earlier code is compatible with the current data, Auth Profile, Site configuration, managed template, and Worker settings. If the template or settings also need to change, review those changes separately.

For an image-only rollback, update the same Worker's IMAGE option with the previous pinned application image reference.

Terminal
ctxl workers update my-site-web \
  --option 'IMAGE=<previous-pinned-image-reference>' \
  --config-id my-config \
  --pretty

This creates a new Worker configuration version using the earlier image and retains the current template, Site binding, other options, and runtime settings. Repeat deployment verification, including actual serving content and sign-in/sign-out, before treating the rollback as complete.