Skip to content

Commit ad20f00

Browse files
authored
🐙 octavia-cli: package and install script (#10823)
1 parent 1b85ff7 commit ad20f00

File tree

10 files changed

+104
-19
lines changed

10 files changed

+104
-19
lines changed

octavia-cli/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN pip install --no-cache-dir .
1111
RUN useradd --create-home --shell /bin/bash octavia-cli
1212
USER octavia-cli
1313

14+
WORKDIR /home/octavia-project
1415
ENTRYPOINT ["octavia"]
1516

1617
LABEL io.airbyte.version=dev

octavia-cli/README.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ It has the following features:
1010

1111
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.
1212

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

17-
1. Build the project locally (from the root of the repo):
15+
## 1. Install and run Docker
16+
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/)**.
17+
18+
## 2.a If you are using ZSH / Bash:
1819
```bash
19-
SUB_BUILD=OCTAVIA_CLI ./gradlew build #from the root of the repo
20+
curl -o- https://raw.githubusercontent.com/airbytehq/airbyte/master/octavia-cli/install.sh | bash
2021
```
21-
2. Run the CLI from docker:
22+
23+
This script:
24+
1. Pulls the [octavia-cli image](https://hub.docker.com/r/airbyte/octavia-cli/tags) from our Docker registry.
25+
2. Creates an `octavia` alias in your profile.
26+
27+
## 2.b If you want to directly run the CLI without alias in your current directory:
2228
```bash
23-
docker run airbyte/octavia-cli:dev
24-
````
25-
3. Create an `octavia` alias in your `.bashrc` or `.zshrc`:
26-
````bash
27-
echo 'alias octavia="docker run airbyte/octavia-cli:dev"' >> ~/.zshrc
28-
source ~/.zshrc
29-
octavia
29+
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
3030
````
3131

3232
# Current development status
@@ -56,6 +56,11 @@ We welcome community contributions!
5656
6. Run the unittest suite: `pytest --cov=octavia_cli`
5757
7. Iterate: please check the [Contributing](#contributing) for instructions on contributing.
5858
59+
## Build
60+
Build the project locally (from the root of the repo):
61+
```bash
62+
SUB_BUILD=OCTAVIA_CLI ./gradlew build # from the root directory of the repo
63+
```
5964
# Contributing
6065
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.
6166
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.

octavia-cli/install.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
# This install scripts currently only works for ZSH and Bash profiles.
4+
# It creates an octavia alias in your profile bound to a docker run command
5+
6+
VERSION=dev
7+
8+
detect_profile() {
9+
if [ "${SHELL#*bash}" != "$SHELL" ]; then
10+
if [ -f "$HOME/.bashrc" ]; then
11+
DETECTED_PROFILE="$HOME/.bashrc"
12+
elif [ -f "$HOME/.bash_profile" ]; then
13+
DETECTED_PROFILE="$HOME/.bash_profile"
14+
fi
15+
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
16+
if [ -f "$HOME/.zshrc" ]; then
17+
DETECTED_PROFILE="$HOME/.zshrc"
18+
fi
19+
fi
20+
21+
if [ -z "${DETECTED_PROFILE}" ]; then
22+
echo "🚨 - Cannot install! This scripts only works if you are using one of these profiles: ~/.bashrc, ~/.bash_profile or ~/.zshrc"
23+
exit 1
24+
else
25+
echo "octavia alias will be added to ${DETECTED_PROFILE}"
26+
fi
27+
}
28+
29+
check_docker_is_running() {
30+
if ! docker info > /dev/null 2>&1; then
31+
echo "🚨 - This script uses docker, and it isn't running - please start docker and try again!"
32+
exit 1
33+
fi
34+
}
35+
36+
delete_previous_alias() {
37+
sed -i'' -e '/^alias octavia=/d' ${DETECTED_PROFILE}
38+
}
39+
40+
41+
pull_image() {
42+
docker pull airbyte/octavia-cli:${VERSION} > /dev/null 2>&1
43+
}
44+
45+
add_alias() {
46+
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
47+
echo "🐙 - 🎉 octavia alias was added to ${DETECTED_PROFILE} , please open a new terminal window or run source ${DETECTED_PROFILE}"
48+
}
49+
50+
install() {
51+
pull_image
52+
add_alias
53+
}
54+
55+
update_or_install() {
56+
if grep -q "^alias octavia=*" ${DETECTED_PROFILE}; then
57+
read -p "❓ - You already have an octavia alias in your profile. Do you want to update? (Y/n)" -n 1 -r
58+
echo # (optional) move to a new line
59+
if [[ $REPLY =~ ^[Yy]$ ]]
60+
then
61+
delete_previous_alias
62+
install
63+
fi
64+
else
65+
install
66+
fi
67+
}
68+
69+
set -e
70+
check_docker_is_running
71+
detect_profile
72+
set -u
73+
update_or_install

octavia-cli/octavia_cli/entrypoint.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def add_commands_to_octavia():
6262
octavia.add_command(command)
6363

6464

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

6969

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

octavia-cli/octavia_cli/generate/renderers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .definitions import BaseDefinition, ConnectionDefinition
1414
from .yaml_dumpers import CatalogDumper
1515

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

1818

1919
class FieldToRender:

octavia-cli/octavia_cli/list/commands.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def sources_connectors(ctx: click.Context):
3535
click.echo(definitions)
3636

3737

38-
@connectors.command(name="destination", help="Latest information on supported destinations.")
38+
@connectors.command(name="destinations", help="Latest information on supported destinations.")
3939
@click.pass_context
4040
def destinations_connectors(ctx: click.Context):
4141
api_client = ctx.obj["API_CLIENT"]

octavia-cli/publish.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
VERSION=$1
5+
docker tag airbyte/octavia-cli:dev airbyte/octavia-cli:${VERSION}
6+
docker push airbyte/octavia-cli:${VERSION}

octavia-cli/setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
"Tracker": "https://github.com/airbytehq/airbyte/issues",
4242
},
4343
packages=find_packages(exclude=("unit_tests", "integration_tests", "docs")),
44+
package_data={"octavia_cli.generate": ["templates/*.j2"]},
4445
install_requires=[
4546
"click~=8.0.3",
4647
f"airbyte_api_client @ file://{os.getcwd()}/build/airbyte_api_client",
4748
"jinja2~=3.0.3",
4849
"deepdiff~=5.7.0",
49-
"PyYAML~=6.0",
50-
"pyhumps~=3.5.3",
50+
"pyyaml~=6.0",
5151
],
5252
python_requires=">=3.8.12",
5353
extras_require={

0 commit comments

Comments
 (0)