# Deployment guide

This page guides you through the Google Cloud Cortex Framework deployment steps
for production-path deployments.

Cortex Framework compiles your declarative YAML configurations
into a complete Dataform project and deploys the generated workspace to
one or more targets: a Google Cloud Dataform repository
(`type: dataform`), a remote or local Git repository (`type: git`), or both in a
single run.

## Before you begin

Complete the following prerequisites before running a production deployment:

1. Satisfy the tool and project setup requirements in [Prerequisites](https://docs.cloud.google.com/cortex/docs/prerequisites.md.txt).
2. Prepare your raw landing datasets or external catalogs as described in [Source system integration](https://docs.cloud.google.com/cortex/docs/source-system-integration/overview.md.txt).
3. If you configure any Git deployment target (`type: git` under `deployment.targets` in `config/config.yaml`), install `git` **version 2.28
   or later** on your workstation or CI/CD runner and configure repository write credentials.

## Configure Identity and Access Management roles

Grant the deploying user or CI/CD service account the following
Identity and Access Management (IAM) roles across your Google Cloud projects.

### Roles for build project


To get the permissions that
you need to build Cortex Framework,

ask your administrator to grant you the
[BigQuery Job User](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.jobUser) (`roles/bigquery.jobUser`) IAM role on your build project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

Grant the role on your build project:

```bash
gcloud projects add-iam-policy-binding BUILD_PROJECT_ID \
  --member="user:USER_EMAIL" \
  --role="roles/bigquery.jobUser"
```

Replace the following:

- `BUILD_PROJECT_ID`: the Google Cloud project ID where schema discovery and compilation jobs execute, for example: `my-cortex-build-project`.
- `USER_EMAIL`: the email address of the deploying user (or use `serviceAccount:SA_EMAIL` for a CI/CD service account), for example: `analyst@example.com`.

### Roles for source project


To get the permissions that
you need to inspect raw source schemas for Cortex Framework,

ask your administrator to grant you the
[BigQuery Data Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) (`roles/bigquery.dataViewer`) IAM role on your source project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

```bash
gcloud projects add-iam-policy-binding SOURCE_PROJECT_ID \
  --member="user:USER_EMAIL" \
  --role="roles/bigquery.dataViewer"
```

Replace the following:

- `SOURCE_PROJECT_ID`: the Google Cloud project ID hosting your raw source datasets or catalog connections, for example: `my-cortex-source-project`.
- `USER_EMAIL`: the email address of the deploying principal, for example: `analyst@example.com`.

### Roles for target projects


To get the permissions that
you need to deploy Cortex Framework,

ask your administrator to grant you the
following IAM roles on your target projects:

- [BigQuery Data Editor](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataEditor) (`roles/bigquery.dataEditor`)
- [Dataform Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/dataform.md.txt#dataform.admin) (`roles/dataform.admin`)
- [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) (`roles/serviceusage.serviceUsageConsumer`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

> [!NOTE]
> **Note:** You can grant Dataform Editor (`roles/dataform.editor`) instead of `roles/dataform.admin` when the target Dataform repository already exists. If all enabled deployment targets use `type: git`, `uv run cortex-deploy` skips Google Cloud target dataset and Dataform API checks, so the deploying principal doesn't need `roles/dataform.admin` or `roles/bigquery.dataEditor` on target projects.

Grant the roles on your target project:

```bash
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
  --member="user:USER_EMAIL" \
  --role="roles/bigquery.dataEditor"
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
  --member="user:USER_EMAIL" \
  --role="roles/dataform.admin"
gcloud projects add-iam-policy-binding TARGET_PROJECT_ID \
  --member="user:USER_EMAIL" \
  --role="roles/serviceusage.serviceUsageConsumer"
```

Replace the following:

- `TARGET_PROJECT_ID`: the destination Google Cloud project ID for BigQuery datasets and Dataform repositories, for example: `my-cortex-target-project`.
- `USER_EMAIL`: the email address of the deploying principal, for example: `analyst@example.com`.

### Roles for Dataform execution

When Dataform executes compiled SQL actions in BigQuery,
it runs under either the default Dataform service agent
(`service-PROJECT_NUMBER@gcp-sa-dataform.iam.gserviceaccount.com`) or a custom service account
configured in `deployment.targets[].targetSettings.serviceAccount`. Grant the
execution service account the following roles:

- **Source projects and external catalog projects** : BigQuery Data Viewer (`roles/bigquery.dataViewer`) on raw landing datasets and external catalog datasets.
- **Target projects** : BigQuery Data Editor (`roles/bigquery.dataEditor`) on foundation, data product, and assertion target datasets, plus BigQuery Job User (`roles/bigquery.jobUser`) on the project hosting the Dataform repository.
- **Custom service account impersonation** (when `targetSettings.serviceAccount` is set): Grant the default Dataform service agent both Service Account Token Creator (`roles/iam.serviceAccountTokenCreator`) and Service Account User (`roles/iam.serviceAccountUser`) on your custom service account, and grant the deploying user Service Account User (`roles/iam.serviceAccountUser`) and Service Account Token Creator (`roles/iam.serviceAccountTokenCreator`) on the custom service account. For a complete `gcloud` example, see [Demo deployment service account setup](https://docs.cloud.google.com/cortex/docs/demo-deployment.md.txt#required-iam-roles-using-service-account).

## Configure deployment settings

Cortex Framework uses a YAML configuration file (by convention,
`config/config.yaml`, copied from `config/config.yaml.example`) to bind source
datasets, target datasets, enabled modules, data quality assertions, and
deployment targets.

Populate the project identifiers for your topology:

- `BUILD_PROJECT_ID` (`buildEnvironment.buildProjectId`): Project where CLI metadata and dry-run queries execute.
- `SOURCE_PROJECT_ID` (`data.datasets[].projectId`): Project hosting raw landing tables.
- `TARGET_PROJECT_ID` (`data.datasets[].projectId`): Destination project for conformed foundation and data product datasets. During `type: dataform` target preflight, when `data.assertionsEnabled` is `true` (the default), Cortex Framework also validates and provisions `defaultAssertionDataset` (default `dataform_assertions`, used by [data quality assertions](https://docs.cloud.google.com/cortex/docs/data-quality-assertions.md.txt)) in every target project.
- `REPO_PROJECT_ID` (`deployment.targets[].targetSettings.repositoryProjectId`): Project hosting your Dataform repository when deploying to `type: dataform`.

For the full schema of every configuration block, see
[Deployment configuration](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt).

### Choose a deployment target (`dataform` or `git`)

Under `deployment.targets` in `config/config.yaml`, you can enable one or more
deployment targets:

- **Google Cloud Dataform workspace (`type: dataform`)** : Creates or reuses a Dataform repository and development workspace in Google Cloud, then reconciles remote files against your compiled `dist/` output. Remote files matching `targetSettings.ignoredPaths` (default `["definitions/custom"]`) are preserved across deployments.
- **Protocol-agnostic Git repository
  (`type: git`)** : Requires Git `2.28` or later on the build host. Validates configuration and payload integrity, clones or initializes the target Git repository, reconciles compiled Dataform artifacts using SHA-256 content hashes, and commits and pushes to `targetSettings.branch` (default `"main"`). Optionally scopes reconciliation to `targetSettings.targetDir` so sibling directories remain untouched. Use `type: git` when your enterprise connects Dataform to GitHub, GitLab, Bitbucket, or internal Git servers through GitOps and pull-request pipelines:
  - **Pre-flight validation** : Before cloning, checks `repositoryUrl` and branch syntax, blocks unsafe `targetDir` paths, verifies `dist/` Dataform descriptors, and probes remote reachability with `git ls-remote` (unless `skipPreflightChecks: true`). Before committing, Cortex Framework also checks that an author email for Git commits is configured using `targetSettings.authorEmail`, `git config user.email`, or both `GIT_AUTHOR_EMAIL` and `GIT_COMMITTER_EMAIL`. This check still runs even if `skipPreflightChecks` is set to `true`.
  - **Supported protocols** : SCP-style SSH (`git@github.com:org/repo.git`), `ssh://...`, `https://...`, `http://...`, and local `file:///path` or file system paths. Non-existent local paths are automatically initialized as bare Git repositories, and inline URL credentials and secrets are redacted in logs.
  - **Authentication (`targetSettings.auth`)** : Supply key or token content in `credentialsEnvVar` or a path in `credentialsPath` (mutually exclusive). Alternatively, rely on your SSH agent or Git credential helper (`allowSystemAuth: true`). For SSH, the deployer configures `GIT_SSH_COMMAND` with `BatchMode=yes` and configurable `strictHostKeyChecking` and `sshKnownHostsPath`. It creates an ephemeral `0600` key file only when you use `credentialsEnvVar` (with `IdentitiesOnly=yes`). When you use `credentialsPath`, SSH points directly to that existing file with `-F /dev/null` and `IdentitiesOnly=yes`. When you provide neither (`allowSystemAuth: true`), SSH uses the host SSH agent and configuration without `-i` or `IdentitiesOnly=yes`. For HTTPS, the deployer injects an ephemeral `0700` `GIT_ASKPASS` helper only when you provide `credentialsEnvVar` or `credentialsPath`. The helper supports `username:token` or a raw personal access token (`x-access-token`).
  - **Commit identity and verified signatures** : Cortex Framework doesn't use a hardcoded default commit email. It requires an email from `targetSettings.authorEmail`, both `GIT_AUTHOR_EMAIL` and `GIT_COMMITTER_EMAIL`, or `git config user.email` (including conditional `includeIf` rules). For repositories enforcing verified GPG or SSH signatures (such as GitHub Enterprise rulesets), omit `targetSettings.authorEmail` when your team shares `config/config.yaml` so Git uses each developer's local signed identity. In headless CI/CD pipelines without global Git configuration, set `targetSettings.authorEmail` or export both `GIT_AUTHOR_EMAIL` and `GIT_COMMITTER_EMAIL`.
  - **Path protection, fast-forward push, and dry-run mode** : Protect repository-owned files from overwrite or deletion with `targetSettings.ignorePatterns` (for example, `["README*", ".github/**", "definitions/custom/**"]`; `.git` is always preserved). Force pushes are disabled, so diverged remote branches fail fast. Set `targetSettings.push: false` to commit locally without pushing, and matching `HEAD` payloads exit as an idempotent no-op without an empty commit.

The following example configures a GitOps deployment target pushing compiled
artifacts into a `dataform/` subdirectory on `main` using an environment
variable token:

```yaml
deployment:
  targets:
    - type: git
      enabled: true
      targetSettings:
        repositoryUrl: https://github.com/ORG_NAME/REPO_NAME.git
        branch: main
        targetDir: dataform
        commitMessage: "Deploy Cortex Framework artifacts {timestamp}"
        authorEmail: DEPLOYER_EMAIL
        push: true
        ignorePatterns:
          - "README*"
          - ".github/**"
          - "definitions/custom/**"
        auth:
          credentialsEnvVar: CORTEX_GIT_TOKEN
          allowSystemAuth: false
```

Replace the following:

- `ORG_NAME`: your target Git organization name, for example: `my-org`.
- `REPO_NAME`: your target Git repository name, for example: `cortex-dataform`.
- `DEPLOYER_EMAIL`: the email address for the Git commit author and committer, for example: `deployer@example.com`. Headless CI/CD runners usually don't have a global `git config user.email` set. When `user.email` isn't set, deployments fail unless you configure `authorEmail` in `config/config.yaml` or export both `GIT_AUTHOR_EMAIL` and `GIT_COMMITTER_EMAIL` in the pipeline environment.

## Execute deployment

> [!NOTE]
> **Note:** Running `uv run cortex-build-and-deploy` or `uv run cortex-deploy` collects anonymous telemetry when a Google Cloud project is involved. To learn more or opt out (`--disable-telemetry`), see [Telemetry](https://docs.cloud.google.com/cortex/docs/telemetry.md.txt).

Run `cortex-build-and-deploy` to validate prerequisites, compile all enabled
modules and assertions into `dist/`, and synchronize every enabled deployment
target:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml

uv run cortex-build-and-deploy --config $CORTEX_CONFIG_FILE
```

When deploying to `type: git` interactively, both `uv run cortex-deploy` and
`uv run cortex-build-and-deploy` prompt for confirmation before creating a
missing remote branch or overwriting or deleting tracked files outside
`ignorePatterns`. In automated CI/CD pipelines, pass `-y` (or `--yes`) to
auto-confirm these prompts non-interactively:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml

uv run cortex-build-and-deploy \
  --config $CORTEX_CONFIG_FILE \
  --yes
```

To validate compiled Dataform SQL and assertion definitions locally
before deploying, run
[`uv run cortex-compile`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-compile.md.txt) (pass
`--dist-dir dist` after `uv run cortex-build` for strictly offline graph
compilation).

> [!NOTE]
> **Note:** When syncing to a remote Dataform workspace (`type: dataform`), any unmanaged files outside `targetSettings.ignoredPaths` (default `definitions/custom`) are overwritten or deleted on the next deployment run.

## Command-line tools


Use the following `uv run` CLI entry points to separate build, validation, and
deployment stages across CI/CD environments:

- [`uv run cortex-build`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-build.md.txt): Compiles YAML configurations, source schemas, and assertions into local Dataform artifacts (`dist/`).
- [`uv run cortex-compile`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-compile.md.txt): Compiles the Dataform dependency graph locally (offline when passed `--dist-dir`) to validate SQL and assertion definitions before deployment.
- [`uv run cortex-deploy`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-deploy.md.txt): Deploys an already-built `dist/` directory to enabled `dataform` and `git` targets without modifying live BigQuery tables.
- [`uv run cortex-build-and-deploy`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-build-and-deploy.md.txt): Runs compilation and target synchronization in a single command.
- [`uv run cortex-apply-security`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-apply-security.md.txt): Reconciles BigQuery column policy tags and stale row access policies after Dataform workflow execution for both `type: dataform` and `type: git` targets (supports `--dry-run` for a read-only preview).

## Upgrade from v7.0 to v7.1

To upgrade an existing Cortex Framework version 7.0.x deployment
to version 7.1, follow the standard workflow in
[Upgrade Cortex Framework](https://docs.cloud.google.com/cortex/docs/upgrade/overview.md.txt)
together with the version-specific steps, SAP column rename map, and targeted
full-refresh table lists in
[Upgrade to version 7.1](https://docs.cloud.google.com/cortex/docs/upgrade/v7-1.md.txt). You can also run the
`/upgrade-cortex`
[agent skill](https://docs.cloud.google.com/cortex/docs/agentic-skills-for-data-product-building.md.txt) to inspect
and update configuration files.

If your deployment enables `cortex_v6_compatibility`, `stock_weekly_snapshots`
and `stock_monthly_snapshots` rebuild automatically on their first version 7.1
incremental run for both SAP S/4HANA and SAP ECC (see
[Inventory snapshots](https://docs.cloud.google.com/cortex/docs/v6-compatibility.md.txt#inventory-snapshots)).

## Next steps

- [Post-deployment steps](https://docs.cloud.google.com/cortex/docs/post-deployment-steps.md.txt): Execute your Dataform workflows and verify materialized tables in BigQuery.
- [Row- and column-level security](https://docs.cloud.google.com/cortex/docs/row-and-column-security.md.txt): Configure column policy tags, row access policies, and `uv run cortex-apply-security` reconciliation.
- [Data quality assertions](https://docs.cloud.google.com/cortex/docs/data-quality-assertions.md.txt): Configure blocking and severity-tagged validation rules on foundation and product tables.
- [Knowledge Catalog
  integration](https://docs.cloud.google.com/cortex/docs/knowledge-catalog): Register and govern deployed data products.
- [Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt): Build custom data products in an isolated namespace.