diff --git a/octavia-cli/Dockerfile b/octavia-cli/Dockerfile index 9313773b20d4b..040a18665e5ed 100644 --- a/octavia-cli/Dockerfile +++ b/octavia-cli/Dockerfile @@ -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 diff --git a/octavia-cli/README.md b/octavia-cli/README.md index 26b2242a834b8..48845908f4782 100644 --- a/octavia-cli/README.md +++ b/octavia-cli/README.md @@ -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 ```` # Current development status @@ -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. diff --git a/octavia-cli/install.sh b/octavia-cli/install.sh new file mode 100755 index 0000000000000..bf6db25eb2865 --- /dev/null +++ b/octavia-cli/install.sh @@ -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 diff --git a/octavia-cli/octavia_cli/entrypoint.py b/octavia-cli/octavia_cli/entrypoint.py index c2ca8c12c5cb9..6160d64d47f1a 100644 --- a/octavia-cli/octavia_cli/entrypoint.py +++ b/octavia-cli/octavia_cli/entrypoint.py @@ -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.") diff --git a/octavia-cli/octavia_cli/generate/renderers.py b/octavia-cli/octavia_cli/generate/renderers.py index be50654e0cacb..b26dfc53ebcab 100644 --- a/octavia-cli/octavia_cli/generate/renderers.py +++ b/octavia-cli/octavia_cli/generate/renderers.py @@ -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: diff --git a/octavia-cli/octavia_cli/templates/connection.yaml.j2 b/octavia-cli/octavia_cli/generate/templates/connection.yaml.j2 similarity index 100% rename from octavia-cli/octavia_cli/templates/connection.yaml.j2 rename to octavia-cli/octavia_cli/generate/templates/connection.yaml.j2 diff --git a/octavia-cli/octavia_cli/templates/source_or_destination.yaml.j2 b/octavia-cli/octavia_cli/generate/templates/source_or_destination.yaml.j2 similarity index 100% rename from octavia-cli/octavia_cli/templates/source_or_destination.yaml.j2 rename to octavia-cli/octavia_cli/generate/templates/source_or_destination.yaml.j2 diff --git a/octavia-cli/octavia_cli/list/commands.py b/octavia-cli/octavia_cli/list/commands.py index 50e44182a9a2b..c181d69d247a4 100644 --- a/octavia-cli/octavia_cli/list/commands.py +++ b/octavia-cli/octavia_cli/list/commands.py @@ -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"] diff --git a/octavia-cli/publish.sh b/octavia-cli/publish.sh new file mode 100755 index 0000000000000..884d141aeae3a --- /dev/null +++ b/octavia-cli/publish.sh @@ -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} diff --git a/octavia-cli/setup.py b/octavia-cli/setup.py index f094e7beec9ff..47ac64c59bc02 100644 --- a/octavia-cli/setup.py +++ b/octavia-cli/setup.py @@ -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={