def reset(ctx: click.Context): utils.print_bold('Trying to wipe the database') command = [ 'docker-compose', '-f', constants.FULL_COMPOSE_PATH, 'run', 'initializer', 'python3', '/app/scripts/reset_db.py', ] subprocess.run( command, cwd=constants.BASE_DIR, stdout=subprocess.DEVNULL, check=False, ) utils.print_bold('Bringing down services') command = [ 'docker-compose', '-f', constants.FULL_COMPOSE_PATH, 'down', '-v', '--remove-orphans', ] utils.run_command(command, cwd=constants.BASE_DIR) utils.print_bold('Running clean') ctx.invoke(clean) utils.print_success('Done!')
def reset(ctx: click.Context): utils.print_bold('Removing skaffold-created resources') utils.run_command(['skaffold', 'delete', '-f', 'deploy/skaffold.yml'], cwd=BASE_DIR) utils.print_bold('Cleaning up') ctx.invoke(clean) utils.print_success('Done!')
def start(dev: bool, **_kwargs): utils.print_bold('Deploying using skaffold') cmd = ['skaffold', 'dev' if dev else 'run', '-f', 'deploy/skaffold.yml'] utils.run_command(cmd, cwd=BASE_DIR) utils.print_success('Deployed successfully!') utils.print_bold('Fetching the address for deployment') service_resource = get_resource_description(resource='service', name='nginx') ip = service_resource['status']['loadBalancer']['ingress'][0]['ip'] utils.print_success(f'You can access ForcAD at http://{ip}')
def print_tokens(): command = [ 'docker-compose', '-f', FULL_COMPOSE_PATH, 'exec', '-T', 'ticker', 'python3', '/app/scripts/print_tokens.py', ] run_command(command, cwd=BASE_DIR)
def print_tokens(): command = [ 'kubectl', '--namespace', 'forcad', 'exec', 'deployment/ticker', '--', 'python3', '/app/scripts/print_tokens.py', ] run_command(command, cwd=BASE_DIR)
def destroy(): tf_out = get_terraform_outputs() cluster_id = tf_out['cluster-id']['value'] registry_id = tf_out['registry-id']['value'] entry_name = f'yc-managed-k8s-{cluster_id}' to_unset = [ f'users.{entry_name}', 'contexts.yc-forcad', f'clusters.{entry_name}' ] for entry in to_unset: utils.run_command(['kubectl', 'config', 'unset', entry]) click.echo('Cleaning up the registry') cmd = [ 'yc', 'container', 'image', 'list', '--registry-id', registry_id, '--format', 'json', ] registry_images = json.loads(utils.get_output(cmd)) for image in registry_images: image_id = image['id'] image_name = image['name'] click.echo(f'Removing image {image_name}') utils.run_command(['yc', 'container', 'image', 'delete', image_id]) utils.run_command( ['terraform', 'destroy', '-auto-approve'], cwd=constants.TERRAFORM_DIR, ) utils.run_command(['skaffold', 'config', 'unset', 'default-repo'])
def build(**_kwargs): cmd = ['skaffold', 'build', '-f', 'deploy/skaffold.yml'] run_command(cmd, cwd=BASE_DIR)
def create(ctx: click.Context): ctx.invoke(validate, full=False, yandex=True) utils.backup_config() basic_config = utils.load_basic_config() config = utils.setup_auxiliary_structure(basic_config) utils.dump_config(config) utils.run_command(['terraform', 'init'], cwd=constants.TERRAFORM_DIR) if not constants.TF_CREDENTIALS_PATH.exists(): zone_choices = click.Choice([f'ru-central1-{c}' for c in 'abc']) data = { "yandex_cloud_token": click.prompt('Enter your YC OAuth token'), "yandex_cloud_id": click.prompt('Enter your YC cloud id'), "yandex_folder_id": click.prompt('Enter your YC folder id'), "yandex_zone": click.prompt( 'In which zone will you deploy ForcAD?', type=zone_choices, default=zone_choices.choices[0], ), } else: data = json.loads(constants.TF_CREDENTIALS_PATH.read_text()) data['db_password'] = config.storages.db.password data['db_user'] = config.storages.db.user data['db_name'] = config.storages.db.dbname constants.TF_CREDENTIALS_PATH.write_text(json.dumps(data)) utils.run_command(['terraform', 'plan'], cwd=constants.TERRAFORM_DIR) click.confirm( click.style('Does the plan above look ok?', bold=True), abort=True, ) utils.print_bold('Applying the plan with Terraform') utils.run_command( ['terraform', 'apply', '-auto-approve'], cwd=constants.TERRAFORM_DIR, ) tf_out = get_terraform_outputs() cluster_id = tf_out['cluster-id']['value'] folder_id = tf_out['folder-id']['value'] registry_id = tf_out['registry-id']['value'] postgres_fqdn = tf_out['postgres-fqdn']['value'] redis_fqdn = tf_out['redis-fqdn']['value'] utils.print_bold('Adding cluster config to kubectl') cmd = [ 'yc', 'managed-kubernetes', 'cluster', 'get-credentials', '--id', cluster_id, '--folder-id', folder_id, '--context-name', 'yc-forcad', '--external', '--force', ] utils.run_command(cmd) utils.print_bold('New kubectl config:') utils.run_command(['kubectl', 'config', 'view']) utils.print_bold('Configuring local docker to authenticate in YC registry') utils.run_command(['yc', 'container', 'registry', 'configure-docker']) repo = f'cr.yandex/{registry_id}' utils.print_bold(f'Configuring skaffold to use repo {repo} by default') utils.run_command(['skaffold', 'config', 'set', 'default-repo', repo]) database = f'{postgres_fqdn}:6432' redis = f'{redis_fqdn}:6379' utils.print_bold(f'Postgres full address is {database}') utils.print_bold(f'Redis full address is {redis}') ctx.invoke(setup, database=database, redis=redis, rabbitmq=None)