Skip to content

Deploy a Custom App from CI

This guide walks through deploying a build of your own Nautobot App to a Nautobot Cloud instance from a CI pipeline, using the same steps the Console performs when you install a custom App from an uploaded package. At the end, your instance is running the App version your pipeline just built.

For a complete, production-ready implementation of everything on this page, see the GitHub Actions example. The snippets below use curl and jq to show each API call.

Before You Start

You need:

  • The built package — a .tar.gz source distribution of your App, for example from poetry build --format sdist or python -m build --sdist.
  • The package's name, version, and module name (the importable Python module Nautobot loads to enable the App — usually the package name with dashes replaced by underscores).
  • Your API token and Organization ID (Before You Start), and the name of the target instance.
export NAUTOBOT_CLOUD_TOKEN="<your-token>"
export ORG_ID="<your-organization-id>"
export INSTANCE_NAME="my-app-develop"

export PACKAGE_NAME="my-nautobot-app"
export MODULE_NAME="my_nautobot_app"
export VERSION="1.4.0.dev42"
export PACKAGE="dist/my_nautobot_app-1.4.0.dev42.tar.gz"

api() { curl -sf -H "Authorization: Token $NAUTOBOT_CLOUD_TOKEN" -H "Content-Type: application/json" -H "App-Id: ci-deploy" "$@"; }

Give every build a unique version

Each package you upload is stored under its name and version, and the same name and version can only be uploaded once. Stamp a development version on each CI build — for example 1.4.0.dev42 using the run number — so every run publishes a distinct version. The example workflow does this for you.

Step 1: Register the App

Your App is registered once per Organization, keyed on its module name. Look it up and register it on the first run:

ADD_ON_ID=$(api "https://nautobot.cloud/api/private/add-on/?organization=$ORG_ID&slug=$MODULE_NAME" | jq -r '.results[0].id // empty')

if [ -z "$ADD_ON_ID" ]; then
  ADD_ON_ID=$(api -X POST "https://nautobot.cloud/api/private/add-on/" -d @- <<JSON | jq -r '.id'
{
  "name": "$PACKAGE_NAME",
  "slug": "$MODULE_NAME",
  "package_name": "$PACKAGE_NAME",
  "addon_type": "app",
  "resource_type": "nautobot",
  "organization": "$ORG_ID",
  "author": "My Team",
  "initial_release_version": "$VERSION",
  "release_date": "$(date +%Y-%m-%d)",
  "description": "Built and deployed from CI."
}
JSON
  )
fi

Step 2: Upload the Package

Register this build as a new version of your App, request an upload URL for it, and upload the package. Then wait until the upload is confirmed.

ADD_ON_VERSION_ID=$(api -X POST "https://nautobot.cloud/api/private/add-on-version/" -d @- <<JSON | jq -r '.id'
{
  "add_on": "$ADD_ON_ID",
  "name": "$PACKAGE_NAME $VERSION",
  "version": "$VERSION",
  "install_source": "uploaded"
}
JSON
)

UPLOAD_URL=$(api "https://nautobot.cloud/api/private/add-on-version/$ADD_ON_VERSION_ID/upload/" | jq -r '.url')
# Upload the file to the returned URL exactly as given, with no extra headers.
curl -sf -X PUT --upload-file "$PACKAGE" "$UPLOAD_URL"

until [ "$(api "https://nautobot.cloud/api/private/add-on-version/$ADD_ON_VERSION_ID/" | jq -r '.upload_status')" = "uploaded" ]; do
  sleep 5
done

If upload_status becomes failed, the package could not be read. Check that it is a valid .tar.gz source distribution and upload it again.

Step 3: Look Up the Instance

Fetch the target instance with depth=2 so its current image is returned in full, including the Apps and static files that image contains:

RESOURCE=$(api "https://nautobot.cloud/api/resource/?org_id=$ORG_ID&name=$INSTANCE_NAME&state__notin=Deleted&depth=2" | jq '.results[0]')
RESOURCE_ID=$(echo "$RESOURCE" | jq -r '.id')

The instance should be Healthy and have no operation in progress before you continue. If a previous Update is still running, wait for it to finish.

Step 4: Define the New Image

An instance's image is defined by a base image (the Nautobot version) plus the Apps and static files built on top of it. Create the image definition for this deployment by taking everything the instance already has and swapping in the new version of your App:

# Start from the image the instance is running (or the one already staged, if any).
CURRENT=$(echo "$RESOURCE" | jq '.pending_image // .image')
BASE_IMAGE=$(echo "$CURRENT" | jq -r '.base_image.id // .id')

# Keep every other App on the image; replace any earlier version of this one.
ADDON_VERSIONS=$(echo "$CURRENT" | jq --arg add_on "$ADD_ON_ID" --arg new "$ADD_ON_VERSION_ID" \
  '[.addon_versions[] | select(.add_on != $add_on) | .id] + [$new]')
STATIC_FILES=$(echo "$CURRENT" | jq '[.static_files[]? | .id]')

IMAGE_ID=$(api -X POST "https://nautobot.cloud/api/image/create-derived-image/" -d @- <<JSON | jq -r '.image.id'
{
  "base_image": "$BASE_IMAGE",
  "addon_versions": $ADDON_VERSIONS,
  "static_files": $STATIC_FILES,
  "organization": "$ORG_ID",
  "resource_type": "nautobot"
}
JSON
)

Nothing is built yet — this only records what the new image should contain. If an identical image already exists, it is reused.

Step 5: Stage the Image and App Configuration

Point the instance at the new image and provide the App's configuration — the equivalent of its PLUGINS_CONFIG entry. Use an empty object if the App needs no configuration.

The configuration you send replaces the App's whole configuration on the instance, including any settings made in the Console. To keep the configuration the instance already has, leave addons out of the request.

api -X PATCH "https://nautobot.cloud/api/resource/$RESOURCE_ID/" -d @- <<JSON
{
  "image": "$IMAGE_ID",
  "addons": { "$MODULE_NAME": { "example_setting": "value" } }
}
JSON

The instance is now Pending Update. You can stage instance settings and Secrets in the same step.

Required settings

If your App declares required_settings, Nautobot refuses to start without them. Provide them in the App configuration here, or the Update will fail. For sensitive values, reference a Secret instead of writing the value into the configuration.

Step 6: Update the Instance

Trigger the Update. Because the staged image is new, the platform builds it first and then deploys it — the same as choosing Update Now in the Console.

api -X POST "https://nautobot.cloud/api/resource/$RESOURCE_ID/rollout/" -d '{}'

Step 7: Wait for the Deployment

Poll the instance until it is Healthy and running the image you staged. Fail the pipeline on a build failure or an Errored state.

while true; do
  R=$(api "https://nautobot.cloud/api/resource/$RESOURCE_ID/")
  STATE=$(echo "$R" | jq -r '.state')
  RUNNING=$(echo "$R" | jq -r '.image')
  BUILD=$(echo "$R" | jq -r '.pending_image_build_status')

  if [ "$BUILD" = "failed" ]; then echo "Image build failed — see the instance's Event History"; exit 1; fi
  if [ "$STATE" = "Errored" ]; then echo "Instance is Errored"; exit 1; fi
  if [ "$STATE" = "Healthy" ] && [ "$RUNNING" = "$IMAGE_ID" ]; then echo "Deployed $VERSION"; break; fi

  sleep 20
done

A build-and-deploy typically takes 10–30 minutes. Set your job timeout accordingly.

  • If the build fails, the instance keeps running its previous image and returns to Pending Update. Open the failed Build Image event in Event History to read the build log.
  • If the instance fails to start on the new image, it moves to Errored. See Instance States for how to recover.

Creating the Instance from CI

To have your pipeline create the instance when it doesn't exist yet (for example, one instance per feature branch), create it with the image and App configuration already in place so it builds and deploys once:

PROJECT_ID="<your-project-id>"

# Pick a base image that supports custom Apps — the preferred image of the newest Nautobot version.
BASE_IMAGE=$(api "https://nautobot.cloud/api/image/?resource_type=nautobot&org_id=$ORG_ID&deleted=false&limit=200" \
  | jq -r '[.results[] | select(.self_service_base_image and (.base_image == null))] | sort_by(.preferred, .version) | last | .id')

IMAGE_ID=$(api -X POST "https://nautobot.cloud/api/image/create-derived-image/" -d @- <<JSON | jq -r '.image.id'
{
  "base_image": "$BASE_IMAGE",
  "addon_versions": $(api "https://nautobot.cloud/api/image/$BASE_IMAGE/?depth=2" | jq --arg new "$ADD_ON_VERSION_ID" '[.addon_versions[].id] + [$new]'),
  "static_files": [],
  "organization": "$ORG_ID",
  "resource_type": "nautobot"
}
JSON
)

api -X POST "https://nautobot.cloud/api/resource/" -d @- <<JSON | jq '{id, name, admin_password}'
{
  "name": "$INSTANCE_NAME",
  "project": "$PROJECT_ID",
  "resource_type": "nautobot",
  "image": "$IMAGE_ID",
  "addons": { "$MODULE_NAME": {} },
  "is_production": false
}
JSON

The response includes the initial admin password. This is the only time it is returned, so capture it from your pipeline's output and change it after first sign-in. Optional fields you can set at creation include config (instance settings), associated_secrets, public, and instance_urls; see the API reference for the full list. Then wait for the instance as in Step 7.

Note

An instance's name, URL prefix, and production flag are set when it is created and can't be changed through this endpoint afterwards.

Good Practices

  • One deployment at a time per instance. Serialize your pipeline so two runs never stage changes on the same instance at once — in GitHub Actions, use a concurrency group.
  • Keep dependencies public. Only your App package is uploaded; its dependencies are resolved from public PyPI when the image is built, so the App must not depend on privately hosted packages.
  • Deploy to Development automatically, promote deliberately. Once a build passes in Development, promote the same image to Staging and Production rather than rebuilding — see Update, Upgrade & Promote.
  • Snapshot before Production. Take a Snapshot as a rollback point before every Production Update.