Skip to content

Commit 4cc287d

Browse files
committed
Add interactive deployment scripts for macOS/Linux and Windows
Co-authored-by: Isaac
1 parent 01dd4b3 commit 4cc287d

2 files changed

Lines changed: 211 additions & 0 deletions

File tree

deploy.ps1

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
$AppName = "databricks-api-explorer"
2+
$ConfigFile = Join-Path $env:USERPROFILE ".databrickscfg"
3+
4+
if (-not (Test-Path $ConfigFile)) {
5+
Write-Host "Error: $ConfigFile not found" -ForegroundColor Red
6+
exit 1
7+
}
8+
9+
# Parse profile names and hosts from .databrickscfg
10+
$profiles = @()
11+
$hosts = @()
12+
$currentProfile = $null
13+
14+
foreach ($line in Get-Content $ConfigFile) {
15+
if ($line -match '^\[(.+)\]$') {
16+
$currentProfile = $Matches[1]
17+
}
18+
elseif ($line -match '^host\s*=\s*(.+)$') {
19+
$host = $Matches[1].Trim().TrimEnd('/')
20+
$profiles += $currentProfile
21+
$hosts += $host
22+
}
23+
}
24+
25+
if ($profiles.Count -eq 0) {
26+
Write-Host "Error: No profiles found in $ConfigFile" -ForegroundColor Red
27+
exit 1
28+
}
29+
30+
# Interactive selector
31+
$selected = 0
32+
$total = $profiles.Count
33+
34+
function Draw-Menu {
35+
param([bool]$Redraw = $false)
36+
37+
if ($Redraw) {
38+
[Console]::SetCursorPosition(0, [Console]::CursorTop - $total)
39+
}
40+
41+
for ($i = 0; $i -lt $total; $i++) {
42+
$profilePad = $profiles[$i].PadRight(35)
43+
if ($i -eq $selected) {
44+
Write-Host " > $profilePad $($hosts[$i])" -ForegroundColor Cyan
45+
}
46+
else {
47+
Write-Host " $profilePad " -NoNewline
48+
Write-Host $hosts[$i] -ForegroundColor DarkGray
49+
}
50+
}
51+
}
52+
53+
Write-Host ""
54+
Write-Host " Select a workspace to deploy ${AppName} to:"
55+
Write-Host " (Up/Down to move, Enter to select, Q to quit)"
56+
Write-Host ""
57+
58+
[Console]::CursorVisible = $false
59+
try {
60+
Draw-Menu
61+
62+
while ($true) {
63+
$key = [Console]::ReadKey($true)
64+
65+
switch ($key.Key) {
66+
'UpArrow' {
67+
if ($selected -gt 0) { $selected-- }
68+
}
69+
'DownArrow' {
70+
if ($selected -lt $total - 1) { $selected++ }
71+
}
72+
'Enter' {
73+
break
74+
}
75+
'Q' {
76+
Write-Host ""
77+
Write-Host " Cancelled."
78+
exit 0
79+
}
80+
default { continue }
81+
}
82+
83+
if ($key.Key -eq 'Enter') { break }
84+
85+
Draw-Menu -Redraw $true
86+
}
87+
}
88+
finally {
89+
[Console]::CursorVisible = $true
90+
}
91+
92+
$profile = $profiles[$selected]
93+
$host = $hosts[$selected]
94+
95+
Write-Host ""
96+
Write-Host " Deploying ${AppName} to:"
97+
Write-Host " Profile: $profile"
98+
Write-Host " Workspace: $host"
99+
Write-Host ""
100+
101+
# Deploy
102+
databricks apps deploy $AppName --source-code-path . --profile $profile

deploy.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
APP_NAME="databricks-api-explorer"
5+
CONFIG_FILE="${HOME}/.databrickscfg"
6+
7+
if [[ ! -f "$CONFIG_FILE" ]]; then
8+
echo "Error: $CONFIG_FILE not found"
9+
exit 1
10+
fi
11+
12+
# Parse profile names and hosts from .databrickscfg
13+
profiles=()
14+
hosts=()
15+
while IFS= read -r line; do
16+
if [[ "$line" =~ ^\[(.+)\]$ ]]; then
17+
current_profile="${BASH_REMATCH[1]}"
18+
elif [[ "$line" =~ ^host[[:space:]]*=[[:space:]]*(.+)$ ]]; then
19+
host="${BASH_REMATCH[1]}"
20+
host="${host%/}" # strip trailing slash
21+
profiles+=("$current_profile")
22+
hosts+=("$host")
23+
fi
24+
done < "$CONFIG_FILE"
25+
26+
if [[ ${#profiles[@]} -eq 0 ]]; then
27+
echo "Error: No profiles found in $CONFIG_FILE"
28+
exit 1
29+
fi
30+
31+
# Interactive selector
32+
selected=0
33+
total=${#profiles[@]}
34+
35+
draw_menu() {
36+
# Move cursor up to redraw (skip on first draw)
37+
if [[ ${1:-0} -eq 1 ]]; then
38+
printf "\033[%dA" "$total"
39+
fi
40+
41+
for i in $(seq 0 $((total - 1))); do
42+
if [[ $i -eq $selected ]]; then
43+
printf "\033[1;36m ▸ %-35s %s\033[0m\n" "${profiles[$i]}" "${hosts[$i]}"
44+
else
45+
printf " %-35s \033[2m%s\033[0m\n" "${profiles[$i]}" "${hosts[$i]}"
46+
fi
47+
done
48+
}
49+
50+
echo ""
51+
echo " Select a workspace to deploy ${APP_NAME} to:"
52+
echo " (↑/↓ to move, Enter to select, q to quit)"
53+
echo ""
54+
55+
# Hide cursor
56+
printf "\033[?25l"
57+
trap 'printf "\033[?25h"' EXIT
58+
59+
draw_menu 0
60+
61+
while true; do
62+
# Read a single keypress
63+
IFS= read -rsn1 key
64+
65+
if [[ "$key" == $'\x1b' ]]; then
66+
read -rsn2 rest
67+
key+="$rest"
68+
fi
69+
70+
case "$key" in
71+
$'\x1b[A') # Up arrow
72+
((selected > 0)) && ((selected--))
73+
;;
74+
$'\x1b[B') # Down arrow
75+
((selected < total - 1)) && ((selected++))
76+
;;
77+
'') # Enter
78+
break
79+
;;
80+
q|Q)
81+
echo ""
82+
echo " Cancelled."
83+
exit 0
84+
;;
85+
*)
86+
continue
87+
;;
88+
esac
89+
90+
draw_menu 1
91+
done
92+
93+
# Restore cursor
94+
printf "\033[?25h"
95+
trap - EXIT
96+
97+
profile="${profiles[$selected]}"
98+
host="${hosts[$selected]}"
99+
100+
echo ""
101+
echo " Deploying ${APP_NAME} to:"
102+
echo " Profile: ${profile}"
103+
echo " Workspace: ${host}"
104+
echo ""
105+
106+
# Deploy
107+
databricks apps deploy "$APP_NAME" \
108+
--source-code-path . \
109+
--profile "$profile"

0 commit comments

Comments
 (0)