Skip to content

Commit

Permalink
Add support for installing the CLI on DBR (#85)
Browse files Browse the repository at this point in the history
We want to install the CLI at $HOME/bin when the `install.sh`
installation script is invoked from DBR. This allows us to provide the
CLI in DBR though a proxy trampoline script that's installed in DBR at
`/usr/local/bin`.

This PR also adds a couple of tests and assertions to make this
functionality robust for use in DBR.
  • Loading branch information
shreyas-goenka authored Feb 22, 2024
1 parent 216cac9 commit c55718d
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 4 deletions.
103 changes: 99 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- run: databricks version
shell: bash

- run: ./setup-cli/test.sh $(cat ./setup-cli/VERSION)
- run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION)
shell: bash

action_with_version:
Expand All @@ -57,7 +57,7 @@ jobs:
- run: databricks version
shell: bash

- run: ./setup-cli/test.sh 0.200.0
- run: ./setup-cli/assert/version.sh 0.200.0
shell: bash

install:
Expand All @@ -79,13 +79,62 @@ jobs:
- run: env
shell: bash

- name: Assert databricks CLI is not already installed
run: ./setup-cli/assert/not-installed.sh
shell: bash

- run: ./setup-cli/install.sh
shell: bash

- run: databricks version
shell: bash

- run: ./setup-cli/test.sh $(cat ./setup-cli/VERSION)
- name: Assert the version of the CLI installed
run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION)
shell: bash

- name: Assert installation path is /usr/local/bin for non-windows platforms
run: ./setup-cli/assert/path.sh /usr/local/bin/databricks
if: matrix.os != 'windows-latest'
shell: bash

- name: Assert installation path is /c/Windows for windows platforms
if: matrix.os == 'windows-latest'
run: ./setup-cli/assert/path.sh /c/Windows/databricks


install-dbr:
# All DBR images are built on top of Ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
path: ./setup-cli

# Append ~/bin to the PATH. This helps with the assertions in the next steps.
- run: echo "PATH=$PATH:$HOME/bin" >> $GITHUB_ENV

- name: Assert databricks CLI is not already installed
run: ./setup-cli/assert/not-installed.sh
shell: bash

- name: Install the CLI
run: ./setup-cli/install.sh
shell: bash
env:
DATABRICKS_RUNTIME_VERSION: value-does-not-matter

- name: Run the CLI
run: databricks version
shell: bash

- name: Assert the version of the CLI installed
run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION)
shell: bash

- name: Assert installation path is ~/bin
run: ./setup-cli/assert/path.sh ~/bin/databricks
shell: bash

curl:
Expand All @@ -104,11 +153,57 @@ jobs:
with:
path: ./setup-cli

- name: Assert databricks CLI is not already installed
run: ./setup-cli/assert/not-installed.sh
shell: bash

- run: curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/${{ github.sha }}/install.sh | sh
shell: bash

- run: databricks version
shell: bash

- run: ./setup-cli/test.sh $(cat ./setup-cli/VERSION)
- name: Assert the version of the CLI installed
run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION)
shell: bash

- name: Assert installation path is /usr/local/bin for non-windows platforms
run: ./setup-cli/assert/path.sh /usr/local/bin/databricks
if: matrix.os != 'windows-latest'
shell: bash

- name: Assert installation path is /c/Windows for windows platforms
if: matrix.os == 'windows-latest'
run: ./setup-cli/assert/path.sh /c/Windows/databricks

curl-dbr:
# All DBR images are built on top of Ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
path: ./setup-cli

# Append ~/bin to the PATH. This helps with the assertions in the next steps.
- run: echo "PATH=$PATH:$HOME/bin" >> $GITHUB_ENV

- name: Assert databricks CLI is not already installed
run: ./setup-cli/assert/not-installed.sh
shell: bash

- run: curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/${{ github.sha }}/install.sh | sh
shell: bash
env:
DATABRICKS_RUNTIME_VERSION: value-does-not-matter

- run: databricks version
shell: bash

- name: Assert the version of the CLI installed
run: ./setup-cli/assert/version.sh $(cat ./setup-cli/VERSION)
shell: bash

- name: Assert installation path is ~/bin
run: ./setup-cli/assert/path.sh ~/bin/databricks
shell: bash
10 changes: 10 additions & 0 deletions assert/not-installed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -euo pipefail

# Assert databricks CLI is not already installed
if which databricks >/dev/null 2>&1; then
exit 1
else
exit 0
fi
14 changes: 14 additions & 0 deletions assert/path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

EXPECTED="${1:-invalid}"
ACTUAL=$(which databricks)

if [[ "$EXPECTED" != "$ACTUAL" ]]; then
echo "Path \"$ACTUAL\" does not match expectation \"$EXPECTED\"."
exit 1
else
echo "Path \"$ACTUAL\" matches expectation."
exit 0
fi
File renamed without changes.
9 changes: 9 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ MINGW64_NT)
;;
esac

# Set target to ~/bin if DATABRICKS_RUNTIME_VERSION environment variable is set.
if [ -n "$DATABRICKS_RUNTIME_VERSION" ]; then
# Set the installation target to ~/bin when run on DBR
TARGET="$HOME/bin"

# Create the target directory if it does not exist
mkdir -p "$TARGET"
fi

# Include architecture in file name.
ARCH="$(uname -m)"
case "$ARCH" in
Expand Down

0 comments on commit c55718d

Please sign in to comment.