Share via


Databricks Varlık Paketi ve GitHub Actions ile CI/CD iş akışı çalıştırma

Bu makalede GitHub Actions ve Databricks Varlık Paketi ile GitHub'da CI/CD (sürekli tümleştirme/sürekli dağıtım) iş akışının nasıl çalıştırıldığı açıklanmaktadır. Bkz . Databricks Varlık Paketleri nedir?

GitHub depolarınızın içinden CI/CD iş akışlarınızı otomatikleştirmek, özelleştirmek ve çalıştırmak için Databricks CLI bundle komutlarıyla birlikte GitHub Actions'ı kullanabilirsiniz.

Aşağıdaki gibi GitHub Actions YAML dosyalarını deponuzun .github/workflows dizinine ekleyebilirsiniz. Aşağıdaki örnek GitHub Actions YAML dosyası, paket yapılandırma dosyasında tanımlanan "qa" adlı üretim öncesi hedefte belirtilen işi doğrular, dağıtır ve çalıştırır. Bu örnek GitHub Actions YAML dosyası aşağıdakilere dayanır:

  • Deponun kökünde bulunan ve GitHub Actions YAML dosyasının ayarıyla working-directory: . açıkça bildirilen bir paket yapılandırma dosyası (Paket yapılandırma dosyası zaten deponun kökündeyse bu ayar atlanabilir.) Bu paket yapılandırma dosyası adlı my-job bir Azure Databricks iş akışını ve adlı qabir hedefi tanımlar. Bkz. Databricks Varlık Paketi yapılandırmaları.
  • Bu paketin dağıtıldığı ve çalıştırıldığı Azure Databricks çalışma alanıyla ilişkili bir Azure Databricks hizmet sorumlusu için Azure Databricks erişim belirtecini temsil eden adlı SP_TOKENbir GitHub gizli dizisi. Bkz . Şifrelenmiş gizli diziler.
# This workflow validates, deploys, and runs the specified bundle
# within a pre-production target named "qa".
name: "QA deployment"

# Ensure that only a single job or workflow using the same concurrency group
# runs at a time.
concurrency: 1

# Trigger this workflow whenever a pull request is opened against the repo's
# main branch or an existing pull request's head branch is updated.
on:
  pull_request:
    types:
      - opened
      - synchronize
    branches:
      - main

jobs:
  # Used by the "pipeline_update" job to deploy the bundle.
  # Bundle validation is automatically performed as part of this deployment.
  # If validation fails, this workflow fails.
  deploy:
    name: "Deploy bundle"
    runs-on: ubuntu-latest

    steps:
      # Check out this repo, so that this workflow can access it.
      - uses: actions/checkout@v3

      # Download the Databricks CLI.
      # See https://github.com/databricks/setup-cli
      - uses: databricks/setup-cli@main

      # Deploy the bundle to the "qa" target as defined
      # in the bundle's settings file.
      - run: databricks bundle deploy
        working-directory: .
        env:
          DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
          DATABRICKS_BUNDLE_ENV: qa

  # Validate, deploy, and then run the bundle.
  pipeline_update:
    name: "Run pipeline update"
    runs-on: ubuntu-latest

    # Run the "deploy" job first.
    needs:
      - deploy

    steps:
      # Check out this repo, so that this workflow can access it.
      - uses: actions/checkout@v3

      # Use the downloaded Databricks CLI.
      - uses: databricks/setup-cli@main

      # Run the Databricks workflow named "my-job" as defined in the
      # bundle that was just deployed.
      - run: databricks bundle run my-job --refresh-all
        working-directory: .
        env:
          DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
          DATABRICKS_BUNDLE_ENV: qa

Aşağıdaki GitHub Actions YAML dosyası, önceki dosyayla aynı depoda bulunabilir. Bu dosya, belirtilen paketi bir paket yapılandırma dosyasında tanımlandığı gibi "prod" adlı bir üretim hedefi içinde doğrular, dağıtır ve çalıştırır. Bu örnek GitHub Actions YAML dosyası aşağıdakilere dayanır:

  • Deponun kökünde bulunan ve GitHub Actions YAML dosyasının ayarıyla working-directory: . açıkça bildirilen bir paket yapılandırma dosyası (Paket yapılandırma dosyası zaten deponun kökündeyse bu ayar atlanabilir.) Bu paket yapılandırma dosyası adlı my-job bir Azure Databricks iş akışını ve adlı prodbir hedefi tanımlar. Bkz. Databricks Varlık Paketi yapılandırmaları.
  • Bu paketin dağıtıldığı ve çalıştırıldığı Azure Databricks çalışma alanıyla ilişkili bir Azure Databricks hizmet sorumlusu için Azure Databricks erişim belirtecini temsil eden adlı SP_TOKENbir GitHub gizli dizisi. Bkz . Şifrelenmiş gizli diziler.
# This workflow validates, deploys, and runs the specified bundle
# within a production target named "prod".
name: "Production deployment"

# Ensure that only a single job or workflow using the same concurrency group
# runs at a time.
concurrency: 1

# Trigger this workflow whenever a pull request is pushed to the repo's
# main branch.
on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: "Deploy bundle"
    runs-on: ubuntu-latest

    steps:
      # Check out this repo, so that this workflow can access it.
      - uses: actions/checkout@v3

      # Download the Databricks CLI.
      # See https://github.com/databricks/setup-cli
      - uses: databricks/setup-cli@main

      # Deploy the bundle to the "prod" target as defined
      # in the bundle's settings file.
      - run: databricks bundle deploy
        working-directory: .
        env:
          DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
          DATABRICKS_BUNDLE_ENV: prod

  # Validate, deploy, and then run the bundle.
  pipeline_update:
    name: "Run pipeline update"
    runs-on: ubuntu-latest

    # Run the "deploy" job first.
    needs:
      - deploy

    steps:
      # Check out this repo, so that this workflow can access it.
      - uses: actions/checkout@v3

      # Use the downloaded Databricks CLI.
      - uses: databricks/setup-cli@main

      # Run the Databricks workflow named "my-job" as defined in the
      # bundle that was just deployed.
      - run: databricks bundle run my-job --refresh-all
        working-directory: .
        env:
          DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
          DATABRICKS_BUNDLE_ENV: prod

Ayrıca bkz.