Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hack extension to streamline creation of resources commonly used when hacking #873

Merged
merged 48 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
61b2c68
Fixed typo on name of SQL server
May 14, 2019
79a1572
Kickoff of hack extension
May 20, 2019
a207c76
Added support for creating a database
May 22, 2019
7428040
Added simple build script for testing
May 22, 2019
80fdd5d
Create database, begin adding app service support
May 22, 2019
cbff29e
updated build for full test run
May 22, 2019
b57160f
Added support for creating website and adding app settings
May 23, 2019
b8d6728
Working on adding MySQL support
May 31, 2019
780e0f5
Added MySQL support
Jun 3, 2019
9ea4e34
Adding support for switches and runtimes
Jun 13, 2019
6e37d4a
Adding readme files
Jun 14, 2019
726aa04
STarting readme
Jun 14, 2019
9a98328
Added metadata
Jun 14, 2019
2a0a2a3
Adding support for Cognitive Services keys'
Jun 18, 2019
ead7b7c
Added support for cogsvcs
Jul 17, 2019
619d26e
adding CosmosDB support
Jul 17, 2019
d41c796
Adding support for CosmosDB
Jul 18, 2019
2b76d19
Added suppot for CosmosDB
Jul 24, 2019
ef220cb
Kickoff of hack extension
May 20, 2019
4dbbad5
Added support for creating a database
May 22, 2019
e943d0e
Added simple build script for testing
May 22, 2019
e3feda5
Create database, begin adding app service support
May 22, 2019
75648f8
updated build for full test run
May 22, 2019
2c8e24b
Added support for creating website and adding app settings
May 23, 2019
72852b1
Working on adding MySQL support
May 31, 2019
643335a
Added MySQL support
Jun 3, 2019
13172e1
Adding support for switches and runtimes
Jun 13, 2019
9ac32b9
Adding readme files
Jun 14, 2019
37f64e4
STarting readme
Jun 14, 2019
fbc2461
Added metadata
Jun 14, 2019
1e783d6
Adding support for Cognitive Services keys'
Jun 18, 2019
634c5b4
Added support for cogsvcs
Jul 17, 2019
ea66aa5
adding CosmosDB support
Jul 17, 2019
fbc3ced
Adding support for CosmosDB
Jul 18, 2019
e2d00d6
Added suppot for CosmosDB
Jul 24, 2019
bc9bc1d
Added validator and converted params to lower
Jul 30, 2019
504c2a1
Added readme
Jul 30, 2019
7082c13
Merge branch 'geektrainer/hack' of https://github.com/geektrainer/azu…
Jul 30, 2019
52f1b77
Updated readme
Jul 30, 2019
92cba25
Cleanup for linting
Jul 30, 2019
ee3c8a3
Linting issues
Jul 30, 2019
4cdec57
Removing personal testing rig
Jul 30, 2019
457611e
More linting
Jul 30, 2019
e5aa750
More linting
Jul 30, 2019
c79a9ac
Added code owner
Jul 30, 2019
d062ea0
Added licenses
Jul 30, 2019
e268647
Fixed comments
Jul 30, 2019
7c947d0
Merge branch 'master' into master
Sep 5, 2019
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
Adding support for switches and runtimes
  • Loading branch information
Christopher Harrison committed Jun 13, 2019
commit 9ea4e347a0a944caff97911f1dfc0025547bd66f
10 changes: 9 additions & 1 deletion src/hack/azext_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
from azure.cli.core import AzCommandsLoader
from azure.cli.command_modules.appservice.commands import ex_handler_factory


class HackExtCommandLoader(AzCommandsLoader):
def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
hack_custom = CliCommandType(operations_tmpl='azext_hack.custom#{}')
super(HackExtCommandLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=hack_custom,
min_profile="2017-03-10-profile")

def load_command_table(self, _):
with self.command_group('hack') as g:
g.custom_command('up', 'hack_up')
return self.command_table

def load_arguments(self, _):
with self.argument_context('hack up') as c:
c.argument('name', options_list=['--name', '-n'], help='Name of resources')
c.argument('name', options_list=[
'--name', '-n'], help='Name of resources')
c.argument('database', options_list=[
'--database', '-d'], help='Database type - { SQL | MySQL }', choices=['SQL', 'MySQL'], default='sql')
c.argument('runtime', options_list=['--runtime', '-r'], help='Runtime', choices=[
'php', 'node', 'tomcat', 'jetty', 'python', 'aspnet'])


COMMAND_LOADER_CLS = HackExtCommandLoader
12 changes: 5 additions & 7 deletions src/hack/azext_hack/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,33 @@

logger = get_logger(__name__)

def hack_up(cmd, name):
def hack_up(cmd, name, runtime, database='sql'):
location = 'westus'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have default location, but it would be nice to be able to change it. it may happen for some reason that particular resource is unavailable lin "westus" location.

runtime = 'Python|3.6'
database_admin = name + '_user'
database_password = uuid4()
output = {}
database_provider = 'mysql'

# Create RG
logger.warning("Creating resource group")
create_resource_group(cmd, name, location)
logger.warning("Created resource group")
# Create SQL server and database
logger.warning("Starting database creation job...")
database_poller = create_database(cmd, database_provider, name, location, database_admin, database_password)
database_poller = create_database(cmd, database, name, location, database_admin, database_password)
# Create app service plan and website
logger.warning("Starting website creation job...")
output = create_website(cmd, name, runtime)
output['settings'] = set_website_settings(cmd, name, database_admin, database_password)
output['settings'] = set_website_settings(cmd, name, database, database_admin, database_password)
# Database takes a while. Wait at the end for it to complete
while True:
database_poller.result(15)
if database_poller.done():
break

if output['deployment_password'] == '***':
logger.warning('Deployment user was already created. To change password use az webapp deployment user set')
logger.warning('Deployment user was already created. To change password use `az webapp deployment user set`')
else:
logger.warning('Created password for deployment user. To change use az webapp deployment user set')
logger.warning('Created password for deployment user. To change use `az webapp deployment user set`')
return output

def hack_down(cmd, name, dryrun=False, confirm=False):
Expand Down
58 changes: 49 additions & 9 deletions src/hack/azext_hack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ def create_database(cmd, database_provider, name, location, admin, password):
database_client = cf_mysql_db(cmd.cli_ctx, None)
admin = admin[:16]
database_settings['engine'] = 'django.db.backends.mysql'


def server_creator():
sku_name='B_Gen5_1'
sku_name = 'B_Gen5_1'
parameters = ServerForCreate(
sku=MySqlSku(name=sku_name),
location=location,
Expand All @@ -92,6 +91,7 @@ def server_creator():
)
)
return server_client.create(resource_group_name=name, server_name=name, parameters=parameters)

def database_creator():
print('in mysql database creator')
return database_client.create_or_update(
Expand Down Expand Up @@ -124,12 +124,52 @@ def database_creator():
return wrapper


RUNTIMES = {
'php': {
'name': 'php|7.3',
'is_linux': True
},
'node': {
'name': 'node|10.6',
'is_linux': True
},
'tomcat': {
'name': 'java|11|Tomcat|9.0',
'is_linux': True
},
'jetty': {
'name': 'java|11|Jetty|9.3',
'is_linux': True
},
'python': {
'name': 'python|3.6',
'is_linux': True
},
'aspnet': {
'name': 'aspnet|4.7',
'is_linux': False
}
}

DATABASES = {
'mysql': {
'host': '{}.mysql.database.azure.com',
'port': '3306'
},
'sql': {
'host': '{}.database.windows.net',
'port': '1433'
}
}


def create_website(cmd, name, runtime, deployment_local_git=True, deployment_user=None):
runtime_values = RUNTIMES[runtime.lower()]
deployment_user_password = None
create_app_service_plan(cmd, resource_group_name=name,
name=name, is_linux=True, hyper_v=False).result()
name=name, is_linux=runtime_values['is_linux'], hyper_v=False).result()
webapp = create_webapp(cmd, resource_group_name=name,
name=name, plan=name, runtime=runtime,
name=name, plan=name, runtime=runtime_values['name'],
deployment_local_git=deployment_local_git)
if deployment_user:
deployment_user_password = uuid4()
Expand All @@ -145,15 +185,15 @@ def create_website(cmd, name, runtime, deployment_local_git=True, deployment_use
site['hostname'] = 'https://{}'.format(webapp.host_names[0])
return site


def set_website_settings(cmd, name, database_admin, database_password):
def set_website_settings(cmd, name, database_provider, database_admin, database_password):
# TODO: Update username to avoid issues
database_options = DATABASES[database_provider.lower()]
settings = []
settings.append('DATABASE_NAME={}'.format(name))
settings.append('DATABASE_HOST={}.database.windows.net'.format(name))
settings.append('DATABASE_PORT=1433')
settings.append('DATABASE_HOST={}'.format(database_options['host'].format(name)))
settings.append('DATABASE_PORT={}'.format(database_options['port']))
settings.append('DATABASE_USER={}'.format(database_admin))
settings.append('DATABASE_PASSWORD={}'.format(database_admin))
settings.append('DATABASE_PASSWORD={}'.format(database_password))
update_app_settings(cmd, resource_group_name=name,
name=name, settings=settings)
return settings
2 changes: 1 addition & 1 deletion src/hack/build.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
az group delete -n geektrainertesting -y && az extension remove -n hack && python setup.py bdist_wheel && az extension add --source .\dist\hack-0.2.17-py2.py3-none-any.whl -y && az hack up -n geektrainertesting
az group delete -n geektrainertesting -y && az extension remove -n hack && python setup.py bdist_wheel && az extension add --source .\dist\hack-0.2.17-py2.py3-none-any.whl -y && az hack up -n geektrainertesting -d MySQL -r php