Skip to content

Commit

Permalink
Add install script
Browse files Browse the repository at this point in the history
- Changed "Spot CLI" to "SpotCLI" everywhere
- Added install script
- Configure Poetry to only build wheel
  • Loading branch information
Dmítry Kovalenko authored Nov 4, 2020
1 parent b4f5fa5 commit 9b97441
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Poetry
uses: abatilo/[email protected]
- name: Build wheel
run: poetry build
run: poetry build -f wheel
- name: Get tag name
id: tag_name
run: echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ SpotCLI is a command-line interface for managing Spot Elastigroups.

## Installation

Download the .whl file from [latest release](https://github.com/SupersonicAds/spotcli/releases/latest) page and install it using pip:
Install latest SpotCLI:

```bash
pip install spotcli-1.0.2-py3-none-any.whl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/SupersonicAds/spotcli/master/install.sh)"
```

Verify that spotcli is installed by running:
You can also install SpotCLI manually:

- Download wheel from [releases](https://github.com/SupersonicAds/spotcli/releases) page
- Install SpotCLI using pip:

```bash
spotcli version
pip install spotcli-1.0.0-py3-none-any.whl
```

## Configuration
Expand Down Expand Up @@ -89,6 +92,7 @@ To automatically accept all prompts, add `-y`.
You can run multiple standalone actions with this tool as well.

Supported actions:

- status (*prints group name, ID, instance count and process suspension status when `--show-processes` is used*)
- roll
- suspend/unsuspend process or scaling policy (*you can do multiple at once*)
Expand Down
48 changes: 48 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -eu
trap "" SIGINT

DOWNLOAD_URL=$(curl -fsSL https://api.github.com/repos/SupersonicAds/spotcli/releases/latest \
| grep browser_download_url \
| cut -d '"' -f 4)
WHEEL_FILE="$(mktemp -d)/${DOWNLOAD_URL##*/}"
trap "rm -f $WHEEL_FILE || true && echo 'ERROR: SpotCLI wasn\\'t installed' && exit 1" ERR

echo -en "Downloading latest wheel from GitHub..."
curl -fsSL -o $WHEEL_FILE "$DOWNLOAD_URL"
echo -en "done\n"

echo -en "Detecting Python..."
if pyenv versions >/dev/null 2>&1 && [[ $(python -V 2>/dev/null) == *"Python 3"* ]]
then
echo -en "$(python -V | sed 's/Python //g') (pyenv)\n"
PIP="$(which pip)"
elif HOMEBREW_PIP=$(brew list python3 -q 2>/dev/null | grep "pip3$")
then
echo -en "$($HOMEBREW_PIP -V | grep -Eo 'python [0-9.]+' | sed 's/python //g') (homebrew)\n"
PIP=$HOMEBREW_PIP
elif [[ $(python3 -V 2>/dev/null) == *"Python 3"* ]]
then
echo -en "$(python3 -V | sed 's/Python //g') (system)\n"
echo -en "You may need to enter sudo password"
PIP="sudo $(which pip3)"
else
echo -en "ERROR: Python 3 not found\n"
exit 1
fi

echo -en "Installing SpotCLI..."
PIP_STDOUT=$(mktemp)
$PIP install "$WHEEL_FILE" >/dev/null
rm -f $WHEEL_FILE
rm -f $PIP_STDOUT
mkdir -p $HOME/.spot
touch $HOME/.spot/config.yaml
echo -en "done\n"

echo -en "Verifying installation..."
[[ $(spotcli version) == *"SpotCLI version"* ]]
echo -en "ok\n"

trap - EXIT
trap - SIGINT
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "spotcli"
version = "1.0.3"
description = "Spot CLI"
description = "CLI for Spot Elastigroups management"
authors = ["Dmitry Kovalenko <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down
10 changes: 5 additions & 5 deletions spotcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def main():

@click.command()
def version():
"""Get Spot CLI version."""
console.print(f"Spot CLI version {spotcli.__version__}")
"""Get SpotCLI version."""
console.print(f"SpotCLI version {spotcli.__version__}")


@click.command()
Expand All @@ -35,7 +35,7 @@ def run(scenario, auto_approve):
SCENARIO is the name of the scenario to run.
"""
console.print(f"[bold]Spot CLI version {spotcli.__version__}")
console.print(f"[bold]SpotCLI version {spotcli.__version__}")
config = spotcli.configuration.load()
try:
s = config.scenarios[scenario]
Expand Down Expand Up @@ -78,7 +78,7 @@ def status(group, show_processes):
GROUP is elastigroup name, alias or regex.
"""
console.print(f"[bold]Spot CLI version {spotcli.__version__}")
console.print(f"[bold]SpotCLI version {spotcli.__version__}")
config = spotcli.configuration.load()
targets = spotcli.tasks.TargetList(config.providers["spot"], config.aliases, [group])
console.print("\n")
Expand Down Expand Up @@ -167,7 +167,7 @@ def scale(kind, group, amount, auto_approve):


def action(action, target, auto_approve, **kwargs):
console.print(f"[bold]Spot CLI version {spotcli.__version__}")
console.print(f"[bold]SpotCLI version {spotcli.__version__}")
config = spotcli.configuration.load()
targets = spotcli.tasks.TargetList(config.providers["spot"], config.aliases, [target])
task = spotcli.tasks.Task(kind=action, targets=targets, **kwargs)
Expand Down

0 comments on commit 9b97441

Please sign in to comment.