メインコンテンツまでスキップ

GitHub Actions

備考

プレビュー

この機能は パブリック プレビュー段階です。

GitHub Actions を使用すると、ビルド、テスト、デプロイの CI/CD パイプラインを自動化できます。Databricks では、GitHub 上の CI/CD ワークフロー用に次の GitHub Actions を開発しました。GitHub Actions YAML ファイルをリポジトリの .github/workflows ディレクトリに追加します。

注記

この記事では、サードパーティによって開発された GitHub Actions について説明します。プロバイダーに連絡するには、「 GitHub Actions のサポート」を参照してください。

GitHub Actions

説明

データブリッケン/セットアップ CLI

GitHub Actions ワークフローで Databricks CLI を設定する複合アクション。

GitHub Actions でバンドルをデプロイする

GitHub Actions を使用して、Databricks アセット バンドルをデプロイし、GitHub リポジトリから CI/CD ワークフローの実行をトリガーできます。のその他のCI/CD 機能とベストプラクティスに関する情報については、Databricks CI/CDのDatabricks およびのベストプラクティスと推奨される ワークフロー を参照してください。CI/CDDatabricks

パイプラインの更新を実行するバンドルを使用して CI/CD ワークフローを実行する

次の YAML ファイルの例では GitHub Actions バンドル設定ファイル内で定義されている「dev」という名前の本番前運用ターゲット内のバンドル内の指定されたジョブを検証、デプロイ、および実行するテストデプロイメントをトリガーします。

この例では、次のものが必要です。

  • リポジトリのルートにあるバンドル構成ファイル (GitHub Actions YAML ファイルの設定で明示的に宣言されます) working-directory: . このバンドル構成ファイルでは、 my-job という名前の Databricks ワークフローと devという名前のターゲットを定義する必要があります。「Databricks アセット バンドルの構成」を参照してください。
  • SP_TOKENという名前の GitHub シークレットは、このバンドルがデプロイおよび実行されている Databricks ワークスペースに関連付けられている Databricks サービスプリンシパルのDatabricks アクセス トークンを表します。暗号化されたシークレットを参照してください。
YAML
# This workflow validates, deploys, and runs the specified bundle
# within a pre-production target named "dev".
name: 'Dev 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 "dev" target as defined
# in the bundle's settings file.
- run: databricks bundle deploy
working-directory: .
env:
DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
DATABRICKS_BUNDLE_ENV: dev

# 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: dev

また、本番運用デプロイメントをトリガーすることもできます。 次の GitHub Actions YAML ファイルは、前のファイルと同じリポジトリに存在できます。このファイルは、バンドル設定ファイル内で定義されている「prod」という名前の本番運用ターゲット内で、指定されたバンドルを検証、デプロイ、および実行します。

YAML
# 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

CI/CD ワークフローを実行して JAR をビルドし、バンドルをデプロイする

Java ベースのエコシステムがある場合、 GitHub Actions バンドルをデプロイする前に JAR をビルドしてアップロードする必要があります。 次の YAML ファイルの例ではGitHub ActionsJARをビルドしてボリュームにアップロードするデプロイをトリガーし、バンドルを検証して、バンドル設定ファイルで定義されている「prod」という名前の本番運用ターゲットにデプロイします。Java ベースの JAR をコンパイルしますが、Scala ベースのプロジェクトのコンパイル手順は似ています。

この例では、次のものが必要です。

  • リポジトリのルートにあるバンドル設定ファイルで、GitHub Actions YAML ファイルの設定を通じて明示的に宣言されます working-directory: .
  • このバンドルがデプロイおよび実行される Databricks ワークスペースに関連付けられている Databricks アクセス トークンを表す DATABRICKS_TOKEN 環境変数。
  • Databricks ホスト ワークスペースを表す DATABRICKS_HOST 環境変数。
YAML
name: Build JAR and deploy with bundles

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build-test-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17' # Specify the Java version used by your project
distribution: 'temurin' # Use a reliable JDK distribution

- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- name: Build and test JAR with Maven
run: mvn clean verify # Use verify to ensure tests are run

- name: Databricks CLI Setup
uses: databricks/setup-cli@v0.9.0 # Pin to a specific version

- name: Upload JAR to a volume
env:
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }} # Add host for clarity
run: |
databricks fs cp target/my-app-1.0.jar dbfs:/Volumes/artifacts/my-app-${{ github.sha }}.jar --overwrite

validate:
needs: build-test-upload
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Databricks CLI Setup
uses: databricks/setup-cli@v0.9.0

- name: Validate bundle
env:
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
run: databricks bundle validate

deploy:
needs: validate
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # Only deploy on push to main
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Databricks CLI Setup
uses: databricks/setup-cli@v0.9.0

- name: Deploy bundle
env:
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
run: databricks bundle deploy --target prod

追加のリソース