diff --git a/README.md b/README.md index f684372..a527807 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Azure Devops Build Manager For Azure Functions +# Azure Devops Build Manager For Azure Functions (Under Development) This project provides the class AzureDevopsBuildManager and supporting classes. This manager class allows -the caller to manage Azure Devops pipelines that are maintained within an Azure Devops account. This project was created to be able to support command line tooling for the AZ Cli. +the caller to manage Azure Devops pipelines that are maintained within an Azure Devops account. ## Install ``` @@ -13,7 +13,7 @@ To use the API, you need to first establish a connection to azure by loging into ```python from azure.cli.core import get_default_cli from azure.cli.core._profile import Profile -from azure_devops_build_manager.organization.organization_manager import OrganizationManager +from azure_functions_devops_build.organization.organization_manager import OrganizationManager import pprint # Get your token from the az login cache @@ -21,11 +21,15 @@ cli_ctx = get_default_cli() profile = Profile(cli_ctx=cli_ctx) creds, _, _ = profile.get_login_credentials(subscription_id=None) -# Create an organization manager using your credentials +# Create an organization manager and user manager using your credentials organization_manager = OrganizationManager(creds=creds) +user_manager = UserManager(creds=creds) + +# Get your user id +userid = user_manager.get_user_id() # Get the list of organizations for your user -organizations = organization_manager.list_organizations() +organizations = organization_manager.get_organizations(userid.id) # Show details about each organization in the console for organization in organizations: diff --git a/azure_devops_build_manager/__init__.py b/azure_functions_devops_build/__init__.py similarity index 100% rename from azure_devops_build_manager/__init__.py rename to azure_functions_devops_build/__init__.py diff --git a/azure_devops_build_manager/artifact/__init__.py b/azure_functions_devops_build/artifact/__init__.py similarity index 100% rename from azure_devops_build_manager/artifact/__init__.py rename to azure_functions_devops_build/artifact/__init__.py diff --git a/azure_devops_build_manager/artifact/artifact_manager.py b/azure_functions_devops_build/artifact/artifact_manager.py similarity index 93% rename from azure_devops_build_manager/artifact/artifact_manager.py rename to azure_functions_devops_build/artifact/artifact_manager.py index 332a2d2..e5838d2 100644 --- a/azure_devops_build_manager/artifact/artifact_manager.py +++ b/azure_functions_devops_build/artifact/artifact_manager.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devops_build_manager.base.base_manager import BaseManager +from ..base.base_manager import BaseManager class ArtifactManager(BaseManager): """ Manage DevOps Artifacts diff --git a/azure_devops_build_manager/base/__init__.py b/azure_functions_devops_build/base/__init__.py similarity index 100% rename from azure_devops_build_manager/base/__init__.py rename to azure_functions_devops_build/base/__init__.py diff --git a/azure_devops_build_manager/base/base_manager.py b/azure_functions_devops_build/base/base_manager.py similarity index 100% rename from azure_devops_build_manager/base/base_manager.py rename to azure_functions_devops_build/base/base_manager.py diff --git a/azure_devops_build_manager/builder/__init__.py b/azure_functions_devops_build/builder/__init__.py similarity index 100% rename from azure_devops_build_manager/builder/__init__.py rename to azure_functions_devops_build/builder/__init__.py diff --git a/azure_devops_build_manager/builder/builder_manager.py b/azure_functions_devops_build/builder/builder_manager.py similarity index 97% rename from azure_devops_build_manager/builder/builder_manager.py rename to azure_functions_devops_build/builder/builder_manager.py index 9a95602..3bd9f70 100644 --- a/azure_devops_build_manager/builder/builder_manager.py +++ b/azure_functions_devops_build/builder/builder_manager.py @@ -4,10 +4,8 @@ # -------------------------------------------------------------------------------------------- import vsts.build.v4_1.models as build_models -import time - -from azure_devops_build_manager.base.base_manager import BaseManager -from azure_devops_build_manager.pool.pool_manager import PoolManager +from ..base.base_manager import BaseManager +from ..pool.pool_manager import PoolManager class BuilderManager(BaseManager): diff --git a/azure_devops_build_manager/constants.py b/azure_functions_devops_build/constants.py similarity index 100% rename from azure_devops_build_manager/constants.py rename to azure_functions_devops_build/constants.py diff --git a/azure_devops_build_manager/extension/__init__.py b/azure_functions_devops_build/extension/__init__.py similarity index 100% rename from azure_devops_build_manager/extension/__init__.py rename to azure_functions_devops_build/extension/__init__.py diff --git a/azure_devops_build_manager/extension/extension_manager.py b/azure_functions_devops_build/extension/extension_manager.py similarity index 95% rename from azure_devops_build_manager/extension/extension_manager.py rename to azure_functions_devops_build/extension/extension_manager.py index 40a2c57..1a43ab9 100644 --- a/azure_devops_build_manager/extension/extension_manager.py +++ b/azure_functions_devops_build/extension/extension_manager.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devops_build_manager.base.base_manager import BaseManager +from ..base.base_manager import BaseManager class ExtensionManager(BaseManager): """ Manage DevOps Extensions diff --git a/azure_devops_build_manager/organization/__init__.py b/azure_functions_devops_build/organization/__init__.py similarity index 100% rename from azure_devops_build_manager/organization/__init__.py rename to azure_functions_devops_build/organization/__init__.py diff --git a/azure_devops_build_manager/organization/models/__init__.py b/azure_functions_devops_build/organization/models/__init__.py similarity index 100% rename from azure_devops_build_manager/organization/models/__init__.py rename to azure_functions_devops_build/organization/models/__init__.py diff --git a/azure_devops_build_manager/organization/models/new_organization.py b/azure_functions_devops_build/organization/models/new_organization.py similarity index 100% rename from azure_devops_build_manager/organization/models/new_organization.py rename to azure_functions_devops_build/organization/models/new_organization.py diff --git a/azure_devops_build_manager/organization/models/organization_details.py b/azure_functions_devops_build/organization/models/organization_details.py similarity index 100% rename from azure_devops_build_manager/organization/models/organization_details.py rename to azure_functions_devops_build/organization/models/organization_details.py diff --git a/azure_devops_build_manager/organization/models/organizations.py b/azure_functions_devops_build/organization/models/organizations.py similarity index 100% rename from azure_devops_build_manager/organization/models/organizations.py rename to azure_functions_devops_build/organization/models/organizations.py diff --git a/azure_devops_build_manager/organization/models/region_details.py b/azure_functions_devops_build/organization/models/region_details.py similarity index 100% rename from azure_devops_build_manager/organization/models/region_details.py rename to azure_functions_devops_build/organization/models/region_details.py diff --git a/azure_devops_build_manager/organization/models/regions.py b/azure_functions_devops_build/organization/models/regions.py similarity index 100% rename from azure_devops_build_manager/organization/models/regions.py rename to azure_functions_devops_build/organization/models/regions.py diff --git a/azure_devops_build_manager/organization/models/validate_account_name.py b/azure_functions_devops_build/organization/models/validate_account_name.py similarity index 100% rename from azure_devops_build_manager/organization/models/validate_account_name.py rename to azure_functions_devops_build/organization/models/validate_account_name.py diff --git a/azure_devops_build_manager/organization/organization_manager.py b/azure_functions_devops_build/organization/organization_manager.py similarity index 99% rename from azure_devops_build_manager/organization/organization_manager.py rename to azure_functions_devops_build/organization/organization_manager.py index b910705..e071863 100644 --- a/azure_devops_build_manager/organization/organization_manager.py +++ b/azure_functions_devops_build/organization/organization_manager.py @@ -9,7 +9,7 @@ from msrest.service_client import ServiceClient from msrest import Configuration, Deserializer from msrest.exceptions import HttpOperationError -from azure_devops_build_manager.user.user_manager import UserManager +from ..user.user_manager import UserManager from . import models diff --git a/azure_devops_build_manager/pool/__init__.py b/azure_functions_devops_build/pool/__init__.py similarity index 100% rename from azure_devops_build_manager/pool/__init__.py rename to azure_functions_devops_build/pool/__init__.py diff --git a/azure_devops_build_manager/pool/models/__init__.py b/azure_functions_devops_build/pool/models/__init__.py similarity index 100% rename from azure_devops_build_manager/pool/models/__init__.py rename to azure_functions_devops_build/pool/models/__init__.py diff --git a/azure_devops_build_manager/pool/models/pool_details.py b/azure_functions_devops_build/pool/models/pool_details.py similarity index 100% rename from azure_devops_build_manager/pool/models/pool_details.py rename to azure_functions_devops_build/pool/models/pool_details.py diff --git a/azure_devops_build_manager/pool/models/pool_details_depth.py b/azure_functions_devops_build/pool/models/pool_details_depth.py similarity index 100% rename from azure_devops_build_manager/pool/models/pool_details_depth.py rename to azure_functions_devops_build/pool/models/pool_details_depth.py diff --git a/azure_devops_build_manager/pool/models/pools.py b/azure_functions_devops_build/pool/models/pools.py similarity index 100% rename from azure_devops_build_manager/pool/models/pools.py rename to azure_functions_devops_build/pool/models/pools.py diff --git a/azure_devops_build_manager/pool/pool_manager.py b/azure_functions_devops_build/pool/pool_manager.py similarity index 96% rename from azure_devops_build_manager/pool/pool_manager.py rename to azure_functions_devops_build/pool/pool_manager.py index 9030fc3..3d77ffc 100644 --- a/azure_devops_build_manager/pool/pool_manager.py +++ b/azure_functions_devops_build/pool/pool_manager.py @@ -8,10 +8,9 @@ from msrest.service_client import ServiceClient from msrest import Configuration, Deserializer from msrest.exceptions import HttpOperationError -from azure_devops_build_manager.base.base_manager import BaseManager +from ..base.base_manager import BaseManager from . import models - class PoolManager(BaseManager): """ Manage DevOps Pools diff --git a/azure_devops_build_manager/project/__init__.py b/azure_functions_devops_build/project/__init__.py similarity index 100% rename from azure_devops_build_manager/project/__init__.py rename to azure_functions_devops_build/project/__init__.py diff --git a/azure_devops_build_manager/project/models/__init__.py b/azure_functions_devops_build/project/models/__init__.py similarity index 100% rename from azure_devops_build_manager/project/models/__init__.py rename to azure_functions_devops_build/project/models/__init__.py diff --git a/azure_devops_build_manager/project/models/project_details.py b/azure_functions_devops_build/project/models/project_details.py similarity index 100% rename from azure_devops_build_manager/project/models/project_details.py rename to azure_functions_devops_build/project/models/project_details.py diff --git a/azure_devops_build_manager/project/models/project_failed.py b/azure_functions_devops_build/project/models/project_failed.py similarity index 100% rename from azure_devops_build_manager/project/models/project_failed.py rename to azure_functions_devops_build/project/models/project_failed.py diff --git a/azure_devops_build_manager/project/models/project_poll.py b/azure_functions_devops_build/project/models/project_poll.py similarity index 100% rename from azure_devops_build_manager/project/models/project_poll.py rename to azure_functions_devops_build/project/models/project_poll.py diff --git a/azure_devops_build_manager/project/models/projects.py b/azure_functions_devops_build/project/models/projects.py similarity index 100% rename from azure_devops_build_manager/project/models/projects.py rename to azure_functions_devops_build/project/models/projects.py diff --git a/azure_devops_build_manager/project/project_manager.py b/azure_functions_devops_build/project/project_manager.py similarity index 96% rename from azure_devops_build_manager/project/project_manager.py rename to azure_functions_devops_build/project/project_manager.py index afb8aa7..ae898ef 100644 --- a/azure_devops_build_manager/project/project_manager.py +++ b/azure_functions_devops_build/project/project_manager.py @@ -10,7 +10,7 @@ from msrest import Configuration, Deserializer from msrest.exceptions import HttpOperationError from vsts.exceptions import VstsServiceError import vsts.core.v4_1.models.team_project as team_project -from azure_devops_build_manager.base.base_manager import BaseManager +from ..base.base_manager import BaseManager from . import models @@ -26,7 +26,8 @@ class ProjectManager(BaseManager): Otherwise see BaseManager """ - def __init__(self, base_url='https://{}.visualstudio.com', organization_name="", creds=None, create_project_url='https://dev.azure.com'): + def __init__(self, base_url='https://{}.visualstudio.com', organization_name="", creds=None, + create_project_url='https://dev.azure.com'): """Inits Project as per BaseManager and adds relevant other needed fields""" super(ProjectManager, self).__init__(creds, organization_name=organization_name) base_url = base_url.format(organization_name) @@ -87,7 +88,7 @@ class ProjectManager(BaseManager): def _poll_project(self, project_id): """Helper function to poll the project""" project_created = False - while (not project_created): + while not project_created: time.sleep(1) res = self._is_project_created(project_id) logging.info('project creation is: %s', res.status) @@ -101,7 +102,7 @@ class ProjectManager(BaseManager): header_paramters = {} header_paramters['Accept'] = 'application/json' - + request = self._create_project_client.get(url, params=query_paramters) response = self._create_project_client.send(request, headers=header_paramters) diff --git a/azure_devops_build_manager/release/__init__.py b/azure_functions_devops_build/release/__init__.py similarity index 100% rename from azure_devops_build_manager/release/__init__.py rename to azure_functions_devops_build/release/__init__.py diff --git a/azure_devops_build_manager/release/release_manager.py b/azure_functions_devops_build/release/release_manager.py similarity index 97% rename from azure_devops_build_manager/release/release_manager.py rename to azure_functions_devops_build/release/release_manager.py index ecfb07b..dcfcd69 100644 --- a/azure_devops_build_manager/release/release_manager.py +++ b/azure_functions_devops_build/release/release_manager.py @@ -6,9 +6,9 @@ import logging import vsts.release.v4_1.models as models -from azure_devops_build_manager.base.base_manager import BaseManager -from azure_devops_build_manager.pool.pool_manager import PoolManager -from azure_devops_build_manager.constants import (LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS) +from ..base.base_manager import BaseManager +from ..pool.pool_manager import PoolManager +from ..constants import (LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS) class ReleaseManager(BaseManager): @@ -21,7 +21,8 @@ class ReleaseManager(BaseManager): super(ReleaseManager, self).__init__(creds, organization_name=organization_name, project_name=project_name) def create_release_definition(self, build_name, artifact_name, pool_name, service_endpoint_name, - release_definition_name, app_type, functionapp_name, storage_name, resource_name, settings=[]): + release_definition_name, app_type, functionapp_name, storage_name, + resource_name, settings=None): pool = self._get_pool_by_name(pool_name) project = self._get_project_by_name(self._project_name) print(build_name, artifact_name, pool_name, service_endpoint_name, @@ -52,7 +53,7 @@ class ReleaseManager(BaseManager): logging.error("Invalid app type provided. Correct types are: Linux Consumption: %s, Linux Dedicated: %s, Windows: %s", LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS) - if settings: + if settings is not None: settings_str = "" for setting in settings: settings_str += (setting[0] + "='" + setting[1] + "'") diff --git a/azure_devops_build_manager/respository/__init__.py b/azure_functions_devops_build/respository/__init__.py similarity index 100% rename from azure_devops_build_manager/respository/__init__.py rename to azure_functions_devops_build/respository/__init__.py diff --git a/azure_devops_build_manager/respository/models/__init__.py b/azure_functions_devops_build/respository/models/__init__.py similarity index 100% rename from azure_devops_build_manager/respository/models/__init__.py rename to azure_functions_devops_build/respository/models/__init__.py diff --git a/azure_devops_build_manager/respository/models/github_connection.py b/azure_functions_devops_build/respository/models/github_connection.py similarity index 100% rename from azure_devops_build_manager/respository/models/github_connection.py rename to azure_functions_devops_build/respository/models/github_connection.py diff --git a/azure_devops_build_manager/respository/models/repository_response.py b/azure_functions_devops_build/respository/models/repository_response.py similarity index 100% rename from azure_devops_build_manager/respository/models/repository_response.py rename to azure_functions_devops_build/respository/models/repository_response.py diff --git a/azure_devops_build_manager/respository/repository_manager.py b/azure_functions_devops_build/respository/repository_manager.py similarity index 71% rename from azure_devops_build_manager/respository/repository_manager.py rename to azure_functions_devops_build/respository/repository_manager.py index 7ef6ee7..3c95b53 100644 --- a/azure_devops_build_manager/respository/repository_manager.py +++ b/azure_functions_devops_build/respository/repository_manager.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from subprocess import DEVNULL, STDOUT, check_call +from subprocess import DEVNULL, STDOUT, check_call, check_output, CalledProcessError import os from msrest.service_client import ServiceClient @@ -11,7 +11,7 @@ from msrest import Configuration, Deserializer from msrest.exceptions import HttpOperationError import vsts.git.v4_1.models.git_repository_create_options as git_repository_create_options -from azure_devops_build_manager.base.base_manager import BaseManager +from ..base.base_manager import BaseManager from . import models @@ -46,6 +46,25 @@ class RepositoryManager(BaseManager): repository = self._get_repository_by_name(project, repository_name) return self._git_client.get_commits(repository.id, None, project=project.id) + def setup_remote(self, repository_name, remote_name): + """This command sets up a remote. It is normally used if a user already has a repository locally that they don't wish to get rid of""" + if self._remote_exists(remote_name): + message = """There is already an remote with this name.""" + succeeded = False + else: + origin_command = ["git", "remote", "add", remote_name, "https://" + self._organization_name + \ + ".visualstudio.com/" + self._project_name + "/_git/" + repository_name] + check_call(origin_command, stdout=DEVNULL, stderr=STDOUT) + check_call('git add -A'.split(), stdout=DEVNULL, stderr=STDOUT) + try: + check_call(["git", "commit", "-a", "-m", "\"creating functions app\""], stdout=DEVNULL, stderr=STDOUT) + except CalledProcessError: + print("no need to commit anything") + check_call(('git push ' + remote_name + ' --all').split(), stdout=DEVNULL, stderr=STDOUT) + message = "succeeded" + succeeded = True + return models.repository_response.RepositoryResponse(message, succeeded) + def setup_repository(self, repository_name): """This command sets up the repository locally - it initialises the git file and creates the initial push ect""" if self._repository_exists(): @@ -67,6 +86,13 @@ class RepositoryManager(BaseManager): """Helper to see if gitfile exists""" return bool(os.path.exists('.git')) + def _remote_exists(self, remote_name): + lines = (check_output('git remote show'.split())).decode('utf-8').split('\n') + for line in lines: + if line == remote_name: + return True + return False + def list_github_repositories(self): """List github repositories if there are any from the current connection""" project = self._get_project_by_name(self._project_name) @@ -76,34 +102,3 @@ class RepositoryManager(BaseManager): return [] else: return self._build_client.list_repositories(project.id, 'github', github_endpoint.id) - - def create_github_connection(self): - """Create a github connection endpoint that the user must go authenticate with""" - project = self._get_project_by_name(self._project_name) - - url = '/' + self._organization_name + '/' + str(project.id) + \ - '/_apis/connectedService/providers/github/authRequests' - - query_paramters = {} - query_paramters['configurationId'] = '00000000-0000-0000-0000-000000000000' - query_paramters['scope'] = 'repo,read:user,user:email,admin:repo_hook' - - #construct header parameters - header_paramters = {} - header_paramters['Accept'] = 'application/json;api-version=5.0;excludeUrls=true;' + \ - 'enumsAsNumbers=true;msDateFormat=true;noArrayWrap=true' - - request = self._client.post(url, params=query_paramters) - response = self._client.send(request, headers=header_paramters) - - # Handle Response - deserialized = None - if response.status_code not in [200]: - print("GET %s", request.url) - print("response: %s", response.status_code) - print(response.text) - raise HttpOperationError(self._deserialize, response) - else: - deserialized = self._deserialize('GithubConnection', response) - - return deserialized diff --git a/azure_devops_build_manager/service_endpoint/__init__.py b/azure_functions_devops_build/service_endpoint/__init__.py similarity index 100% rename from azure_devops_build_manager/service_endpoint/__init__.py rename to azure_functions_devops_build/service_endpoint/__init__.py diff --git a/azure_devops_build_manager/service_endpoint/service_endpoint_manager.py b/azure_functions_devops_build/service_endpoint/service_endpoint_manager.py similarity index 77% rename from azure_devops_build_manager/service_endpoint/service_endpoint_manager.py rename to azure_functions_devops_build/service_endpoint/service_endpoint_manager.py index 2b55fa7..ea3ecd9 100644 --- a/azure_devops_build_manager/service_endpoint/service_endpoint_manager.py +++ b/azure_functions_devops_build/service_endpoint/service_endpoint_manager.py @@ -6,7 +6,7 @@ import json import subprocess import vsts.service_endpoint.v4_1.models as models -from azure_devops_build_manager.base.base_manager import BaseManager +from ..base.base_manager import BaseManager class ServiceEndpointManager(BaseManager): """ Manage DevOps service endpoints within projects @@ -14,12 +14,36 @@ class ServiceEndpointManager(BaseManager): Attributes: See BaseManager """ - + def __init__(self, organization_name="", project_name="", creds=None): """Inits ServiceEndpointManager as per BaseManager""" super(ServiceEndpointManager, self).__init__(creds, organization_name=organization_name, project_name=project_name) + def create_github_service_endpoint(self, githubname, access_token): + """ Create a github access token connection """ + project = self._get_project_by_name(self._project_name) + + data = {} + + auth = models.endpoint_authorization.EndpointAuthorization( + parameters={ + "AccessToken": access_token + }, + scheme="OAuth" + ) + + service_endpoint = models.service_endpoint.ServiceEndpoint( + administrators_group=None, + authorization=auth, + data=data, + name=githubname, + type="github", + url="http://github.com" + ) + + return self._service_endpoint_client.create_service_endpoint(service_endpoint, project.id) + def create_service_endpoint(self, servicePrincipalName): """Create a new service endpoint within a project with an associated service principal""" project = self._get_project_by_name(self._project_name) diff --git a/azure_devops_build_manager/user/__init__.py b/azure_functions_devops_build/user/__init__.py similarity index 100% rename from azure_devops_build_manager/user/__init__.py rename to azure_functions_devops_build/user/__init__.py diff --git a/azure_devops_build_manager/user/models/__init__.py b/azure_functions_devops_build/user/models/__init__.py similarity index 100% rename from azure_devops_build_manager/user/models/__init__.py rename to azure_functions_devops_build/user/models/__init__.py diff --git a/azure_devops_build_manager/user/models/user.py b/azure_functions_devops_build/user/models/user.py similarity index 100% rename from azure_devops_build_manager/user/models/user.py rename to azure_functions_devops_build/user/models/user.py diff --git a/azure_devops_build_manager/user/user_manager.py b/azure_functions_devops_build/user/user_manager.py similarity index 98% rename from azure_devops_build_manager/user/user_manager.py rename to azure_functions_devops_build/user/user_manager.py index 870e755..47597a8 100644 --- a/azure_devops_build_manager/user/user_manager.py +++ b/azure_functions_devops_build/user/user_manager.py @@ -3,7 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from __future__ import print_function import logging from msrest.service_client import ServiceClient from msrest import Configuration, Deserializer diff --git a/azure_devops_build_manager/yaml/__init__.py b/azure_functions_devops_build/yaml/__init__.py similarity index 100% rename from azure_devops_build_manager/yaml/__init__.py rename to azure_functions_devops_build/yaml/__init__.py diff --git a/azure_devops_build_manager/yaml/templates/build.jinja b/azure_functions_devops_build/yaml/templates/build.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/build.jinja rename to azure_functions_devops_build/yaml/templates/build.jinja diff --git a/azure_devops_build_manager/yaml/templates/depricated/linux_consumption_release_included.jinja b/azure_functions_devops_build/yaml/templates/depricated/linux_consumption_release_included.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/depricated/linux_consumption_release_included.jinja rename to azure_functions_devops_build/yaml/templates/depricated/linux_consumption_release_included.jinja diff --git a/azure_devops_build_manager/yaml/templates/depricated/linux_dedicated_release_included.jinja b/azure_functions_devops_build/yaml/templates/depricated/linux_dedicated_release_included.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/depricated/linux_dedicated_release_included.jinja rename to azure_functions_devops_build/yaml/templates/depricated/linux_dedicated_release_included.jinja diff --git a/azure_devops_build_manager/yaml/templates/depricated/windows_release_included.jinja b/azure_functions_devops_build/yaml/templates/depricated/windows_release_included.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/depricated/windows_release_included.jinja rename to azure_functions_devops_build/yaml/templates/depricated/windows_release_included.jinja diff --git a/azure_devops_build_manager/yaml/templates/linux_consumption.jinja b/azure_functions_devops_build/yaml/templates/linux_consumption.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/linux_consumption.jinja rename to azure_functions_devops_build/yaml/templates/linux_consumption.jinja diff --git a/azure_devops_build_manager/yaml/templates/linux_dedicated.jinja b/azure_functions_devops_build/yaml/templates/linux_dedicated.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/linux_dedicated.jinja rename to azure_functions_devops_build/yaml/templates/linux_dedicated.jinja diff --git a/azure_devops_build_manager/yaml/templates/windows.jinja b/azure_functions_devops_build/yaml/templates/windows.jinja similarity index 100% rename from azure_devops_build_manager/yaml/templates/windows.jinja rename to azure_functions_devops_build/yaml/templates/windows.jinja diff --git a/azure_devops_build_manager/yaml/yaml_manager.py b/azure_functions_devops_build/yaml/yaml_manager.py similarity index 94% rename from azure_devops_build_manager/yaml/yaml_manager.py rename to azure_functions_devops_build/yaml/yaml_manager.py index 1af7dc3..b3c8553 100644 --- a/azure_devops_build_manager/yaml/yaml_manager.py +++ b/azure_functions_devops_build/yaml/yaml_manager.py @@ -5,9 +5,8 @@ import os.path as path import logging -import json from jinja2 import Environment, PackageLoader, select_autoescape -from azure_devops_build_manager.constants import (LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS, PYTHON, NODE, DOTNET, JAVA) +from ..constants import (WINDOWS, PYTHON, NODE, DOTNET, JAVA) class YamlManager(object): """ Generate yaml files for devops @@ -53,11 +52,12 @@ class YamlManager(object): def _generate_yaml(self, dependencies, vmImage, language_str, platform_str): env = Environment( - loader=PackageLoader('azure_devops_build_manager.yaml', 'templates'), + loader=PackageLoader('azure_functions_devops_build.yaml', 'templates'), autoescape=select_autoescape(['html', 'xml', 'jinja']) ) template = env.get_template('build.jinja') - outputText = template.render(dependencies=dependencies, vmImage=vmImage, language=language_str, platform=platform_str) + outputText = template.render(dependencies=dependencies, vmImage=vmImage, + language=language_str, platform=platform_str) return outputText def _requires_extensions(self): diff --git a/sample_yaml_builds/linux/consumption/python-consumption.yml b/sample_yaml_builds/linux/consumption/python-consumption.yml new file mode 100644 index 0000000..d2680de --- /dev/null +++ b/sample_yaml_builds/linux/consumption/python-consumption.yml @@ -0,0 +1,70 @@ +# Configure the details of the functionapp +variables: + azureSubscription: '{ARM ACCESS TOKEN NAME}' + storageName: '{STORAGE NAME OF FUNCTIONAPP}' + functionappName: '{NAME OF FUNCTIONAPP}' + resourceGroupName: '{RESOURCE GROUP NAME OF FUNCTIONAPP}' + +jobs: + # Build the python packages in a virtual env + - job: Build + pool: + vmImage: ubuntu-16.04 + steps: + - task: UsePythonVersion@0 + displayName: "Setting python version to 3.6 as required by functions" + inputs: + versionSpec: '3.6' + architecture: 'x64' + - script: | + dotnet restore # COMMENT OUT IF NOT USING FUNCTION EXTENSIONS + dotnet build --runtime ubuntu.16.04-x64 --output './bin/' # COMMENT OUT IF NOT USING FUNCTION EXTENSIONS + python3.6 -m venv worker_venv + source worker_venv/bin/activate + pip3.6 install setuptools + pip3.6 install -r requirements.txt + - task: ArchiveFiles@2 + displayName: "Archive files" + inputs: + rootFolderOrFile: "$(System.DefaultWorkingDirectory)" + includeRootFolder: false + archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip" + - task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip' + name: 'drop' + # Download the build artifacts from + - job: Deploy + pool: + vmImage: 'VS2017-Win2016' + steps: + - task: DownloadBuildArtifacts@0 + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'drop' + downloadPath: '$(System.DefaultWorkingDirectory)' + - task: AzureFileCopy@2 + inputs: + sourcePath: "drop/build$(Build.BuildId).zip" + azureConnectionType: 'ConnectedServiceNameARM' + azureSubscription: "$(azureSubscription)" + destination: azureBlob + storage: "$(storageName)" + containerName: 'azure-build' + - task: createsastoken@1 + inputs: + ConnectedServiceName: "$(azureSubscription)" + StorageAccountRM: "$(storageName)" + SasTokenTimeOutInHours: 10000 + Permission: 'r' + StorageContainerName: 'azure-build' + - task: AzureAppServiceSetAppSettings@2 + inputs: + ConnectedServiceName: "$(azureSubscription)" + WebAppName: "$(functionappName)" + ResourceGroupName: "$(resourceGroupName)" + AppSettings: "WEBSITE_RUN_FROM_PACKAGE='$(storageUri)/build$(Build.BuildId).zip$(storageToken)'" + + dependsOn: Build + condition: succeeded() diff --git a/sample_yaml_builds/linux/dedicated/python-dedicated.yml b/sample_yaml_builds/linux/dedicated/python-dedicated.yml new file mode 100644 index 0000000..185d66f --- /dev/null +++ b/sample_yaml_builds/linux/dedicated/python-dedicated.yml @@ -0,0 +1,35 @@ +variables: + azureSubscription: '{ARM ACCESS TOKEN NAME}' + functionappName: '{NAME OF FUNCTIONAPP}' + +pool: + vmImage: ubuntu-16.04 +steps: +- task: UsePythonVersion@0 + displayName: "Setting python version to 3.6 as required by functions" + inputs: + versionSpec: '3.6' + architecture: 'x64' +- script: | + dotnet restore # COMMENT OUT IF NOT USING FUNCTION EXTENSIONS + dotnet build --runtime ubuntu.16.04-x64 --output './bin/' # COMMENT OUT IF NOT USING FUNCTION EXTENSIONS + python3.6 -m venv worker_venv + source worker_venv/bin/activate + pip3.6 install setuptools + pip3.6 install -r requirements.txt +- task: ArchiveFiles@2 + displayName: "Archive files" + inputs: + rootFolderOrFile: "$(System.DefaultWorkingDirectory)" + includeRootFolder: false + archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip" +- task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip' + name: 'drop' +- task: AzureRmWebAppDeployment@4 + inputs: + connectionType: 'AzureRM' + azureSubscription: "$(azureSubscription)" + appType: 'functionAppLinux' + webAppName: "$(functionappName)" diff --git a/sample_yaml_builds/windows/dotnet-windows.yml b/sample_yaml_builds/windows/dotnet-windows.yml new file mode 100644 index 0000000..153dc04 --- /dev/null +++ b/sample_yaml_builds/windows/dotnet-windows.yml @@ -0,0 +1,28 @@ +# Starter template for Azure functions build for {{language}} {{appType}} +variables: + azureSubscription: '{ARM ACCESS TOKEN NAME}' + functionappName: '{NAME OF FUNCTIONAPP}' + +pool: + vmImage: 'VS2017-Win2016' + +steps: +- script: | + dotnet restore + dotnet build --output \'./bin/\' +- task: ArchiveFiles@2 + displayName: "Archive files" + inputs: + rootFolderOrFile: "$(System.DefaultWorkingDirectory)" + includeRootFolder: false + archiveFile: "$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip" +- task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip' + name: 'drop' +- task: AzureRmWebAppDeployment@4 + inputs: + connectionType: 'AzureRM' + azureSubscription: "$(azureSubscription)" + appType: 'functionApp' + webAppName: "$(functionappName)" diff --git a/sample_yaml_builds/windows/node-windows.yml b/sample_yaml_builds/windows/node-windows.yml new file mode 100644 index 0000000..199c896 --- /dev/null +++ b/sample_yaml_builds/windows/node-windows.yml @@ -0,0 +1,30 @@ +# Starter template for Azure functions build for {{language}} {{appType}} +variables: + azureSubscription: '{ARM ACCESS TOKEN NAME}' + functionappName: '{NAME OF FUNCTIONAPP}' + +pool: + vmImage: 'VS2017-Win2016' + +steps: +- script: | + dotnet restore # comment out if not using extensions + dotnet build --output \'./bin/\' # comment out if not using extensions + npm install + npm run build +- task: ArchiveFiles@2 + displayName: "Archive files" + inputs: + rootFolderOrFile: "$(System.DefaultWorkingDirectory)" + includeRootFolder: false + archiveFile: "$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip" +- task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip' + name: 'drop' +- task: AzureRmWebAppDeployment@4 + inputs: + connectionType: 'AzureRM' + azureSubscription: "$(azureSubscription)" + appType: 'functionApp' + webAppName: "$(functionappName)" diff --git a/setup.py b/setup.py index a8d177c..01a1e22 100644 --- a/setup.py +++ b/setup.py @@ -6,8 +6,8 @@ from setuptools import setup, find_packages -NAME = "azure-devops-build-manager" -VERSION = "0.1.0" +NAME = "azure-functions-devops-build" +VERSION = "0.0.1" # To install the library, run the following # @@ -16,12 +16,14 @@ VERSION = "0.1.0" # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools -REQUIRES = ["msrest>=0.2.0", 'mock'] +REQUIRES = ["msrest>=0.2.0", + "vsts>=0.1.25", + "jinja2>=2.10"] setup( name=NAME, version=VERSION, - description="Python package for integrating azure functions with azure devops", + description="Python package for integrating azure functions with azure devops. Specifically made for the Azure Cli", author_email="t-oldolk@microsoft.com", url="https://github.com/dolko/azure-devops-build-manager", keywords=["Microsoft", "Azure Devops", "Azure Functions"], diff --git a/tests/_config.py b/tests/_config.py index cc5e347..c135b43 100644 --- a/tests/_config.py +++ b/tests/_config.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devops_build_manager.constants import LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS, NODE, PYTHON, JAVA, DOTNET +from azure_functions_devops_build.constants import LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS, NODE, PYTHON, JAVA, DOTNET # You need to fill in the variables with names of the resources you already have # When you are finished setting the configs then you can run test.cmd @@ -11,8 +11,8 @@ from azure_devops_build_manager.constants import LINUX_CONSUMPTION, LINUX_DEDICA CREATE_DEVOPS_OBJECTS = False # Specify the name of your already created devops objects -ORGANIZATION_NAME = 'dolk-automated-11' -PROJECT_NAME = 'auto-python' +ORGANIZATION_NAME = 'ollys-hck' +PROJECT_NAME = 'cmd-test-2' SERVICE_ENDPOINT_NAME = ORGANIZATION_NAME + PROJECT_NAME REPOSITORY_NAME = PROJECT_NAME BUILD_DEFINITION_NAME = PROJECT_NAME diff --git a/tests/_config_example.py b/tests/_config_example.py index 09cb128..ced3a46 100644 --- a/tests/_config_example.py +++ b/tests/_config_example.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure_devops_build_manager.constants import LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS, NODE, PYTHON, JAVA, DOTNET +from azure_functions_devops_build.constants import LINUX_CONSUMPTION, LINUX_DEDICATED, WINDOWS, NODE, PYTHON, JAVA, DOTNET """This file contains the configs needed for the tests""" diff --git a/tests/test_artifact_manager.py b/tests/test_artifact_manager.py index 8ffed3f..729d201 100644 --- a/tests/test_artifact_manager.py +++ b/tests/test_artifact_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.artifact.artifact_manager import ArtifactManager +from azure_functions_devops_build.artifact.artifact_manager import ArtifactManager from ._config import ORGANIZATION_NAME, PROJECT_NAME from ._helpers import get_credentials diff --git a/tests/test_builder_manager.py b/tests/test_builder_manager.py index 8824775..8d94310 100644 --- a/tests/test_builder_manager.py +++ b/tests/test_builder_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.builder.builder_manager import BuilderManager +from azure_functions_devops_build.builder.builder_manager import BuilderManager from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME, REPOSITORY_NAME, BUILD_DEFINITION_NAME, POOL_NAME from ._helpers import get_credentials diff --git a/tests/test_extension_manager.py b/tests/test_extension_manager.py index c7e421d..46bbaa1 100644 --- a/tests/test_extension_manager.py +++ b/tests/test_extension_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.extension.extension_manager import ExtensionManager +from azure_functions_devops_build.extension.extension_manager import ExtensionManager from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME from ._helpers import get_credentials diff --git a/tests/test_organization_manager.py b/tests/test_organization_manager.py index 662e46f..5f0d8ed 100644 --- a/tests/test_organization_manager.py +++ b/tests/test_organization_manager.py @@ -4,8 +4,8 @@ # -------------------------------------------------------------------------------------------- import unittest, string, random -from azure_devops_build_manager.organization.organization_manager import OrganizationManager -from azure_devops_build_manager.user.user_manager import UserManager +from azure_functions_devops_build.organization.organization_manager import OrganizationManager +from azure_functions_devops_build.user.user_manager import UserManager from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME from ._helpers import get_credentials diff --git a/tests/test_pool_manager.py b/tests/test_pool_manager.py index 30408ef..5e92699 100644 --- a/tests/test_pool_manager.py +++ b/tests/test_pool_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.pool.pool_manager import PoolManager +from azure_functions_devops_build.pool.pool_manager import PoolManager from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME from ._helpers import get_credentials diff --git a/tests/test_project_manager.py b/tests/test_project_manager.py index c61098b..b65ed26 100644 --- a/tests/test_project_manager.py +++ b/tests/test_project_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.project.project_manager import ProjectManager +from azure_functions_devops_build.project.project_manager import ProjectManager from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME from ._helpers import get_credentials diff --git a/tests/test_release_manager.py b/tests/test_release_manager.py index 6063c9d..97f6f16 100644 --- a/tests/test_release_manager.py +++ b/tests/test_release_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.release.release_manager import ReleaseManager +from azure_functions_devops_build.release.release_manager import ReleaseManager from ._config import CREATE_DEVOPS_OBJECTS, ORGANIZATION_NAME, PROJECT_NAME, REPOSITORY_NAME, SERVICE_ENDPOINT_NAME, BUILD_DEFINITION_NAME, RELEASE_DEFINITION_NAME, POOL_NAME, FUNCTIONAPP_TYPE, FUNCTIONAPP_NAME, STORAGE_NAME, RESOURCE_GROUP_NAME from ._helpers import get_credentials diff --git a/tests/test_repository_manager.py b/tests/test_repository_manager.py index 79dae17..6536bda 100644 --- a/tests/test_repository_manager.py +++ b/tests/test_repository_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.respository.repository_manager import RepositoryManager +from azure_functions_devops_build.respository.repository_manager import RepositoryManager from ._config import ORGANIZATION_NAME, PROJECT_NAME, REPOSITORY_NAME, CREATE_DEVOPS_OBJECTS from ._helpers import get_credentials diff --git a/tests/test_service_endpoint_manager.py b/tests/test_service_endpoint_manager.py index da7f162..d5f1e51 100644 --- a/tests/test_service_endpoint_manager.py +++ b/tests/test_service_endpoint_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.service_endpoint.service_endpoint_manager import ServiceEndpointManager +from azure_functions_devops_build.service_endpoint.service_endpoint_manager import ServiceEndpointManager from ._config import ORGANIZATION_NAME, PROJECT_NAME, SERVICE_ENDPOINT_NAME, CREATE_DEVOPS_OBJECTS from ._helpers import get_credentials @@ -24,7 +24,7 @@ class TestServiceEndpointManager(unittest.TestCase): creds = get_credentials() service_endpoint_manager = ServiceEndpointManager(organization_name=ORGANIZATION_NAME, project_name=PROJECT_NAME, creds=creds) endpoint = service_endpoint_manager.create_service_endpoint(SERVICE_ENDPOINT_NAME) - - + + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/tests/test_yaml_manager.py b/tests/test_yaml_manager.py index a9ca8a4..f6eecb7 100644 --- a/tests/test_yaml_manager.py +++ b/tests/test_yaml_manager.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- import unittest -from azure_devops_build_manager.yaml.yaml_manager import YamlManager +from azure_functions_devops_build.yaml.yaml_manager import YamlManager from ._config import FUNCTIONAPP_LANGUAGE, FUNCTIONAPP_TYPE class TestYamlManager(unittest.TestCase):