def __init__( self, scope: Construct, id: str, context: "Context", ) -> None: self.scope = scope self.id = id self.context = context super().__init__( scope=scope, id=id, stack_name=id, env=Environment(account=self.context.account_id, region=self.context.region), ) Tags.of(scope=cast(IConstruct, self)).add( key="Env", value=f"orbit-{self.context.name}") if self.context.networking.vpc_id is None: raise ValueError("self.context.networking.vpc_id is None.") if self.context.networking.availability_zones is None: raise ValueError( "self.context.networking.availability_zones is None.") self.i_vpc = ec2.Vpc.from_vpc_attributes( scope=self, id="vpc", vpc_id=self.context.networking.vpc_id, availability_zones=self.context.networking.availability_zones, ) self.role_eks_cluster = self._create_role_cluster() self.role_eks_env_nodegroup = self._create_env_nodegroup_role() self.role_fargate_profile = self._create_role_fargate_profile() self.role_cluster_autoscaler = self._create_cluster_autoscaler_role() if self.context.user_pool_id: self.context.cognito_users_url = orbit_cognito.get_users_url( user_pool_id=self.context.user_pool_id, region=self.context.region) cognito_pool_arn: str = orbit_cognito.get_pool_arn( user_pool_id=self.context.user_pool_id, region=self.context.region, account=self.context.account_id) self.user_pool: cognito.UserPool = self._get_user_pool( user_pool_arn=cognito_pool_arn) else: raise Exception("Missing Cognito User Pool ID ('user_pool_id') ") self.user_pool_client = self._create_user_pool_client() self.identity_pool = self._create_identity_pool() self.token_validation_lambda = self._create_token_validation_lambda() self.eks_service_lambda = self._create_eks_service_lambda() self.cluster_pod_security_group = self._create_cluster_pod_security_group( ) self.context_parameter = self._create_manifest_parameter() self._create_post_authentication_lambda()
def deploy_teams( filename: str, debug: bool, ) -> None: with MessagesContext("Deploying", debug=debug) as msg_ctx: msg_ctx.progress(2) manifest: "Manifest" = ManifestSerDe.load_manifest_from_file(filename=filename, type=Manifest) msg_ctx.info(f"Manifest loaded: {filename}") msg_ctx.info(f"Teams: {','.join([t.name for t in manifest.teams])}") msg_ctx.progress(5) manifest_dir: str = os.path.dirname(os.path.abspath(filename)) _logger.debug("manifest directory is set to %s", manifest_dir) context_parameter_name: str = f"/orbit/{manifest.name}/context" if not ssm.does_parameter_exist(name=context_parameter_name): msg_ctx.error(f"Orbit Environment {manifest.name} cannot be found in the current account and region.") return context: "Context" = ContextSerDe.load_context_from_manifest(manifest=manifest) msg_ctx.info("Current Context loaded") msg_ctx.info(f"Teams: {','.join([t.name for t in context.teams])}") msg_ctx.progress(10) _logger.debug("Inspecting possible manifest changes...") changeset: "Changeset" = extract_changeset(manifest=manifest, context=context, msg_ctx=msg_ctx) _logger.debug(f"Changeset:\n{dump_changeset_to_str(changeset=changeset)}") msg_ctx.progress(30) deploy.deploy_teams( env_name=context.name, manifest_dir=manifest_dir, ) msg_ctx.info("Orbit Workbench deployed") msg_ctx.progress(98) if cfn.does_stack_exist(stack_name=context.env_stack_name): context = ContextSerDe.load_context_from_ssm(env_name=manifest.name, type=Context) msg_ctx.info(f"Context updated: {filename}") msg_ctx.progress(99) if context.user_pool_id: cognito_users_url = orbit_cognito.get_users_url(user_pool_id=context.user_pool_id, region=context.region) msg_ctx.tip(f"Add users: {stylize(cognito_users_url, underline=True)}") if context.landing_page_url: msg_ctx.tip(f"Access Orbit Workbench: {stylize(f'{context.landing_page_url}/orbit/login', underline=True)}") else: raise RuntimeError("Landing Page URL not found.") msg_ctx.progress(100)