Skip to content

Commit

Permalink
[INF-179] Add audius-cloud (#3575)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheran-senthil authored Aug 2, 2022
1 parent c59af06 commit 20d665b
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 7 deletions.
171 changes: 171 additions & 0 deletions dev-tools/audius-cloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/usr/bin/env python3

import subprocess
import uuid
import time

import click


def wait_for_instance(name):
while True:
try:
subprocess.check_output(
["gcloud", "compute", "ssh", f"audius@{name}", "--", "exit 0"]
)
break
except subprocess.CalledProcessError:
time.sleep(1)


@click.group()
def cli():
pass


@cli.command()
@click.pass_context
def create_image(ctx):
name = f"audius-cloud-{uuid.uuid4()}"

ctx.invoke(
create_raw,
name=name,
gcloud_args=[
"--boot-disk-size=64G",
"--no-boot-disk-auto-delete",
"--boot-disk-type=pd-balanced",
],
)

ctx.invoke(delete, gcloud_args=[name])

subprocess.run(
[
"gcloud",
"compute",
"images",
"create",
"audius-protocol-dev",
f"--source-disk={name}",
],
check=True,
)

subprocess.run(
[
"gcloud",
"compute",
"disks",
"delete",
"--quiet", # disable prompt
name,
],
check=True,
)


@cli.command(context_settings=dict(ignore_unknown_options=True))
@click.argument("name")
@click.argument("gcloud-args", nargs=-1, type=click.UNPROCESSED)
def create(name, gcloud_args):
subprocess.run(
[
"gcloud",
"compute",
"instances",
"create",
"--machine-type=e2-custom-6-24576",
"--boot-disk-size=256G",
"--image=audius-protocol-dev",
name,
*gcloud_args,
],
check=True,
)


@cli.command(context_settings=dict(ignore_unknown_options=True))
@click.argument("name")
@click.argument("gcloud-args", nargs=-1, type=click.UNPROCESSED)
def create_raw(name, gcloud_args):
click.secho(f"Creating instance {name}", fg="green")

subprocess.run(
[
"gcloud",
"compute",
"instances",
"create",
"--machine-type=e2-custom-6-24576",
"--boot-disk-size=256G",
name,
*gcloud_args,
],
check=True,
)

click.secho(f"Waiting for instance {name} to be ready", fg="green")

wait_for_instance(name)

click.secho("Setting up audius-protocol on instance", fg="green")

subprocess.run(
[
"gcloud",
"compute",
"ssh",
f"audius@{name}",
"--",
"curl 'https://raw.githubusercontent.com/AudiusProject/audius-protocol/master/dev-tools/setup.sh' | bash",
],
check=True,
)

subprocess.run(
[
"gcloud",
"compute",
"ssh",
f"audius@{name}",
"--",
"cd ~/audius-protocol && PROTOCOL_DIR=$PWD ~/.local/bin/audius-compose build && docker compose pull",
],
check=True,
)


@cli.command(context_settings=dict(ignore_unknown_options=True))
@click.argument("gcloud-args", nargs=-1, type=click.UNPROCESSED)
def delete(gcloud_args):
subprocess.run(
[
"gcloud",
"compute",
"instances",
"delete",
"--quiet", # disable prompt
*gcloud_args,
],
check=True,
)


@cli.command(context_settings=dict(ignore_unknown_options=True))
@click.argument("gcloud-args", nargs=-1, type=click.UNPROCESSED)
def describe(gcloud_args):
subprocess.run(
[
"gcloud",
"compute",
"instances",
"describe",
*gcloud_args,
],
check=True,
)


if __name__ == "__main__":
cli()
14 changes: 7 additions & 7 deletions dev-tools/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ debian | ubuntu)
sudo apt-get install -y git python3 python3-pip docker-ce docker-ce-cli containerd.io docker-compose-plugin

# Add user to docker group
sudo usermod -aG docker $USER
sudo usermod -aG docker "$USER"
;;
*)
if ! command -v docker &>/dev/null; then
Expand All @@ -46,18 +46,18 @@ debian | ubuntu)
esac

if [[ "${BASH_SOURCE[0]}" == "" ]]; then
git clone https://github.com/AudiusProject/audius-protocol.git ~/audius-protocol
export PROTOCOL_DIR="$HOME/audius-protocol"
export PROTOCOL_DIR="${PROTOCOL_DIR:-$HOME/audius-protocol}"
git clone https://github.com/AudiusProject/audius-protocol.git "$PROTOCOL_DIR"
else
export PROTOCOL_DIR="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
fi

python3 -m pip install -r $PROTOCOL_DIR/dev-tools/requirements.txt
python3 -m pip install -r "$PROTOCOL_DIR/dev-tools/requirements.txt"

mkdir -p "$HOME/.local/bin"

ln -sf "$PROTOCOL_DIR/dev-tools/audius-compose" "$HOME/.local/bin/audius-compose"
# ln -sf "$PROTOCOL_DIR/dev-tools/audius-cloud" "$HOME/.local/bin/audius-cloud"
ln -sf "$PROTOCOL_DIR/dev-tools/audius-cloud" "$HOME/.local/bin/audius-cloud"

echo "export PROTOCOL_DIR=$PROTOCOL_DIR" >>~/.bashrc
echo "export PATH=$HOME/.local/bin:$PATH" >>~/.bashrc
echo "export PROTOCOL_DIR=$PROTOCOL_DIR" >>~/.profile
echo "export PATH=$HOME/.local/bin:$PATH" >>~/.profile

0 comments on commit 20d665b

Please sign in to comment.