Konfigurasi Bundel Otomatisasi Deklaratif

Artikel ini menguraikan sintaks untuk file konfigurasi bundel, yang menentukan Bundel Otomatisasi Deklaratif (sebelumnya dikenal sebagai Bundel Aset Databricks). Lihat Apa itu Bundel Otomatisasi Deklaratif?.

Untuk membuat dan bekerja dengan bundel, lihat Mengembangkan Bundel Otomatisasi Deklaratif.

Untuk referensi konfigurasi bundel, lihat Referensi konfigurasi.

databricks.yml

Bundel harus berisi satu (dan hanya satu) file konfigurasi bernama databricks.yml di akar folder proyek bundel. databricks.yml adalah file konfigurasi utama yang menentukan bundel, tetapi dapat mereferensikan file konfigurasi lain, seperti file konfigurasi sumber daya, dalam include pemetaan. Konfigurasi bundel dinyatakan dalam YAML. Untuk informasi selengkapnya tentang YAML, lihat spesifikasi YAML resmi.

Yang paling databricks.yml sederhana mendefinisikan nama bundel, yang merupakan pemetaan tingkat atas yang diperlukan, dan penyebaran target.

bundle:
  name: my_bundle

targets:
  dev:
    default: true

Untuk detail tentang semua pemetaan tingkat atas, lihat Referensi konfigurasi.

Petunjuk / Saran

Dukungan Python untuk Bundel Otomatisasi Deklaratif memungkinkan Anda menentukan sumber daya di Python. Lihat Konfigurasi bundel di Python.

Spesifikasi

Spesifikasi YAML berikut menyediakan kunci konfigurasi tingkat atas untuk Bundel Otomatisasi Deklaratif. Untuk referensi konfigurasi lengkap, lihat Referensi konfigurasi dan sumber daya Bundel Automation Deklaratif.

# 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 workspace settings if not otherwise overridden in
# the targets top-level mapping.
workspace:
  artifact_path: string
  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:
  alerts:
    <unique-alert-name>:
      # alert settings
  apps:
    <unique-app-name>:
      # app settings
  catalogs:
    <unique-catalog-name>:
      # catalog settings
  clusters:
    <unique-cluster-name>:
      # cluster settings
  dashboards:
    <unique-dashboard-name>:
      # dashboard settings
  database_catalogs:
    <unique-database-catalog-name>:
      # database catalog settings
  database_instances:
    <unique-database-instance-name>:
      # database instance settings
  experiments:
    <unique-experiment-name>:
      # experiment settings
  jobs:
    <unique-job-name>:
      # job settings
  model_serving_endpoints:
    <unique-model-serving-endpoint-name>:
    # model_serving_endpoint settings
  pipelines:
    <unique-pipeline-name>:
      # pipeline settings
  postgres_branches:
    <unique-postgres-branch-name>:
      # postgres branch settings
  postgres_endpoints:
    <unique-postgres-endpoint-name>:
      # postgres endpoint settings
  postgres_projects:
    <unique-postgres-project-name>:
      # postgres project settings
  quality_monitors:
    <unique-quality-monitor-name>:
    # quality monitor settings
  registered_models:
    <unique-registered-model-name>:
    # registered model settings
  schemas:
    <unique-schema-name>:
      # schema settings
  secret_scopes:
    <unique-secret-scope-name>:
      # secret scopes settings
  sql_warehouses:
    <unique-sql-warehouse-name>:
      # sql warehouse settings
  synced_database_tables:
    <unique-synced-database-table-name>:
      # synced database table settings
  volumes:
    <unique-volume-name>:
    # volumes settings

# 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:
      # artifact build settings for this target
    bundle:
      # bundle settings for this target
    default: boolean
    git: Map
    mode: string
    permissions:
      # permissions for this target
    presets:
      <preset>: <value>
    resources:
      # resource settings for this target
    sync:
      # sync settings for this target
    variables:
      <defined-variable-name>: <non-default-value> # value for this target
    workspace:
      # workspace settings for this target
    run_as:
      # run_as settings for this target

Contoh

Bagian ini berisi beberapa contoh dasar untuk membantu Anda memahami cara kerja bundel dan cara menyusun konfigurasi.

Catatan

Untuk contoh konfigurasi yang menunjukkan fitur bundel dan kasus penggunaan bundel umum, lihat Contoh konfigurasi bundel dan repositori contoh bundel di GitHub.

Contoh konfigurasi bundel berikut menentukan file lokal bernama hello.py yang berada di direktori yang sama dengan file databricks.ymlkonfigurasi bundel . Ini menjalankan notebook ini sebagai pekerjaan menggunakan kluster jarak jauh dengan ID kluster yang ditentukan. URL ruang kerja jarak jauh dan kredensial autentikasi ruang kerja dibaca dari profil konfigurasi lokal penelepon bernama 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

Contoh berikut menambahkan target dengan nama prod yang menggunakan URL ruang kerja jarak jauh dan kredensial autentikasi ruang kerja yang berbeda, yang dibaca dari entri pencocokan .databrickscfg file pemanggil host dengan URL ruang kerja yang ditentukan. Pekerjaan ini menjalankan notebook yang sama tetapi menggunakan kluster jarak jauh yang berbeda dengan ID kluster yang ditentukan.

Catatan

Databricks merekomendasikan agar Anda menggunakan host pemetaan alih-alih default pemetaan sedapat mungkin, karena ini membuat file konfigurasi bundel Anda lebih portabel. host Mengatur pemetaan menginstruksikan Databricks CLI untuk menemukan profil yang cocok dalam file Anda .databrickscfg lalu menggunakan bidang profil tersebut untuk menentukan jenis autentikasi Databricks mana yang akan digunakan. Jika ada beberapa profil dengan bidang yang host cocok, maka Anda harus menggunakan --profile opsi pada perintah bundel untuk menentukan profil yang akan digunakan.

Perhatikan bahwa Anda tidak perlu mendeklarasikan pemetaan notebook_task di dalam pemetaan prod karena akan otomatis menggunakan pemetaan notebook_task di dalam pemetaan resources tingkat atas, jika pemetaan notebook_task tidak secara eksplisit digantikan dalam pemetaan 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

Gunakan perintah bundel berikut untuk memvalidasi, menyebarkan, dan menjalankan pekerjaan ini dalam dev target. Untuk detail tentang siklus hidup bundel, lihat Mengembangkan Bundel Otomatisasi Deklaratif.

# 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

Untuk memvalidasi, menyebarkan, dan menjalankan pekerjaan ini dalam prod target, gunakan ini sebagai gantinya:

# 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

Untuk modularisasi yang lebih banyak dan penggunaan kembali definisi dan pengaturan yang lebih baik di seluruh bundel, bagi konfigurasi bundel Anda menjadi file terpisah:

# 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

Sumber daya tambahan