Skip to content
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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,4 @@ audius-cli launch <service-name>
# Options:
# --seed
# Seeds the database from a snapshot. Required for first-time discovery setup.
# --environment [stage, prod]
# Uses environment variables for the relevant environment.
```
53 changes: 31 additions & 22 deletions audius-cli
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ SERVICE_PORTS = {
}

service_type = click.Choice(["creator-node", "discovery-provider"])
environment = click.Choice(["prod", "stage"])
network_type = click.Choice(["prod", "stage"])
container_type = click.Choice(["backend", "cache", "db"])


def update_base_env(ctx, environment):
"""
Sets the base env in .env for each service and
returns the name of the base env file to use.
"""
for service in ["creator-node", "discovery-provider"]:
env_file = ctx.obj["manifests_path"] / service / ".env"
dotenv.set_key(env_file, "ENV", environment)
return f"{environment}.env"
def get_network(ctx, service):
"""Returns the network name for the given service."""
return dotenv.dotenv_values(ctx.obj["manifests_path"] / service / ".env").get(
"NETWORK", "prod"
)


@click.group()
Expand All @@ -50,11 +46,10 @@ def cli(ctx):

@cli.command()
@click.argument("service", type=service_type)
@click.option("--environment", type=environment, default="prod")
@click.pass_context
def check_config(ctx, service, environment):
def check_config(ctx, service):
"""Check the config for a service"""
env = ctx.obj["manifests_path"] / service / update_base_env(ctx, environment)
env = ctx.obj["manifests_path"] / service / f"{get_network(ctx, service)}.env"
override_env = ctx.obj["manifests_path"] / service / "override.env"

env_data = dotenv.dotenv_values(env)
Expand Down Expand Up @@ -137,14 +132,11 @@ def health_check(ctx, service):
@cli.command()
@click.argument("service", type=service_type)
@click.option("--seed", is_flag=True)
@click.option("--environment", type=environment, default="prod")
@click.pass_context
def launch(ctx, service, seed, environment):
def launch(ctx, service, seed):
"""Launch the service"""
update_base_env(ctx, environment)

try:
ctx.invoke(check_config, service=service, environment=environment)
ctx.invoke(check_config, service=service)
except SystemExit:
pass

Expand All @@ -168,7 +160,7 @@ def launch(ctx, service, seed, environment):
"docker",
"compose",
"--project-directory",
ctx.obj["manifests_path"] / service,
ctx.obj["manifests_path"] / "discovery-provider",
"down",
"backend",
],
Expand Down Expand Up @@ -267,15 +259,14 @@ def restart(ctx, service, containers):
@click.argument("value", required=False)
@click.option("--unset", is_flag=True)
@click.option("--required", is_flag=True)
@click.option("--environment", type=environment, default="prod")
@click.pass_context
def set_config(ctx, service, unset, required, key, value, environment):
def set_config(ctx, service, unset, required, key, value):
"""Set a config value"""
if required and (key or value):
click.secho("--required cannot be used when key or value is set", fg="red")
sys.exit(1)

env = ctx.obj["manifests_path"] / service / update_base_env(ctx, environment)
env = ctx.obj["manifests_path"] / service / f"{get_network(ctx, service)}.env"
env_data = dotenv.dotenv_values(env)

override_env = ctx.obj["manifests_path"] / service / "override.env"
Expand Down Expand Up @@ -324,6 +315,24 @@ def set_tag(ctx, unset, tag):
dotenv.set_key(env_file, "TAG", tag)


@cli.command()
@click.argument("network", type=network_type, required=False)
@click.option("--unset", is_flag=True)
@click.pass_context
def set_network(ctx, unset, network):
"""Set a config value"""
if not unset and network is None:
network = click.prompt(click.style("Network", bold=True))

for service in ["creator-node", "discovery-provider"]:
env_file = ctx.obj["manifests_path"] / service / ".env"

if unset:
dotenv.unset_key(env_file, "NETWORK")
else:
dotenv.set_key(env_file, "NETWORK", network)


@cli.command()
@click.argument("branch", required=False)
@click.pass_context
Expand Down
2 changes: 1 addition & 1 deletion creator-node/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
ports:
- "4000:4000"
env_file:
- ${ENV}.env
- ${NETWORK}.env
- override.env
networks:
- creator-node-network
Expand Down
6 changes: 3 additions & 3 deletions discovery-provider/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ services:
ports:
- "5000:5000"
env_file:
- ${ENV}.env
- ${NETWORK}.env
- override.env
networks:
- discovery-provider-network

seed:
image: audius/discovery-provider:${TAG:-257b60f2ff0b990138d08e618b4e364e3b27b6d7}
command: bash /usr/share/seed.sh ${ENV}
command: bash /usr/share/seed.sh ${NETWORK}
env_file:
- ${ENV}.env
- ${NETWORK}.env
- override.env
volumes:
- ./seed.sh:/usr/share/seed.sh
Expand Down
19 changes: 9 additions & 10 deletions discovery-provider/seed.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/usr/bin/bash
set -e

ENV=$1
NETWORK=$1

if [ "$ENV" == 'prod' ]
then
echo "Downloading $ENV database..."
if [[ "$NETWORK" == "prod" ]]; then
echo "Downloading $NETWORK database..."
curl https://audius-pgdump.s3-us-west-2.amazonaws.com/discProvProduction.dump -O
echo "Restoring $ENV database to $audius_db_url..."
echo "Restoring $NETWORK database to $audius_db_url..."
pg_restore -d $audius_db_url --clean --if-exists --verbose discProvProduction.dump
elif [ "$ENV" == 'stage' ]
then
echo "Downloading $ENV database..."
elif [[ "$NETWORK" == "stage" ]]; then
echo "Downloading $NETWORK database..."
curl https://audius-pgdump.s3-us-west-2.amazonaws.com/discProvStaging.dump -O
echo "Restoring $ENV database to $audius_db_url..."
echo "Restoring $NETWORK database to $audius_db_url..."
pg_restore -d $audius_db_url --clean --if-exists --verbose discProvStaging.dump
else
echo "Invalid env: $ENV"
echo "Invalid network: $NETWORK"
exit 1
fi