次の方法で共有


Databricks アセット バンドルの構成

この記事では、Databricks アセット バンドルを定義する Databricks アセット バンドル構成ファイルの構文について説明します。 「Databricks アセット バンドルとは」をご覧ください。

バンドルを作成して使用するには、「 Databricks アセット バンドルの開発」を参照してください。

バンドル構成リファレンスについては、「 構成リファレンス」を参照してください

databricks.yml

バンドルには、バンドル プロジェクト フォルダーのルートに databricks.yml という名前の構成ファイルが 1 つだけ含まれている必要があります。 databricks.yml はバンドルを定義するメイン構成ファイルですが、リソース構成ファイルなどの他の構成ファイルを include マッピングで参照できます。 バンドル構成は YAML で表されます。 YAML の詳細については、公式の YAML 仕様を参照してください。

最も簡単な databricks.yml では、必要な最上位レベルのマッピングとターゲットのデプロイであるバンドル名を定義します。

bundle:
  name: my_bundle

targets:
  dev:
    default: true

すべての最上位マッピングの詳細については、「 構成リファレンス」を参照してください

ヒント

Databricks アセット バンドルの Python サポートを使用すると、Python でリソースを定義できます。 Python でのバンドル構成を参照してください。

仕様

次の YAML 仕様では、Databricks アセット バンドルの最上位レベルの構成キーを提供します。 構成リファレンスについては、「構成リファレンス」を参照してください。

# This is the default bundle configuration if not otherwise overridden in
# the "targets" top-level mapping.
bundle: # Required.
  name: string # Required.
  databricks_cli_version: string
  cluster_id: string
  deployment: Map
  git:
    origin_url: string
    branch: string

# This is the identity to use to run the bundle
run_as:
  - user_name: <user-name>
  - service_principal_name: <service-principal-name>

# These are any additional configuration files to include.
include:
  - '<some-file-or-path-glob-to-include>'
  - '<another-file-or-path-glob-to-include>'

# These are any scripts that can be run.
scripts:
  <some-unique-script-name>:
    content: string

# These are any additional files or paths to include or exclude.
sync:
  include:
    - '<some-file-or-path-glob-to-include>'
    - '<another-file-or-path-glob-to-include>'
  exclude:
    - '<some-file-or-path-glob-to-exclude>'
    - '<another-file-or-path-glob-to-exclude>'
  paths:
    - '<some-file-or-path-to-synchronize>'

# These are the default artifact settings if not otherwise overridden in
# the targets top-level mapping.
artifacts:
  <some-unique-artifact-identifier>:
    build: string
    dynamic_version: boolean
    executable: string
    files:
      - source: string
    path: string
    type: string

# These are for any custom variables for use throughout the bundle.
variables:
  <some-unique-variable-name>:
    description: string
    default: string or complex
    lookup: Map
    type: string # The only valid value is "complex" if the variable is a complex variable, otherwise do not define this key.

# These are the default workspace settings if not otherwise overridden in
# the targets top-level mapping.
workspace:
  artifact_path: string
  auth_type: string
  azure_client_id: string # For Azure Databricks only.
  azure_environment: string # For Azure Databricks only.
  azure_login_app_id: string # For Azure Databricks only. Reserved for future use.
  azure_tenant_id: string # For Azure Databricks only.
  azure_use_msi: true | false # For Azure Databricks only.
  azure_workspace_resource_id: string # For Azure Databricks only.
  client_id: string # For Databricks on AWS only.
  file_path: string
  google_service_account: string # For Databricks on Google Cloud only.
  host: string
  profile: string
  resource_path: string
  root_path: string
  state_path: string

# These are the permissions to apply to resources defined
# in the resources mapping.
permissions:
  - level: <permission-level>
    group_name: <unique-group-name>
  - level: <permission-level>
    user_name: <unique-user-name>
  - level: <permission-level>
    service_principal_name: <unique-principal-name>

# These are the resource settings if not otherwise overridden in
# the targets top-level mapping.
resources:
  apps:
    <unique-app-name>:
      # See the REST API create request payload reference for apps.
  clusters:
    <unique-cluster-name>:
      # See the REST API create request payload reference for clusters.
  dashboards:
    <unique-dashboard-name>:
      # See the REST API create request payload reference for dashboards.
  experiments:
    <unique-experiment-name>:
      # See the REST API create request payload reference for experiments.
  jobs:
    <unique-job-name>:
      # See REST API create request payload reference for jobs.
  model_serving_endpoint:
    <unique-model-serving-endpoint-name>:
    # See the model serving endpoint request payload reference.
  models:
    <unique-model-name>:
      # See the REST API create request payload reference for models (legacy).
  pipelines:
    <unique-pipeline-name>:
      # See the REST API create request payload reference for :re[LDP] (pipelines).
  quality_monitors:
    <unique-quality-monitor-name>:
    # See the quality monitor request payload reference.
  registered_models:
    <unique-registered-model-name>:
    # See the registered model request payload reference.
  schemas:
    <unique-schema-name>:
      # See the Unity Catalog schema request payload reference.
  secret_scopes:
    <unique-secret-scope-name>:
      # See the secret scope request payload reference.
  volumes:
    <unique-volume-name>:
    # See the Unity Catalog volume request payload reference.

# These are the targets to use for deployments and workflow runs. One and only one of these
# targets can be set to "default: true".
targets:
  <some-unique-programmatic-identifier-for-this-target>:
    artifacts:
      # See the preceding "artifacts" syntax.
    bundle:
      # See the preceding "bundle" syntax.
    default: boolean
    git: Map
    mode: string
    permissions:
      # See the preceding "permissions" syntax.
    presets:
      <preset>: <value>
    resources:
      # See the preceding "resources" syntax.
    sync:
      # See the preceding "sync" syntax.
    variables:
      <preceding-unique-variable-name>: <non-default-value>
    workspace:
      # See the preceding "workspace" syntax.
    run_as:
      # See the preceding "run_as" syntax.

このセクションでは、バンドルのしくみと構成の構成方法を理解するのに役立つ基本的な例をいくつか示します。

バンドル機能と一般的なバンドルのユース ケースを示す構成例については、「バンドルの構成例」と、「GitHub のバンドル例のリポジトリ」を参照してください。

次のバンドル構成例では、バンドル構成ファイル hello.pyと同じディレクトリにある databricks.yml という名前のローカル ファイルを指定します。 指定されたクラスター ID を持つリモート クラスターを使用すると、このノートブックがジョブとして実行されます。 リモート ワークスペースの URL とワークスペース認証資格情報は、という名前の呼び出し元のローカルDEFAULTから読み取られます。

bundle:
  name: hello-bundle

resources:
  jobs:
    hello-job:
      name: hello-job
      tasks:
        - task_key: hello-task
          existing_cluster_id: 1234-567890-abcde123
          notebook_task:
            notebook_path: ./hello.py

targets:
  dev:
    default: true

次の例では、別のリモート ワークスペース URL とワークスペース認証資格情報を使用する名前 prod を持つターゲットを追加します。これは、呼び出し元の .databrickscfg ファイルの一致する host エントリから、指定したワークスペース URL で読み取られます。 このジョブでは同じノートブックを実行しますが、指定されたクラスター ID を持つ別のリモート クラスターを使用します。

バンドル構成ファイルの移植性を高めるために、Databricks では可能な限り host マッピングの代わりに default マッピングを使用することをお勧めします。 hostマッピングを設定すると、Databricks CLI は、.databrickscfg ファイル内で一致するプロファイルを検索し、そのプロファイルのフィールドを使用して、使用する Databricks 認証の種類を決定するように指示します。 一致する host フィールドを持つ複数のプロファイルが存在する場合は、バンドル コマンドの --profile オプションを使用して、使用するプロファイルを指定する必要があります。

notebook_task マッピングが明示的に prod マッピング内で、オーバーライドされていない場合は、最上位の notebook_task マッピング内の resources マッピングを使用するようにフォールバックされるため、notebook_task マッピング内の prod マッピングを宣言する必要はありません。

bundle:
  name: hello-bundle

resources:
  jobs:
    hello-job:
      name: hello-job
      tasks:
        - task_key: hello-task
          existing_cluster_id: 1234-567890-abcde123
          notebook_task:
            notebook_path: ./hello.py

targets:
  dev:
    default: true
  prod:
    workspace:
      host: https://<production-workspace-url>
    resources:
      jobs:
        hello-job:
          name: hello-job
          tasks:
            - task_key: hello-task
              existing_cluster_id: 2345-678901-fabcd456

次の バンドル コマンド を使用して、 dev ターゲット内でこのジョブを検証、デプロイ、および実行します。 バンドルのライフサイクルの詳細については、「 Databricks アセット バンドルの開発」を参照してください。

# Because the "dev" target is set to "default: true",
# you do not need to specify "-t dev":
databricks bundle validate
databricks bundle deploy
databricks bundle run hello_job

# But you can still explicitly specify it, if you want or need to:
databricks bundle validate
databricks bundle deploy -t dev
databricks bundle run -t dev hello_job

代わりに、prod ターゲット内でこのジョブを検証、デプロイおよび実行するには:

# You must specify "-t prod", because the "dev" target
# is already set to "default: true":
databricks bundle validate
databricks bundle deploy -t prod
databricks bundle run -t prod hello_job

バンドル間での定義と設定のモジュール化と再利用を強化するには、バンドル構成を別のファイルに分割します。

# databricks.yml

bundle:
  name: hello-bundle

include:
  - '*.yml'
# hello-job.yml

resources:
  jobs:
    hello-job:
      name: hello-job
      tasks:
        - task_key: hello-task
          existing_cluster_id: 1234-567890-abcde123
          notebook_task:
            notebook_path: ./hello.py
# targets.yml

targets:
  dev:
    default: true
  prod:
    workspace:
      host: https://<production-workspace-url>
    resources:
      jobs:
        hello-job:
          name: hello-job
          tasks:
            - task_key: hello-task
              existing_cluster_id: 2345-678901-fabcd456