def auth(self): variables = load_environment_variables([ 'AZURE_APP_ID', 'AZURE_PASSWORD', 'AZURE_TENANT', 'AZURE_CONTAINER_REGISTRY_NAME' ]) self._azure_login(variables['AZURE_APP_ID'], variables['AZURE_PASSWORD'], variables['AZURE_TENANT']) self._azure_acr_login(variables['AZURE_CONTAINER_REGISTRY_NAME'])
def cluster(self): variables = load_environment_variables( ['AZURE_RESOURCE_GROUP', 'CLUSTER']) print('Pointing to azure \'' + variables['CLUSTER'] + '\' cluster... ', end='', flush=True) call([ 'az', 'aks', 'get-credentials', '--resource-group', variables['AZURE_RESOURCE_GROUP'], '--name', variables['CLUSTER'], '--overwrite-existing' ], stdout=PIPE) print('done')
def container_built_and_pushed(self, container: str) -> bool: variables = load_environment_variables( ['AZURE_CONTAINER_REGISTRY_NAME']) acr_name = variables['AZURE_CONTAINER_REGISTRY_NAME'] image_name = generate_image_name(container, self.short_image_name_template) with open(container + '/tag') as tag: image_name += ':' + tag.read() return call([ 'az', 'acr', 'repository', 'show', '--name', acr_name, '--image', image_name ], stdout=PIPE, stderr=PIPE) == 0
def get_deployment_image_name(self, container: str) -> str: variables = load_environment_variables( ['AZURE_CONTAINER_REGISTRY_NAME']) acr_name = variables['AZURE_CONTAINER_REGISTRY_NAME'] short_image_name = generate_image_name(container, self.short_image_name_template) if not self.production: short_image_name += ':latest' else: with open(container + '/tag') as tag: short_image_name += ':' + tag.read() digest = check_output([ 'az', 'acr', 'repository', 'show', '--name', acr_name, '--image', short_image_name, '--query', 'digest', '--output', 'tsv' ]).decode('UTF-8').replace('\n', '') return self.get_build_image_name(container) + '@' + digest
def image_pull_secret(self): variables = load_environment_variables([ 'IMAGE_PULL_SECRET_NAME', 'IMAGE_PULL_SECRET_SERVER', 'IMAGE_PULL_SECRET_USERNAME', 'IMAGE_PULL_SECRET_PASSWORD', 'IMAGE_PULL_SECRET_EMAIL' ]) name = variables['IMAGE_PULL_SECRET_NAME'] server = variables['IMAGE_PULL_SECRET_SERVER'] username = variables['IMAGE_PULL_SECRET_USERNAME'] password = variables['IMAGE_PULL_SECRET_PASSWORD'] email = variables['IMAGE_PULL_SECRET_EMAIL'] data = check_output([ 'kubectl', 'create', 'secret', 'docker-registry', name, '--docker-server', server, '--docker-username', username, '--docker-password', password, '--docker-email', email, '--dry-run', '-o', 'yaml' ]).decode('UTF-8') run(['kubectl', 'apply', '-f', '-'], input=data, encoding='UTF-8', stdout=PIPE)