Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Önemli
Bu özellik Genel Önizleme aşamasındadır. Önizlemeler sayfasında önizleme kaydını onaylayabilirsiniz. Bkz. Azure Databricks önizlemelerini yönetme.
GitHub Actions, GitHub depolarınızdan CI/CD akışlarınızın çalıştırılmasını tetikler ve DERLEME, test ve dağıtım CI/CD işlem hattınızı otomatikleştirmenize olanak tanır.
Bu makalede Databricks tarafından geliştirilen GitHub Actions hakkında bilgi ve yaygın kullanım örnekleri sağlanır. Databricks'te diğer CI/CD özellikleri ve en iyi yöntemler hakkında bilgi için bkz. Azure Databricks'te CI/CD ve En iyi yöntemler ve Databricks'te önerilen CI/CD iş akışları.
Databricks GitHub Actions
Databricks, GitHub'da CI/CD iş akışlarınız için aşağıdaki GitHub Actions'ı geliştirmiştir. GitHub Actions YAML dosyalarını deponuzun .github/workflows dizinine ekleyin.
Uyarı
Bu makale, üçüncü taraf tarafından geliştirilen GitHub Actions'ı kapsar. Sağlayıcıya başvurmak için bkz. GitHub Actions Support.
| GitHub İşlemi | Açıklama |
|---|---|
| databricks/setup-cli | GitHub Actions iş akışında Databricks CLI'yi ayarlayan bileşik eylem. |
Git klasörünü güncelleştiren bir CI/CD iş akışı çalıştırma
Aşağıdaki örnek GitHub Actions YAML dosyası, uzak dal güncelleştirildiğinde çalışma alanı Git klasörünü güncelleştirir. CI/CD için Git klasörü yaklaşımı hakkında bilgi için bkz. Kaynak denetimi için diğer araçlar.
Gereksinimler
Bu örnekte gelişmiş güvenlik için GitHub Actions için iş yükü kimlik federasyonu kullanılmaktadır ve bir federasyon ilkesi oluşturmanız gerekir. Bkz . GitHub Actions için iş yükü kimlik federasyonu etkinleştirme.
Eylemi Oluşturma
Şimdi aşağıdaki YAML ile deponuza bir dosya .github/workflows/sync_git_folder.yml ekleyin:
name: Sync Git Folder
concurrency: prod_environment
on:
push:
branches:
# Set your base branch name here
- git-folder-cicd-example
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
name: 'Update git folder'
environment: Prod
env:
DATABRICKS_AUTH_TYPE: github-oidc
DATABRICKS_HOST: ${{ vars.DATABRICKS_HOST }}
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
steps:
- uses: actions/checkout@v3
- uses: databricks/setup-cli@main
- name: Update git folder
# Set your workspace path and branch name here
run: databricks repos update /Workspace/<git-folder-path> --branch git-folder-cicd-example
İşlem hattı güncelleştirmesini çalıştıran bir paketle CI/CD iş akışı çalıştırma
Aşağıdaki örnek GitHub Actions YAML dosyası, paket yapılandırma dosyasında tanımlanan adlı dev üretim öncesi hedefte belirtilen işi doğrulayan, dağıtan ve çalıştıran bir test dağıtımını tetikler.
Gereksinimler
Bu örnek, şunlar olmasını gerektirir:
Depo kökünde bulunan ve GitHub Actions YAML dosyasının ayarıyla açıkça belirtilmiş bir paket yapılandırma dosyası
working-directory: .. Bu paket yapılandırma dosyası,sample_jobadına sahip bir Azure Databricks iş akışı vedevadlı bir hedef tanımlamalıdır. Örneğin:# This is a Databricks asset bundle definition for pipeline_update. bundle: name: pipeline_update include: - resources/*.yml variables: catalog: description: The catalog to use schema: description: The schema to use resources: jobs: sample_job: name: sample_job parameters: - name: catalog default: ${var.catalog} - name: schema default: ${var.schema} tasks: - task_key: refresh_pipeline pipeline_task: pipeline_id: ${resources.pipelines.sample_pipeline.id} environments: - environment_key: default spec: environment_version: '4' pipelines: sample_pipeline: name: sample_pipeline catalog: ${var.catalog} schema: ${var.schema} serverless: true root_path: '../src/sample_pipeline' libraries: - glob: include: ../src/sample_pipeline/transformations/** environment: dependencies: - --editable ${workspace.file_path} targets: dev: mode: development default: true workspace: host: <dev-workspace-url> variables: catalog: my_catalog schema: ${workspace.current_user.short_name} prod: mode: production workspace: host: <production-workspace-url> root_path: /Workspace/Users/someone@example.com/.bundle/${bundle.name}/${bundle.target} variables: catalog: my_catalog schema: prod permissions: - user_name: someone@example.com level: CAN_MANAGEPaket yapılandırması hakkında daha fazla bilgi için bkz. Databricks Varlık Paketi yapılandırması.
Bu paketin dağıtıldığı ve çalıştırıldığı Azure Databricks çalışma alanıyla ilişkili bir Azure Databricks
SP_TOKENiçin Azure Databricks erişim belirtecini temsil eden adlı bir GitHub gizli dizisi. Jeton oluşturmak için:- Databricks hizmet sorumlusu oluşturun. Bkz. Hesabınıza hizmet sorumluları ekleme.
- Hizmet sorumlusu için bir gizli anahtar oluşturun. Bkz 1. Adım: OAuth gizli anahtarı oluşturma. Gizli anahtar ve istemci kimliği değerlerini kopyalayın.
- Kopyalanan gizli dizi ve istemci kimliği değerlerini kullanarak manuel olarak Databricks erişim belirteci (hesap veya çalışma alanı) oluşturun. Bkz. Hesap düzeyinde erişim belirteci oluşturma.
-
access_tokenJSON yanıtından değeri kopyalayın. Deponuzda Actions adlıSP_TOKENbir GitHub gizli dizisi ekleyin ve gizli dizi değeri olarak Databricks erişim belirtecini kullanın. Bkz. Şifrelenmiş gizli bilgiler.
Eylemi Oluşturma
Şimdi aşağıdaki YAML ile deponuza bir dosya .github/workflows/pipeline_update.yml ekleyin:
# 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 "sample_job" as defined in the
# bundle that was just deployed.
- run: databricks bundle run sample_job --refresh-all
working-directory: .
env:
DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
DATABRICKS_BUNDLE_ENV: dev
Ayrıca üretim dağıtımlarını tetiklemeniz de gerekebilir. 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.
# 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 "sample_job" as defined in the
# bundle that was just deployed.
- run: databricks bundle run sample_job --refresh-all
working-directory: .
env:
DATABRICKS_TOKEN: ${{ secrets.SP_TOKEN }}
DATABRICKS_BUNDLE_ENV: prod
JAR oluşturan ve paket dağıtan bir CI/CD iş akışı çalıştırma
Java tabanlı bir ekosisteminiz varsa, paketi dağıtmadan önce GitHub Action'ınızın bir JAR oluşturması ve karşıya yüklemesi gerekir. Aşağıdaki örnek GitHub Actions YAML dosyası, jar oluşturup bir birime yükleyen, ardından paketi doğrulayan ve paket yapılandırma dosyasında tanımlanan "prod" adlı bir üretim hedefine dağıtan bir dağıtımı tetikler. Java tabanlı bir JAR derlese de Scala tabanlı bir proje için derleme adımları benzerdir.
Gereksinimler
Bu örnek, şunlar olmasını gerektirir:
- GitHub Actions YAML dosyasının ayarı aracılığıyla açıkça bildirilen, deponun kökündeki bir paket yapılandırma dosyası
working-directory: . -
DATABRICKS_TOKENBu paketin dağıtıldığı ve çalıştırıldığı Azure Databricks çalışma alanıyla ilişkili Azure Databricks erişim belirtecini temsil eden bir ortam değişkeni. -
DATABRICKS_HOSTAzure Databricks konak çalışma alanını temsil eden bir ortam değişkeni.
Eylemi Oluşturma
Şimdi aşağıdaki YAML ile deponuza bir dosya .github/workflows/build_jar.yml ekleyin:
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