Skip to content

Commit a7e45aa

Browse files
committed
Remove DB Warehouse
1 parent a25d64a commit a7e45aa

File tree

1 file changed

+76
-13
lines changed

1 file changed

+76
-13
lines changed

.github/workflows/databricks-ci.yml

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,97 @@ jobs:
2525

2626
- name: Set up Databricks CLI
2727
uses: databricks/setup-cli@main
28+
env:
29+
DATABRICKS_HOST: 'https://e2-demo-field-eng.cloud.databricks.com'
30+
DATABRICKS_TOKEN: ${{ secrets.DEPLOY_NOTEBOOK_TOKEN }}
2831

2932
- name: Configure Databricks CLI authentication
3033
run: |
31-
# Set default environment to dev
32-
echo "DEPLOY_ENV=dev" >> $GITHUB_ENV
34+
echo "[DEFAULT]" > ~/.databrickscfg
35+
echo "host = https://e2-demo-field-eng.cloud.databricks.com" >> ~/.databrickscfg
36+
echo "token = ${{ secrets.DEPLOY_NOTEBOOK_TOKEN }}" >> ~/.databrickscfg
37+
38+
- name: Get or Create serverless SQL warehouse
3339
env:
3440
DATABRICKS_HOST: 'https://e2-demo-field-eng.cloud.databricks.com'
3541
DATABRICKS_TOKEN: ${{ secrets.DEPLOY_NOTEBOOK_TOKEN }}
42+
run: |
43+
WAREHOUSE_NAME="Shared Unity Catalog Serverless"
44+
echo "Looking for warehouse named: $WAREHOUSE_NAME"
45+
46+
echo "Fetching existing warehouses..."
47+
EXISTING_WAREHOUSE=$(curl -s -H "Authorization: Bearer $DATABRICKS_TOKEN" \
48+
"$DATABRICKS_HOST/api/2.0/sql/warehouses")
49+
50+
echo "Warehouse List Response: $(echo $EXISTING_WAREHOUSE | sed 's/\"token\":\"[^\"]*\"/\"token\":\"***\"/g')"
51+
52+
WAREHOUSE_ID=$(echo "$EXISTING_WAREHOUSE" | python3 -c "
53+
import sys, json
54+
import argparse
55+
56+
parser = argparse.ArgumentParser()
57+
parser.add_argument('--name', required=True)
58+
args = parser.parse_args()
59+
60+
try:
61+
data = json.load(sys.stdin)
62+
name = args.name
63+
if 'warehouses' in data:
64+
warehouses = data['warehouses']
65+
matching = [w for w in warehouses if w['name'] == name]
66+
if matching:
67+
print(matching[0]['id'])
68+
else:
69+
print('')
70+
else:
71+
print('')
72+
except Exception as e:
73+
print(f'Error parsing response: {str(e)}', file=sys.stderr)
74+
print('')
75+
" --name "$WAREHOUSE_NAME")
76+
77+
if [ -z "$WAREHOUSE_ID" ]; then
78+
echo "Creating new warehouse..."
79+
RESPONSE=$(curl -s -X POST -H "Authorization: Bearer $DATABRICKS_TOKEN" \
80+
-H "Content-Type: application/json" \
81+
"$DATABRICKS_HOST/api/2.0/sql/warehouses" \
82+
-d "{
83+
\"name\": \"${WAREHOUSE_NAME}\",
84+
\"cluster_size\": \"2X-Small\",
85+
\"enable_serverless_compute\": true,
86+
\"auto_stop_mins\": 10,
87+
\"max_num_clusters\": 1
88+
}")
89+
90+
echo "Create API Response: $(echo $RESPONSE | sed 's/\"token\":\"[^\"]*\"/\"token\":\"***\"/g')"
91+
WAREHOUSE_ID=$(echo $RESPONSE | python3 -c "import sys, json; print(json.load(sys.stdin).get('id', ''))")
92+
else
93+
echo "Found existing warehouse with ID: $WAREHOUSE_ID"
94+
fi
95+
96+
if [ -z "$WAREHOUSE_ID" ]; then
97+
echo "Error: Failed to get warehouse ID"
98+
exit 1
99+
fi
100+
101+
echo "Using warehouse with ID: $WAREHOUSE_ID"
102+
echo "WAREHOUSE_ID=$WAREHOUSE_ID" >> $GITHUB_ENV
103+
# Set default environment to dev
104+
echo "DEPLOY_ENV=dev" >> $GITHUB_ENV
36105
37106
- name: Validate bundle
38107
run: databricks bundle validate --var="environment=${{ env.DEPLOY_ENV }}"
39-
env:
40-
DATABRICKS_HOST: 'https://e2-demo-field-eng.cloud.databricks.com'
41-
DATABRICKS_TOKEN: ${{ secrets.DEPLOY_NOTEBOOK_TOKEN }}
42108

43109
- name: Run and monitor workflow
44110
run: |
45111
echo "Starting workflow execution..."
46112
databricks bundle run demo_workflow --target dev --var="environment=${{ env.DEPLOY_ENV }}"
47-
echo
48-
echo "Workflow execution completed"
49-
env:
50-
DATABRICKS_HOST: 'https://e2-demo-field-eng.cloud.databricks.com'
51-
DATABRICKS_TOKEN: ${{ secrets.DEPLOY_NOTEBOOK_TOKEN }}
113+
114+
- name: Run and monitor production workflow
115+
run: |
116+
echo "Starting production workflow execution..."
117+
databricks bundle run demo_workflow --target dev --var="environment=${{ env.DEPLOY_ENV }}"
52118
53119
- name: Cleanup PR deployment
54120
run: |
55121
databricks bundle destroy --target dev --var="environment=${{ env.DEPLOY_ENV }}" || true
56-
env:
57-
DATABRICKS_HOST: 'https://e2-demo-field-eng.cloud.databricks.com'
58-
DATABRICKS_TOKEN: ${{ secrets.DEPLOY_NOTEBOOK_TOKEN }}

0 commit comments

Comments
 (0)