Skip to content

Commit 254ff18

Browse files
committed
databricks asset bundle setup
1 parent 3754af7 commit 254ff18

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Name of the bundle
2+
bundle:
3+
name: modern-data-warehouse-databricks-asset-bundles
4+
5+
# Including the workflows to be used in the bundle.
6+
# This will deploy the workflows to the Databricks workspace and can be used to run the workflows as part of CI/CD pipeline.
7+
# In this case we are creating test workflows and running test in databricks workspace as part of CI/CD pipeline.
8+
include:
9+
- single_tech_samples/databricks/databricks_terraform/workflows/*.yml
10+
11+
# Target Environment Configuration
12+
# Each environment has its own resources in Azure.
13+
targets:
14+
# Sandbox
15+
sandbox:
16+
presets:
17+
name_prefix: "sandbox_"
18+
workspace:
19+
host: <DATABRICKS_WORKSPACE_URL>
20+
root_path: /Workspace/sandbox/${workspace.current_user.userName}/${bundle.name}/${bundle.target}
21+
run_as:
22+
service_principal_name: ${workspace.current_user.userName}
23+
24+
dev:
25+
presets:
26+
name_prefix: "dev_"
27+
default: true
28+
workspace:
29+
host: <DATABRICKS_WORKSPACE_URL>
30+
root_path: /Workspace/dev/${workspace.current_user.userName}/${bundle.name}/${bundle.target}
31+
run_as:
32+
service_principal_name: ${workspace.current_user.userName}
33+
34+
stg:
35+
presets:
36+
name_prefix: "stg_"
37+
default: true
38+
workspace:
39+
host: <DATABRICKS_WORKSPACE_URL>
40+
root_path: /Workspace/stg/${workspace.current_user.userName}/${bundle.name}/${bundle.target}
41+
run_as:
42+
service_principal_name: ${workspace.current_user.userName}
43+
44+
prod:
45+
presets:
46+
name_prefix: "prod_"
47+
default: true
48+
workspace:
49+
host: <DATABRICKS_WORKSPACE_URL>
50+
root_path: /Workspace/prod/${workspace.current_user.userName}/${bundle.name}/${bundle.target}
51+
run_as:
52+
service_principal_name: ${workspace.current_user.userName}
53+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Databricks notebook source
2+
# COMMAND ----------
3+
4+
import unittest
5+
6+
class Greeter:
7+
def __init__(self):
8+
self.message = "Hello Test Message from Dummy File!"
9+
10+
class TestGreeter(unittest.TestCase):
11+
def test_greeter_message(self):
12+
greeter = Greeter()
13+
self.assertEqual(greeter.message, "Hello Test Message from Dummy File!", "The message should be 'Hello world!'")
14+
15+
if __name__ == "__main__":
16+
unittest.main(argv=['first-arg-is-ignored'], exit=False)
17+
18+
# COMMAND ----------
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
###
4+
# The Bellow Script is used to generate Databricks Job YAML files for each test file in the tests directory.
5+
# The script will iterate over all the test files and generate a YAML file for each test file under the workflows directory.
6+
###
7+
8+
# Change to the root directory of the project
9+
cd "$(dirname "$0")/.." || exit
10+
11+
# Set the directory where YAML files will be generated
12+
OUTPUT_DIR="workflows/"
13+
TEST_FOLDER_PATH="single_tech_samples/databricks/databricks_terraform/tests"
14+
15+
mkdir -p "$OUTPUT_DIR"
16+
17+
# Find all _test.py files from the root directory and iterate over them
18+
for test_file in $(find ./tests -type f -name "*_test.py"); do
19+
# Extract the base filename without extension
20+
base_name=$(basename "$test_file" .py)
21+
22+
# Define the path to the output YAML file
23+
output_file="${OUTPUT_DIR}/${base_name}.job.yml"
24+
25+
# Generate the YAML content
26+
cat <<EOF > "$output_file"
27+
resources:
28+
jobs:
29+
${base_name}:
30+
name: ${base_name}
31+
tasks:
32+
- task_key: ${base_name}
33+
notebook_task:
34+
notebook_path: ${TEST_FOLDER_PATH}/${base_name}
35+
base_parameters:
36+
env: \${bundle.target}
37+
source: GIT
38+
39+
git_source:
40+
git_url: https://github.com/Azure-Samples/modern-data-warehouse-dataops
41+
git_provider: gitHub
42+
git_branch: main
43+
queue:
44+
enabled: true
45+
46+
job_clusters:
47+
- job_cluster_key: job_cluster
48+
new_cluster:
49+
spark_version: 15.4.x-scala2.12
50+
node_type_id: Standard_D4ds_v5
51+
autoscale:
52+
min_workers: 1
53+
max_workers: 4
54+
EOF
55+
56+
echo "Generated YAML job template for: $base_name -> $output_file"
57+
done
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resources:
2+
jobs:
3+
hello_test:
4+
name: hello_test
5+
tasks:
6+
- task_key: hello_test
7+
notebook_task:
8+
notebook_path: single_tech_samples/databricks/databricks_terraform/tests/hello_test
9+
base_parameters:
10+
env: ${bundle.target}
11+
source: GIT
12+
13+
git_source:
14+
git_url: https://github.com/Azure-Samples/modern-data-warehouse-dataops
15+
git_provider: gitHub
16+
git_branch: main
17+
queue:
18+
enabled: true
19+
20+
job_clusters:
21+
- job_cluster_key: job_cluster
22+
new_cluster:
23+
spark_version: 15.4.x-scala2.12
24+
node_type_id: Standard_D4ds_v5
25+
autoscale:
26+
min_workers: 1
27+
max_workers: 4

0 commit comments

Comments
 (0)