Skip to content

Deployment Guide

Energy Copilot is deployed using Databricks Asset Bundles (DAB), which manages all resources declaratively via YAML. The deployment creates jobs, pipelines, MLflow experiments, and the Databricks App in a single command.

The confirmed working deployment workflow is:

  1. Build the React frontend with Vite
  2. Import the built files to the Databricks workspace
  3. Deploy the app with databricks apps deploy
RequirementNotes
Databricks WorkspaceServerless-enabled (AWS, Azure, or GCP)
Unity CatalogEnabled on the metastore
SQL WarehouseAt least one warehouse (Serverless Starter is sufficient)
Databricks AppsEnabled on the workspace
LakebaseProvisioned (optional — falls back to SQL Warehouse if absent)
ToolInstall CommandRequired Version
Databricks CLIbrew tap databricks/tap && brew install databricksv0.209.0+
Node.js + npmbrew install nodev18+
Pythonbrew install python@3.113.10+

Verify your CLI version:

Terminal window
databricks version
# Databricks CLI v0.209.0

The backend reads these environment variables at runtime. Set them via the Databricks Apps configuration or the bundle variables.

VariableDescriptionRequired
DATABRICKS_HOSTWorkspace URL (e.g. https://myworkspace.cloud.databricks.com)Yes
DATABRICKS_TOKENPersonal access token or M2M OAuth tokenYes
DATABRICKS_WAREHOUSE_IDSQL Warehouse ID for fallback queriesYes
DATABRICKS_CATALOGUnity Catalog name (default: energy_copilot)Yes
LAKEBASE_INSTANCE_NAMELakebase instance nameOptional
LAKEBASE_HOSTLakebase Postgres hostnameOptional
LAKEBASE_PASSWORDLakebase Postgres passwordOptional
ANTHROPIC_API_KEYOnly needed if NOT using Databricks FMAPI routingOptional
Terminal window
databricks auth login https://your-workspace.cloud.databricks.com --profile=my-profile

Verify authentication:

Terminal window
databricks current-user me --profile=my-profile
# {
# "user_name": "you@company.com",
# "display_name": "Your Name"
# }
Terminal window
git clone https://github.com/sourabhghose/databricks-energy-copilot.git
cd energy-copilot

Before deploying, validate that all YAML is correct and all variable references resolve:

Terminal window
databricks bundle validate --target dev --profile=my-profile

Expected output: no errors. Warnings about missing experiments or models are normal on first deploy.

Terminal window
databricks bundle deploy --target dev --profile=my-profile

This command creates or updates:

Resource TypeWhat Is Created
Jobs14 serverless jobs: setup, ingest (NEMWEB, OpenElec, Weather, Solar, AER, CER LGC, ISP), ML forecast, market summary, data quality, simulator, snapshots
DLT Pipelines4 serverless Delta Live Tables pipelines
MLflow Experiments5 experiments: price, demand, wind, solar, anomaly

Deployment typically takes 2–5 minutes.

Terminal window
databricks bundle run job_00_setup --target dev --profile=my-profile

This job runs 8 tasks:

TaskDescriptionDuration
create_schemasCreates bronze, silver, gold, ml, tools schemas~30s
create_tablesCreates all Delta tables + grants SP permissions~2 min
seed_isp_dataAEMO ISP 2024 projects and capacity outlook~1 min
seed_lgc_dataCER LGC registry + spot prices~1 min
seed_tariff_dataAER CDR retail tariffs + components~1 min
seed_facility_dataOpenNEM facility generation timeseries~1 min
seed_deal_data5 counterparties, 3 portfolios, 50 sample trades~1 min
backfill90 days of synthetic NEM data (~130K rows)15–30 min

Monitor progress:

Terminal window
databricks jobs get-run <RUN_ID> --profile=my-profile
Terminal window
cd app/frontend
npx vite build
# ✓ built in 45.2s
# dist/ created with index.html + assets/

The build output goes to app/frontend/dist/.

Terminal window
# Import the built frontend to the Databricks workspace
databricks workspace import-dir app/frontend/dist \
/Workspace/Users/you@company.com/energy-copilot/frontend \
--profile=my-profile \
--overwrite
Terminal window
databricks apps deploy energy-copilot \
--source-code-path /Workspace/Users/you@company.com/energy-copilot \
--profile=my-profile

The app URL is shown in the output:

App deployed: https://energy-copilot-<workspace-id>.aws.databricksapps.com

The post-deploy script handles resources that require the App to be deployed first:

Terminal window
./post_deploy.sh my-profile dev

This script:

StepDescriptionDuration
Get App SP UUIDLooks up the Service Principal assigned to the App~5s
Grant Lakebase PermsGrants the App SP SELECT on Lakebase gold schema~2 min
Create Synced TablesSets up continuous Delta-to-Postgres sync~3 min
Create Genie SpacesCreates 12 AI/BI Genie spaces~2 min
Terminal window
databricks bundle run job_09_simulator --target dev --profile=my-profile

The simulator writes fresh NEM market data every 30 seconds to all Gold tables. It runs continuously until cancelled.

Terminal window
# Check app health
curl https://<app-url>/health
# Check data source
curl https://<app-url>/api/health/datasource
# Check latest prices
curl https://<app-url>/api/prices/latest

Expected health response:

{
"status": "ok",
"sql_connected": true,
"lakebase_connected": true,
"lakebase_fresh": true
}

For production:

Terminal window
databricks bundle deploy --target prod --profile=prod-profile \
--var="notification_email=ops@mycompany.com"

The prod target uses:

  • mode: production (no [dev] prefixes on resource names)
  • catalog: energy_copilot (production catalog name)
Terminal window
# List all bundle resources
databricks bundle summary --target dev --profile=my-profile
# Check app status
databricks apps get energy-copilot --profile=my-profile
# List jobs
databricks jobs list --profile=my-profile | grep energy-copilot
Terminal window
# Rebuild frontend (if UI changed)
cd app/frontend && npx vite build && cd ../..
# Redeploy (idempotent)
databricks bundle deploy --target dev --profile=my-profile
Terminal window
databricks jobs list --profile=my-profile | grep "Simulator"
databricks jobs cancel-all-runs <JOB_ID> --profile=my-profile
Terminal window
databricks bundle destroy --target dev --profile=my-profile

This removes all bundle-managed resources. Data in Unity Catalog tables is preserved.

bundle validate fails with “warehouse not found”

Section titled “bundle validate fails with “warehouse not found””

The warehouse_id variable uses a name lookup: "Serverless Starter Warehouse". If your warehouse has a different name, override it:

Terminal window
databricks bundle deploy --target dev --var="warehouse_id=<your-warehouse-id>"

Find your warehouse ID:

Terminal window
databricks warehouses list --profile=my-profile
  1. Check /health — verify sql_connected: true
  2. Check /api/health/datasource — verify queries hit real backends
  3. Verify the SQL warehouse is running: databricks warehouses list --profile=my-profile
  4. Check app logs in the Databricks Apps UI → Logs tab
  1. Check synced table status: Unity Catalog > Tables > [table name] > Sync Status
  2. Re-run synced table creation: ./post_deploy.sh my-profile dev
  3. Verify the App SP has SELECT on the Lakebase gold schema

The service_principal_id field is only populated after the App is fully deployed and active. Wait 2–3 minutes after databricks apps deploy completes before running post_deploy.sh.

Genie Spaces API is in preview. The setup/04_create_genie_spaces.py script includes a REST API fallback. If the SDK method fails:

Terminal window
python setup/04_create_genie_spaces.py --use-rest-api --profile=my-profile

Notebook import fails with “already exists”

Section titled “Notebook import fails with “already exists””
Terminal window
databricks workspace import /path/to/notebook.py \
--file=local.py \
--format=SOURCE \
--language=PYTHON \
--overwrite \
--profile=my-profile