次の方法で共有


Databricks アセット バンドルと GitHub Actions を使用して CI/CD ワークフローを実行する

この記事では、GitHub ActionsDatabricks アセット バンドルを使って、GitHub で CI/CD (継続的インテグレーションと継続的デプロイ) ワークフローを実行する方法について説明します。 「Databricks アセット バンドルとは」を参照してください

Databricks CLI bundle コマンドとともに GitHub Actions を使用して、GitHub リポジトリ内から CI/CD ワークフローを自動化、カスタマイズ、実行できます。

次のような GitHub Actions YAML ファイルを、リポジトリの .github/workflows ディレクトリに追加できます。 次の GitHub Actions YAML ファイルの例では、バンドル構成ファイル内に定義されている "qa" という名前の実稼働前ターゲット内のバンドルで、指定したジョブを検証、デプロイ、実行します。 この GitHub Actions YAML ファイルの例は、次に依存しています。

  • リポジトリのルートにあるバンドル構成ファイル。GitHub Actions YAML ファイルの設定によって明示的に宣言されます working-directory: . (バンドル構成ファイルがリポジトリのルートに既にある場合は、この設定を省略できます)。このバンドル構成ファイルによって、my-job という名前の Azure Databricks ワークフローと qa という名前のターゲットが定義されます。 「Databricks アセット バンドルの構成」をご覧ください。
  • SP_TOKEN という名前の GitHub シークレット。Azure Databricks サービス プリンシパルの Azure Databricks アクセス トークンを表しており、このバンドルのデプロイ先および実行先である Azure Databricks ワークスペースに関連付けられます。 「暗号化されたシークレット」をご覧ください。
# 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

次の GitHub Actions YAML ファイルは、上記のファイルと同じリポジトリに存在できます。 このファイルでは、バンドル構成ファイル内に定義されている "prod" という名前の実稼働ターゲット内の指定バンドルを検証、デプロイ、実行します。 この GitHub Actions YAML ファイルの例は、次に依存しています。

  • リポジトリのルートにあるバンドル構成ファイル。GitHub Actions YAML ファイルの設定によって明示的に宣言されます working-directory: . (バンドル構成ファイルがリポジトリのルートに既にある場合は、この設定を省略できます)。 このバンドル構成ファイルによって、my-job という名前の Azure Databricks ワークフローと prod という名前のターゲットが定義されます。 「Databricks アセット バンドルの構成」をご覧ください。
  • SP_TOKEN という名前の GitHub シークレット。Azure Databricks サービス プリンシパルの Azure Databricks アクセス トークンを表しており、このバンドルのデプロイ先および実行先である Azure Databricks ワークスペースに関連付けられます。 「暗号化されたシークレット」をご覧ください。
# 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

関連項目