Skip to content

Commit

Permalink
Fix/optimising run deploy in spoke (#630)
Browse files Browse the repository at this point in the history
* fix: moving logic from run-deploy-in-spoke (run per spoke) to generate-manifest-with-ids (run once per execution)
* fix: making black
  • Loading branch information
eamonnfaherty authored Feb 6, 2023
1 parent 01574af commit 69c63bc
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 107 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "aws-service-catalog-puppet"
version = "0.215.0"
version = "0.216.0"
description = "Making it easier to deploy ServiceCatalog products"
classifiers = ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Natural Language :: English"]
homepage = "https://service-catalog-tools-workshop.com/"
Expand Down
111 changes: 6 additions & 105 deletions servicecatalog_puppet/workflow/launch/run_deploy_in_spoke_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,116 +25,17 @@ def run(self):
generated_manifest = self.get_output_from_reference_dependency(
self.generate_manifest_ref
)
reference_signed_url = generated_manifest.get("reference_signed_url")
manifest_signed_url = generated_manifest.get("manifest_signed_url")
cached_output_signed_url = generated_manifest.get("cached_output_signed_url")

version = constants.VERSION
home_region = constants.HOME_REGION

vars = [
{
"name": environmental_variables.CACHE_INVALIDATOR,
"value": self.cache_invalidator,
"type": "PLAINTEXT",
},
{"name": "VERSION", "value": version, "type": "PLAINTEXT"},
{"name": "MANIFEST_URL", "value": manifest_signed_url, "type": "PLAINTEXT"},
{
"name": "TASK_REFERENCE_URL",
"value": reference_signed_url,
"type": "PLAINTEXT",
},
{
"name": "PUPPET_ACCOUNT_ID",
"value": self.puppet_account_id,
"type": "PLAINTEXT",
},
{"name": "HOME_REGION", "value": home_region, "type": "PLAINTEXT",},
{
"name": "REGIONS",
"value": ",".join(config.get_regions()),
"type": "PLAINTEXT",
},
{
"name": "SHOULD_COLLECT_CLOUDFORMATION_EVENTS",
"value": str(config.get_should_use_sns()),
"type": "PLAINTEXT",
},
{
"name": "SHOULD_FORWARD_EVENTS_TO_EVENTBRIDGE",
"value": str(config.get_should_use_eventbridge()),
"type": "PLAINTEXT",
},
{
"name": "SHOULD_FORWARD_FAILURES_TO_OPSCENTER",
"value": str(config.get_should_forward_failures_to_opscenter()),
"type": "PLAINTEXT",
},
{
"name": "OUTPUT_CACHE_STARTING_POINT",
"value": cached_output_signed_url,
"type": "PLAINTEXT",
},
{
"name": environmental_variables.IS_CACHING_ENABLED,
"value": "False", # no caching in spokes
"type": "PLAINTEXT",
},
{
"name": environmental_variables.INITIALISER_STACK_TAGS,
"value": config.get_initialiser_stack_tags(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.GLOBAL_SHARING_MODE,
"value": config.get_global_sharing_mode_default(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SHOULD_DELETE_ROLLBACK_COMPLETE_STACKS,
"value": config.get_should_delete_rollback_complete_stacks(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SHOULD_USE_PRODUCT_PLANS,
"value": config.get_should_use_product_plans(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SPOKE_EXECUTION_MODE_DEPLOY_ENV,
"value": config.get_spoke_execution_mode_deploy_env(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SCHEDULER_THREADS_OR_PROCESSES,
"value": config.get_scheduler_threads_or_processes(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.GLOBAL_SHARE_TAG_OPTIONS,
"value": config.get_global_share_tag_options_default(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.GLOBAL_SHARE_PRINCIPALS,
"value": config.get_global_share_principals_default(),
"type": "PLAINTEXT",
},
]

if "http" in version:
install_command = f"pip install {version}"
else:
install_command = f"pip install aws-service-catalog-puppet=={version}"

build_spec = constants.RUN_DEPLOY_IN_SPOKE_BUILDSPEC.format(install_command)
build_spec = generated_manifest.get("build_spec")
spoke_execution_mode_deploy_env = generated_manifest.get(
"spoke_execution_mode_deploy_env"
)
vars = generated_manifest.get("vars")

with self.spoke_client("codebuild") as codebuild:
response = codebuild.start_build(
projectName=constants.EXECUTION_SPOKE_CODEBUILD_PROJECT_NAME,
environmentVariablesOverride=vars,
computeTypeOverride=self.spoke_execution_mode_deploy_env,
computeTypeOverride=spoke_execution_mode_deploy_env,
buildspecOverride=build_spec,
)
self.write_output(dict(account_id=self.account_id, **response))
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import zipfile

from servicecatalog_puppet.workflow.dependencies import tasks
from servicecatalog_puppet import constants, environmental_variables, config


class GenerateManifestWithIdsTask(tasks.TaskWithReference):
Expand Down Expand Up @@ -48,13 +49,117 @@ def run(self):
bucket, s3
)

version = constants.VERSION
home_region = constants.HOME_REGION

vars = [
{
"name": environmental_variables.CACHE_INVALIDATOR,
"value": self.cache_invalidator,
"type": "PLAINTEXT",
},
{"name": "VERSION", "value": version, "type": "PLAINTEXT"},
{"name": "MANIFEST_URL", "value": manifest_signed_url, "type": "PLAINTEXT"},
{
"name": "TASK_REFERENCE_URL",
"value": reference_signed_url,
"type": "PLAINTEXT",
},
{
"name": "PUPPET_ACCOUNT_ID",
"value": self.puppet_account_id,
"type": "PLAINTEXT",
},
{"name": "HOME_REGION", "value": home_region, "type": "PLAINTEXT",},
{
"name": "REGIONS",
"value": ",".join(config.get_regions()),
"type": "PLAINTEXT",
},
{
"name": "SHOULD_COLLECT_CLOUDFORMATION_EVENTS",
"value": str(config.get_should_use_sns()),
"type": "PLAINTEXT",
},
{
"name": "SHOULD_FORWARD_EVENTS_TO_EVENTBRIDGE",
"value": str(config.get_should_use_eventbridge()),
"type": "PLAINTEXT",
},
{
"name": "SHOULD_FORWARD_FAILURES_TO_OPSCENTER",
"value": str(config.get_should_forward_failures_to_opscenter()),
"type": "PLAINTEXT",
},
{
"name": "OUTPUT_CACHE_STARTING_POINT",
"value": cached_output_signed_url,
"type": "PLAINTEXT",
},
{
"name": environmental_variables.IS_CACHING_ENABLED,
"value": "False", # no caching in spokes
"type": "PLAINTEXT",
},
{
"name": environmental_variables.INITIALISER_STACK_TAGS,
"value": config.get_initialiser_stack_tags(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.GLOBAL_SHARING_MODE,
"value": config.get_global_sharing_mode_default(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SHOULD_DELETE_ROLLBACK_COMPLETE_STACKS,
"value": config.get_should_delete_rollback_complete_stacks(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SHOULD_USE_PRODUCT_PLANS,
"value": config.get_should_use_product_plans(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SPOKE_EXECUTION_MODE_DEPLOY_ENV,
"value": config.get_spoke_execution_mode_deploy_env(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.SCHEDULER_THREADS_OR_PROCESSES,
"value": config.get_scheduler_threads_or_processes(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.GLOBAL_SHARE_TAG_OPTIONS,
"value": config.get_global_share_tag_options_default(),
"type": "PLAINTEXT",
},
{
"name": environmental_variables.GLOBAL_SHARE_PRINCIPALS,
"value": config.get_global_share_principals_default(),
"type": "PLAINTEXT",
},
]

if "http" in version:
install_command = f"pip install {version}"
else:
install_command = f"pip install aws-service-catalog-puppet=={version}"

build_spec = constants.RUN_DEPLOY_IN_SPOKE_BUILDSPEC.format(install_command)

self.write_output(
dict(
reference_task_reference_content=reference_task_reference_content,
reference_signed_url=reference_signed_url,
cached_output_signed_url=cached_output_signed_url,
manifest_signed_url=manifest_signed_url,
manifest_content=manifest_content,
build_spec=build_spec,
spoke_execution_mode_deploy_env=self.spoke_execution_mode_deploy_env,
vars=vars,
)
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.215.0',
'version': '0.216.0',
'description': 'Making it easier to deploy ServiceCatalog products',
'long_description': '# aws-service-catalog-puppet\n\n![logo](./docs/logo.png) \n\n## Badges\n\n[![codecov](https://codecov.io/gh/awslabs/aws-service-catalog-puppet/branch/master/graph/badge.svg?token=e8M7mdsmy0)](https://codecov.io/gh/awslabs/aws-service-catalog-puppet)\n\n\n## What is it?\nThis is a python3 framework that makes it easier to share multi region AWS Service Catalog portfolios and makes it \npossible to provision products into accounts declaratively using a metadata based rules engine.\n\nWith this framework you define your accounts in a YAML file. You give each account a set of tags, a default region and \na set of enabled regions.\n\nOnce you have done this you can define portfolios should be shared with each set of accounts using the tags and you \ncan specify which regions the shares occur in.\n\nIn addition to this, you can also define products that should be provisioned into accounts using the same tag based \napproach. The framework will assume role into the target account and provision the product on your behalf.\n\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/30-service-catalog-puppet.html)\nor you can read through the [every day use](https://service-catalog-tools-workshop.com/30-how-tos/50-every-day-use.html)\nguides.\n\nYou can read the [documentation](https://aws-service-catalog-puppet.readthedocs.io/en/latest/) to understand the inner \nworkings. \n\n\n## Going further\n\nThe framework is one of a pair. The other is [aws-service-catalog-factory](https://github.com/awslabs/aws-service-catalog-factory).\nWith Service Catalog Factory you can create pipelines that deploy multi region portfolios very easily. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n \n',
'author': 'Eamonn Faherty',
Expand Down

0 comments on commit 69c63bc

Please sign in to comment.