This commit is contained in:
Atul Bagga 2019-10-04 13:17:51 +05:30
Родитель e720a1083e
Коммит 3607179124
6 изменённых файлов: 20 добавлений и 18 удалений

Просмотреть файл

@ -7,14 +7,8 @@ from knack.help_files import helps
def load_admin_help():
# helps['aks'] = """
# type: group
# short-summary: Manage administration operations.
# long-summary:
# """
helps['aks up'] = """
type: command
short-summary: Deploy to AKS via GH actions.
short-summary: Deploy to AKS via GitHub actions.
long-summary:
"""

Просмотреть файл

@ -14,10 +14,18 @@ logger = get_logger(__name__)
def aks_deploy(aks_cluster=None, acr=None, repository=None):
"""Build and Deploy to AKS via GitHub actions
:param aks_cluster: Name of the cluster to select for deployment.
:type aks_cluster: str
:param acr: Name of the Azure Container Registry to be used for pushing the image.
:type acr: str
:param repository: GitHub repository URL e.g. https://github.com/azure/azure-cli.
:type repository: str
"""
if repository is None:
repository = get_repository_url_from_local_repo()
logger.debug('Github Remote url detected local repo is {}'.format(repository))
if not repository:
repository = prompt('GitHub Repository url (e.g. https://github.com/atbagga/aks-deploy):')
if not repository:
raise CLIError('The following arguments are required: --repository.')
repo_name = _get_repo_name_from_repo_url(repository)
@ -35,20 +43,20 @@ def aks_deploy(aks_cluster=None, acr=None, repository=None):
if acr is None:
acr_details = get_acr_details(acr)
logger.debug(acr_details)
files = get_yaml_template_for_repo(languages.keys(), cluster_details, acr_details)
files = get_yaml_template_for_repo(languages.keys(), cluster_details, acr_details, repo_name)
# File checkin
logger.warning('Setting up your workflow. This will require 1 or more files to be checkedin to the repository.')
for file_name in files:
logger.warning("Checkin file path: {}".format(file_name.path))
logger.debug("Checkin file path: {}".format(file_name.path))
logger.debug("Checkin file content: {}".format(file_name.content))
push_files_github(files, repo_name, 'master', True, message="Setting up CI/CD with Azure CLI")
logger.warning('GitHub workflow is setup for continuous deployment.')
push_files_github(files, repo_name, 'master', True, message="Setting up K8s deployment workflow.")
print('')
print('GitHub workflow is setup for continuous deployment.')
return
def get_yaml_template_for_repo(languages, cluster_details, acr_details):
def get_yaml_template_for_repo(languages, cluster_details, acr_details, repo_name):
if 'JavaScript' in languages and 'Dockerfile' in languages:
logger.warning('Nodejs with dockerfile repository detected.')
files_to_return = []

Просмотреть файл

@ -34,7 +34,7 @@ def get_aks_details(name=None):
for aks_clusters in aks_list:
if not name:
cluster_choice_list.append(aks_clusters['name'])
elif name.lower() == aks_clusters['name']:
elif name.lower() == aks_clusters['name'].lower():
return aks_clusters
if name is not None:
raise CLIError('Cluster with name {} could not be found. Please check using command az aks list.'.format(name))
@ -57,7 +57,7 @@ def get_acr_details(name=None):
for acr_clusters in acr_list:
if not name:
registry_choice_list.append(acr_clusters['name'])
elif name.lower() == acr_clusters['name']:
elif name.lower() == acr_clusters['name'].lower():
return acr_clusters
if name is not None:
raise CLIError('Container Registry with name {} could not be found. Please check using command az acr list.'.format(name))

Просмотреть файл

@ -161,7 +161,7 @@ def commit_file_to_github_branch(path_to_commit, content, repo_name, branch, mes
logger.warning('Checking in file %s in the Github repository %s', path_to_commit, repo_name)
response = requests.put(url_for_github_file_api, auth=('', token),
json=request_body, headers=headers)
logger.debug(response)
logger.debug(response.text)
if not response.status_code == _HTTP_CREATED_STATUS:
raise CLIError('GitHub file checkin failed for file ({file}). Status Code ({code}).'.format(
file=path_to_commit, code=response.status_code))

Просмотреть файл

@ -1,5 +1,5 @@
DEPLOY_TO_AKS_TEMPLATE = """name: CI
on: [push]
on: [push, pull_request]
jobs:
build:

Просмотреть файл

@ -3,4 +3,4 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
VERSION = "0.0.1"
VERSION = "0.0.2"