-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathupdate_from_templates.sh
More file actions
executable file
·128 lines (105 loc) · 4.05 KB
/
update_from_templates.sh
File metadata and controls
executable file
·128 lines (105 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
set -euo pipefail
function cleanup() {
cd "$1"
local BUNDLE_UUID="$2"
# Replace specific names with company.databricks.com, user@company.com, user_name
find . -type f -exec sed -i '' -E 's|e2[^[:space:]]*\.com|company.databricks.com|g' {} \;
find . -type f -exec sed -i '' -E 's|[A-Za-z0-9._%+-]+@databricks\.com|user@company.com|g' {} \;
find . -type f -exec sed -i '' -e "s|$CURRENT_USER_NAME|user_name|g" {} \;
find . -type f -exec sed -i '' -E "s|^([[:space:]]*uuid:[[:space:]]*)[^[:space:]]*[[:space:]]*$|\\1$BUNDLE_UUID|g" {} \;
cd ..
}
function init_bundle() {
local TEMPLATE_NAME="$1"
local BUNDLE_UUID="${2:-}"
local CONFIG_JSON="$3"
# Extract project_name from JSON
local PROJECT_NAME=$(echo "$CONFIG_JSON" | grep -o '"project_name"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
# Use CLI_COMMAND if set, otherwise default to 'databricks'
local CLI_COMMAND="${CLI_COMMAND:-databricks}"
echo
echo "# $PROJECT_NAME"
rm -rf "$PROJECT_NAME"
echo "$CONFIG_JSON" > /tmp/config.json
$CLI_COMMAND bundle init "$TEMPLATE_NAME" --config-file /tmp/config.json
cleanup "$PROJECT_NAME" "$BUNDLE_UUID"
}
# Check and extract the host from the databrickscfg file
if [ ! -f ~/.databrickscfg ]; then
echo "Error: ~/.databrickscfg not found." >&2
exit 1
fi
DATABRICKS_HOST=$(grep -A1 '\[DEFAULT\]' ~/.databrickscfg | grep 'host' | awk -F'=' '{print $2}' | xargs || true)
if [ ! "$DATABRICKS_HOST" ]; then
echo "Error: expected ~/.databrickscfg file with a [DEFAULT] section with the first line of the form 'host=...'." >&2
exit 1
fi
# Prompt for CURRENT_USER_NAME if not passed as first arg
if [ -n "${1-}" ]; then
CURRENT_USER_NAME="$1"
else
read -r -p "Enter the current user name of your 'DEFAULT' profile (e.g., 'lennart_kats'): " CURRENT_USER_NAME
if [ -z "${CURRENT_USER_NAME:-}" ]; then
echo "Error: current user name is required." >&2
exit 1
fi
fi
cd $(dirname $0)/..
# Use the 'databricks' CLI by default
# To use a custom CLI, set: export CLI_COMMAND=/path/to/cli
echo "Using Databricks CLI: ${CLI_COMMAND:-databricks}"
${CLI_COMMAND:-databricks} --version
echo
init_bundle "default-python" "87d5a23e-7bc7-4f52-98ee-e374b67d5681" '{
"project_name": "default_python",
"include_job": "yes",
"include_pipeline": "yes",
"include_python": "yes",
"serverless": "yes",
"default_catalog": "catalog",
"personal_schemas": "yes"
}'
init_bundle "default-sql" "853cd9bc-631c-4d4f-bca0-3195c7540854" '{
"project_name": "default_sql",
"http_path": "/sql/1.0/warehouses/abcdef1234567890",
"default_catalog": "catalog",
"personal_schemas": "yes"
}'
init_bundle "dbt-sql" "5e5ca8d5-0388-473e-84a1-1414ed89c5df" '{
"project_name": "dbt_sql",
"http_path": "/sql/1.0/warehouses/abcdef1234567890",
"serverless": "yes",
"default_catalog": "catalog",
"personal_schemas": "yes"
}'
init_bundle "lakeflow-pipelines" "295000fc-1ea8-4f43-befe-d5fb9f7d4ad4" '{
"project_name": "lakeflow_pipelines_sql",
"default_catalog": "catalog",
"personal_schemas": "yes",
"language": "sql"
}'
init_bundle "lakeflow-pipelines" "87a174ba-60e4-4867-a140-1936bc9b00de" '{
"project_name": "lakeflow_pipelines_python",
"default_catalog": "catalog",
"personal_schemas": "yes",
"language": "python"
}'
init_bundle "default-minimal" "8127e9c1-adac-4c9c-b006-d3450874f663" '{
"project_name": "default_minimal",
"default_catalog": "catalog",
"personal_schemas": "yes",
"language_choice": "sql"
}'
# Add .gitkeep files to empty directories in default_minimal
echo > default_minimal/src/.gitkeep
echo > default_minimal/resources/.gitkeep
init_bundle "pydabs" "4062028b-2184-4acd-9c62-f2ec572f7843" '{
"project_name": "pydabs",
"include_job": "yes",
"include_pipeline": "yes",
"include_python": "yes",
"serverless": "yes",
"default_catalog": "catalog",
"personal_schemas": "yes"
}'