Skip to content

🐙 octavia-cli: package and install script #10823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions octavia-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN pip install --no-cache-dir .
RUN useradd --create-home --shell /bin/bash octavia-cli
USER octavia-cli

WORKDIR /home/octavia-project
ENTRYPOINT ["octavia"]

LABEL io.airbyte.version=dev
Expand Down
31 changes: 18 additions & 13 deletions octavia-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ It has the following features:

The project is under development: readers can refer to our [tech spec deck](https://docs.google.com/presentation/d/10RjkCzBiVhCivnjSh63icYI7wG6S0N0ZIErEIsmXTqM/edit?usp=sharing) for an introduction to the tool.

# Usage
We encourage users to use the CLI with docker to avoid the hassle of setting up a Python installation.
The project is under development: we have not yet published any docker image to our Docker registry.
# Install

1. Build the project locally (from the root of the repo):
## 1. Install and run Docker
We are packaging this CLI as a Docker image to avoid dependency hell, **[please install and run Docker if you are not](https://docs.docker.com/get-docker/)**.

## 2.a If you are using ZSH / Bash:
```bash
SUB_BUILD=OCTAVIA_CLI ./gradlew build #from the root of the repo
curl -o- https://raw.githubusercontent.com/airbytehq/airbyte/master/octavia-cli/install.sh | bash
```
2. Run the CLI from docker:

This script:
1. Pulls the [octavia-cli image](https://hub.docker.com/r/airbyte/octavia-cli/tags) from our Docker registry.
2. Creates an `octavia` alias in your profile.

## 2.b If you want to directly run the CLI without alias in your current directory:
```bash
docker run airbyte/octavia-cli:dev
````
3. Create an `octavia` alias in your `.bashrc` or `.zshrc`:
````bash
echo 'alias octavia="docker run airbyte/octavia-cli:dev"' >> ~/.zshrc
source ~/.zshrc
octavia
docker run --rm -v ${PWD}:/home/octavia-project --network host -e AIRBYTE_URL="${AIRBYTE_URL}" -e AIRBYTE_WORKSPACE_ID="${AIRBYTE_WORKSPACE_ID}" airbyte/octavia-cli:dev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
docker run --rm -v ${PWD}:/home/octavia-project --network host -e AIRBYTE_URL="${AIRBYTE_URL}" -e AIRBYTE_WORKSPACE_ID="${AIRBYTE_WORKSPACE_ID}" airbyte/octavia-cli:dev
docker run --rm -v ${PWD}:/home/octavia-project --network host -e AIRBYTE_URL="${AIRBYTE_URL}" airbyte/octavia-cli:dev

````

# Current development status
Expand Down Expand Up @@ -55,6 +55,11 @@ We welcome community contributions!
6. Run the unittest suite: `pytest --cov=octavia_cli`
7. Iterate: please check the [Contributing](#contributing) for instructions on contributing.

## Build
Build the project locally (from the root of the repo):
```bash
SUB_BUILD=OCTAVIA_CLI ./gradlew build # from the root directory of the repo
```
# Contributing
1. Please sign up to [Airbyte's Slack workspace](https://slack.airbyte.io/) and join the `#octavia-cli`. We'll sync up community efforts in this channel.
2. Read the [execution plan](https://docs.google.com/spreadsheets/d/1weB9nf0Zx3IR_QvpkxtjBAzyfGb7B0PWpsVt6iMB5Us/edit#gid=0) and find a task you'd like to work on.
Expand Down
73 changes: 73 additions & 0 deletions octavia-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

# This install scripts currently only works for ZSH and Bash profiles.
# It creates an octavia alias in your profile bound to a docker run command

VERSION=dev

detect_profile() {
if [ "${SHELL#*bash}" != "$SHELL" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
if [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
fi

if [ -z "${DETECTED_PROFILE}" ]; then
echo "🚨 - Cannot install! This scripts only works if you are using one of these profiles: ~/.bashrc, ~/.bash_profile or ~/.zshrc"
exit 1
else
echo "octavia alias will be added to ${DETECTED_PROFILE}"
fi
}

check_docker_is_running() {
if ! docker info > /dev/null 2>&1; then
echo "🚨 - This script uses docker, and it isn't running - please start docker and try again!"
exit 1
fi
}

delete_previous_alias() {
sed -i'' -e '/^alias octavia=/d' ${DETECTED_PROFILE}
}


pull_image() {
docker pull airbyte/octavia-cli:${VERSION} > /dev/null 2>&1
}

add_alias() {
echo 'alias octavia="pwd | xargs -I {} docker run --rm -v {}:/home/octavia-project --network host -e AIRBYTE_URL="\${AIRBYTE_URL}" -e AIRBYTE_WORKSPACE_ID="\${AIRBYTE_WORKSPACE_ID}" airbyte/octavia-cli:'${VERSION}'"' >> ~/.zshrc
echo "🐙 - 🎉 octavia alias was added to ${DETECTED_PROFILE} , please open a new terminal window or run source ${DETECTED_PROFILE}"
}

install() {
pull_image
add_alias
}

update_or_install() {
if grep -q "^alias octavia=*" ${DETECTED_PROFILE}; then
read -p "❓ - You already have an octavia alias in your profile. Do you want to update? (Y/n)" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
delete_previous_alias
install
fi
else
install
fi
}

set -e
check_docker_is_running
detect_profile
set -u
update_or_install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!
image

4 changes: 2 additions & 2 deletions octavia-cli/octavia_cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def add_commands_to_octavia():
octavia.add_command(command)


@octavia.command(name="import", help="Import an existing resources from the Airbyte instance.")
@octavia.command(name="import", help="[NOT IMPLEMENTED] Import an existing resources from the Airbyte instance.")
def _import() -> None:
raise click.ClickException("The import command is not yet implemented.")


@octavia.command(help="Delete resources")
@octavia.command(help="[NOT IMPLEMENTED] Delete resources")
def delete() -> None:
raise click.ClickException("The delete command is not yet implemented.")

Expand Down
2 changes: 1 addition & 1 deletion octavia-cli/octavia_cli/generate/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .definitions import BaseDefinition, ConnectionDefinition
from .yaml_dumpers import CatalogDumper

JINJA_ENV = Environment(loader=PackageLoader("octavia_cli"), autoescape=select_autoescape(), trim_blocks=False, lstrip_blocks=True)
JINJA_ENV = Environment(loader=PackageLoader(__package__), autoescape=select_autoescape(), trim_blocks=False, lstrip_blocks=True)


class FieldToRender:
Expand Down
2 changes: 1 addition & 1 deletion octavia-cli/octavia_cli/list/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def sources_connectors(ctx: click.Context):
click.echo(definitions)


@connectors.command(name="destination", help="Latest information on supported destinations.")
@connectors.command(name="destinations", help="Latest information on supported destinations.")
@click.pass_context
def destinations_connectors(ctx: click.Context):
api_client = ctx.obj["API_CLIENT"]
Expand Down
6 changes: 6 additions & 0 deletions octavia-cli/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eux
VERSION=$1
docker tag airbyte/octavia-cli:dev airbyte/octavia-cli:${VERSION}
docker push airbyte/octavia-cli:${VERSION}
4 changes: 2 additions & 2 deletions octavia-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"Tracker": "https://github.com/airbytehq/airbyte/issues",
},
packages=find_packages(exclude=("unit_tests", "integration_tests", "docs")),
package_data={"octavia_cli.generate": ["templates/*.j2"]},
install_requires=[
"click~=8.0.3",
f"airbyte_api_client @ file://{os.getcwd()}/build/airbyte_api_client",
"jinja2~=3.0.3",
"deepdiff~=5.7.0",
"PyYAML~=6.0",
"pyhumps~=3.5.3",
"pyyaml~=6.0",
],
python_requires=">=3.8.12",
extras_require={
Expand Down