Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
mysql command added for deploy and run
  • Loading branch information
DaeunYim committed May 3, 2021
commit 392cecf51f1b8ea1687c81bccfba25e9cb7f1782
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ def load_flexibleserver_command_table(self, _):
g.show_command('show', 'get')
g.command('list', 'list_by_server')

with self.command_group('postgres deploy', postgres_flexible_servers_sdk,
custom_command_type=flexible_servers_custom_postgres,
client_factory=cf_postgres_flexible_servers,
is_preview=True) as g:
g.custom_command('setup', 'github_actions_setup')
g.custom_command('run', 'github_actions_run')

# MySQL commands
with self.command_group('mysql flexible-server', mysql_flexible_servers_sdk,
custom_command_type=flexible_servers_custom_mysql,
Expand Down Expand Up @@ -222,9 +229,9 @@ def load_flexibleserver_command_table(self, _):
g.custom_command('create', 'flexible_replica_create', supports_no_wait=True)
g.custom_command('stop-replication', 'flexible_replica_stop', confirmation=True)

with self.command_group('postgres deploy', postgres_flexible_servers_sdk,
custom_command_type=flexible_servers_custom_postgres,
client_factory=cf_postgres_flexible_servers,
with self.command_group('mysql deploy', mysql_flexible_servers_sdk,
custom_command_type=flexible_servers_custom_common,
client_factory=cf_mysql_flexible_servers,
is_preview=True) as g:
g.custom_command('setup', 'github_actions_setup')
g.custom_command('run', 'github_actions_run')
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from knack.log import get_logger
from knack.util import CLIError
from ._flexible_server_util import run_subprocess, run_subprocess_get_output, fill_action_template, get_git_root_dir, \
GITHUB_ACTION_PATH

logger = get_logger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from .flexible_server_custom_common import user_confirmation
from ._flexible_server_util import generate_missing_parameters, resolve_poller, create_firewall_rule, \
parse_public_access_input, generate_password, parse_maintenance_window, get_postgres_list_skus_info, \
DEFAULT_LOCATION_PG, run_subprocess, run_subprocess_get_output, fill_action_template, get_git_root_dir, \
GITHUB_ACTION_PATH
DEFAULT_LOCATION_PG
from .flexible_server_virtual_network import prepare_private_network, prepare_private_dns_zone
from .validators import pg_arguments_validator, validate_server_name

Expand Down Expand Up @@ -473,55 +472,6 @@ def _update_local_contexts(cmd, server_name, resource_group_name, location, user
cmd.cli_ctx.local_context.set([ALL], 'resource_group_name', resource_group_name)


def github_actions_setup(cmd, client, resource_group_name, server_name, database_name, administrator_login, administrator_login_password, sql_file_path, repository, action_name=None, branch=None, allow_push=None):

if allow_push and not branch:
raise RequiredArgumentMissingError("Provide remote branch name to allow pushing the action file to your remote branch.")
if action_name is None:
action_name = server.name + '_' + database_name + "_deploy"
gitcli_check_and_login()

server = client.get(resource_group_name, server_name)
fill_action_template(cmd,
server=server,
database_name=database_name,
administrator_login=administrator_login,
administrator_login_password=administrator_login_password,
file_name=sql_file_path,
repository=repository,
action_name=action_name)


action_path = get_git_root_dir() + GITHUB_ACTION_PATH + action_name + '.yml'
logger.warning("Making git commit for file {}".format(action_path))
run_subprocess("git add {}".format(action_path))
run_subprocess("git commit -m \"Add github action file\"")

if allow_push:
logger.warning("Pushing the created action file to origin {} branch".format(branch))
run_subprocess("git push origin {}".format(branch))
github_actions_run(action_name, branch)
else:
logger.warning('You did not set --allow-push parameter. Please push the prepared file {} to your remote repo and run "deploy run" command to activate the workflow.'.format(action_path))


def github_actions_run(action_name, branch):

gitcli_check_and_login()
logger.warning("Created event for {}.yml in branch {}".format(action_name, branch))
run_subprocess("gh workflow run {}.yml --ref {}".format(action_name, branch))


def gitcli_check_and_login():
output = run_subprocess_get_output("gh")
if output.returncode:
raise ClientRequestError('Please install "Github CLI" to run this command.')

output = run_subprocess_get_output("gh auth status")
if output.returncode:
run_subprocess("gh auth login", stdout_show=True)


# pylint: disable=too-many-instance-attributes, too-few-public-methods, useless-object-inheritance
class DbContext(object):
def __init__(self, azure_sdk=None, logging_name=None, cf_firewall=None, cf_db=None,
Expand Down