Fix nested Library cache
							parent
							
								
									8bb695773c
								
							
						
					
					
						commit
						22322303c8
					
				|  | @ -611,9 +611,10 @@ class Caching { | ||||||
|                     if (__1.Input.cloudRunnerTests) { |                     if (__1.Input.cloudRunnerTests) { | ||||||
|                         yield cloud_runner_system_1.CloudRunnerSystem.Run(`tree ${destinationFolder}`); |                         yield cloud_runner_system_1.CloudRunnerSystem.Run(`tree ${destinationFolder}`); | ||||||
|                     } |                     } | ||||||
|                     remote_client_logger_1.RemoteClientLogger.log(`cache item exists`); |                     remote_client_logger_1.RemoteClientLogger.log(`cache item exists ${cacheSelection}.zip`); | ||||||
|                     console_1.assert(`${fs_1.default.existsSync(destinationFolder)}`); |                     console_1.assert(`${fs_1.default.existsSync(destinationFolder)}`); | ||||||
|                     yield extract_zip_1.default(`${cacheSelection}.zip`, { dir: `${destinationFolder}` }); |                     yield extract_zip_1.default(`${cacheSelection}.zip`, { dir: path_1.default.basename(destinationFolder) }); | ||||||
|  |                     yield cloud_runner_system_1.CloudRunnerSystem.Run(`mv "${path_1.default.basename(destinationFolder)}/*" "${destinationFolder}/"`); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|                     remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`); |                     remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`); | ||||||
|  |  | ||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -96,9 +96,10 @@ export class Caching { | ||||||
|         if (Input.cloudRunnerTests) { |         if (Input.cloudRunnerTests) { | ||||||
|           await CloudRunnerSystem.Run(`tree ${destinationFolder}`); |           await CloudRunnerSystem.Run(`tree ${destinationFolder}`); | ||||||
|         } |         } | ||||||
|         RemoteClientLogger.log(`cache item exists`); |         RemoteClientLogger.log(`cache item exists ${cacheSelection}.zip`); | ||||||
|         assert(`${fs.existsSync(destinationFolder)}`); |         assert(`${fs.existsSync(destinationFolder)}`); | ||||||
|         await extract(`${cacheSelection}.zip`, { dir: `${destinationFolder}` }); |         await extract(`${cacheSelection}.zip`, { dir: path.basename(destinationFolder) }); | ||||||
|  |         await CloudRunnerSystem.Run(`mv "${path.basename(destinationFolder)}/*" "${destinationFolder}/"`); | ||||||
|       } else { |       } else { | ||||||
|         RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`); |         RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`); | ||||||
|         if (cacheSelection !== ``) { |         if (cacheSelection !== ``) { | ||||||
|  |  | ||||||
|  | @ -1,142 +0,0 @@ | ||||||
| AWSTemplateFormatVersion: '2010-09-09' |  | ||||||
| Description: Schedule automatic deletion of CloudFormation stacks |  | ||||||
| Metadata: |  | ||||||
|   AWS::CloudFormation::Interface: |  | ||||||
|     ParameterGroups: |  | ||||||
|       - Label: |  | ||||||
|           default: Input configuration |  | ||||||
|         Parameters: |  | ||||||
|           - StackName |  | ||||||
|           - TTL |  | ||||||
|     ParameterLabels: |  | ||||||
|       StackName: |  | ||||||
|         default: Stack name |  | ||||||
|       TTL: |  | ||||||
|         default: Time-to-live |  | ||||||
| Parameters: |  | ||||||
|   EnvironmentName: |  | ||||||
|     Type: String |  | ||||||
|     Default: development |  | ||||||
|     Description: 'Your deployment environment: DEV, QA , PROD' |  | ||||||
|   BUILDGUID: |  | ||||||
|     Type: String |  | ||||||
|     Default: '' |  | ||||||
|   StackName: |  | ||||||
|     Type: String |  | ||||||
|     Description: Stack name that will be deleted. |  | ||||||
|   DeleteStackName: |  | ||||||
|     Type: String |  | ||||||
|     Description: Stack name that will be deleted. |  | ||||||
|   TTL: |  | ||||||
|     Type: Number |  | ||||||
|     Description: Time-to-live in minutes for the stack. |  | ||||||
| Resources: |  | ||||||
|   DeleteCFNLambda: |  | ||||||
|     Type: 'AWS::Lambda::Function' |  | ||||||
|     Properties: |  | ||||||
|       FunctionName: !Join ['', ['DeleteCFNLambda', !Ref BUILDGUID]] |  | ||||||
|       Code: |  | ||||||
|         ZipFile: | |  | ||||||
|           import boto3 |  | ||||||
|           import os |  | ||||||
|           import json |  | ||||||
| 
 |  | ||||||
|           stack_name = os.environ['stackName'] |  | ||||||
|           delete_stack_name = os.environ['deleteStackName'] |  | ||||||
| 
 |  | ||||||
|           def delete_cfn(stack_name): |  | ||||||
|               try: |  | ||||||
|                   cfn = boto3.resource('cloudformation') |  | ||||||
|                   stack = cfn.Stack(stack_name) |  | ||||||
|                   stack.delete() |  | ||||||
|                   return "SUCCESS" |  | ||||||
|               except: |  | ||||||
|                   return "ERROR" |  | ||||||
| 
 |  | ||||||
|           def handler(event, context): |  | ||||||
|               print("Received event:") |  | ||||||
|               print(json.dumps(event)) |  | ||||||
|               result = delete_cfn(stack_name) |  | ||||||
|               delete_cfn(delete_stack_name) |  | ||||||
|               return result |  | ||||||
|       Environment: |  | ||||||
|         Variables: |  | ||||||
|           stackName: !Ref 'StackName' |  | ||||||
|           deleteStackName: !Ref 'DeleteStackName' |  | ||||||
|       Handler: 'index.handler' |  | ||||||
|       Runtime: 'python3.6' |  | ||||||
|       Timeout: '5' |  | ||||||
|       Role: |  | ||||||
|         'Fn::ImportValue': !Sub '${EnvironmentName}:DeleteCFNLambdaExecutionRole' |  | ||||||
|   DeleteStackEventRule: |  | ||||||
|     DependsOn: |  | ||||||
|       - DeleteCFNLambda |  | ||||||
|       - GenerateCronExpression |  | ||||||
|     Type: 'AWS::Events::Rule' |  | ||||||
|     Properties: |  | ||||||
|       Name: !Join ['', ['DeleteStackEventRule', !Ref BUILDGUID]] |  | ||||||
|       Description: Delete stack event |  | ||||||
|       ScheduleExpression: !GetAtt GenerateCronExpression.cron_exp |  | ||||||
|       State: 'ENABLED' |  | ||||||
|       Targets: |  | ||||||
|         - Arn: !GetAtt DeleteCFNLambda.Arn |  | ||||||
|           Id: 'DeleteCFNLambda' |  | ||||||
|   PermissionForDeleteCFNLambda: |  | ||||||
|     Type: 'AWS::Lambda::Permission' |  | ||||||
|     DependsOn: |  | ||||||
|       - DeleteStackEventRule |  | ||||||
|     Properties: |  | ||||||
|       FunctionName: !Join ['', ['DeleteCFNLambda', !Ref BUILDGUID]] |  | ||||||
|       Action: 'lambda:InvokeFunction' |  | ||||||
|       Principal: 'events.amazonaws.com' |  | ||||||
|       SourceArn: !GetAtt DeleteStackEventRule.Arn |  | ||||||
|   GenerateCronExpLambda: |  | ||||||
|     Type: 'AWS::Lambda::Function' |  | ||||||
|     Properties: |  | ||||||
|       FunctionName: !Join ['', ['GenerateCronExpressionLambda', !Ref BUILDGUID]] |  | ||||||
|       Code: |  | ||||||
|         ZipFile: | |  | ||||||
|           from datetime import datetime, timedelta |  | ||||||
|           import os |  | ||||||
|           import logging |  | ||||||
|           import json |  | ||||||
|           import cfnresponse |  | ||||||
| 
 |  | ||||||
|           def deletion_time(ttl): |  | ||||||
|               delete_at_time = datetime.now() + timedelta(minutes=int(ttl)) |  | ||||||
|               hh = delete_at_time.hour |  | ||||||
|               mm = delete_at_time.minute |  | ||||||
|               yyyy = delete_at_time.year |  | ||||||
|               month = delete_at_time.month |  | ||||||
|               dd = delete_at_time.day |  | ||||||
|               # minutes hours day month day-of-week year |  | ||||||
|               cron_exp = "cron({} {} {} {} ? {})".format(mm, hh, dd, month, yyyy) |  | ||||||
|               return cron_exp |  | ||||||
| 
 |  | ||||||
|           def handler(event, context): |  | ||||||
|             print('Received event: %s' % json.dumps(event)) |  | ||||||
|             status = cfnresponse.SUCCESS |  | ||||||
|             try: |  | ||||||
|                 if event['RequestType'] == 'Delete': |  | ||||||
|                     cfnresponse.send(event, context, status, {}) |  | ||||||
|                 else: |  | ||||||
|                     ttl = event['ResourceProperties']['ttl'] |  | ||||||
|                     responseData = {} |  | ||||||
|                     responseData['cron_exp'] = deletion_time(ttl) |  | ||||||
|                     cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData) |  | ||||||
|             except Exception as e: |  | ||||||
|                 logging.error('Exception: %s' % e, exc_info=True) |  | ||||||
|                 status = cfnresponse.FAILED |  | ||||||
|                 cfnresponse.send(event, context, status, {}, None) |  | ||||||
|       Handler: 'index.handler' |  | ||||||
|       Runtime: 'python3.6' |  | ||||||
|       Timeout: '5' |  | ||||||
|       Role: |  | ||||||
|         'Fn::ImportValue': !Sub '${EnvironmentName}:DeleteCFNLambdaExecutionRole' |  | ||||||
|   GenerateCronExpression: |  | ||||||
|     Type: 'Custom::GenerateCronExpression' |  | ||||||
|     Version: '1.0' |  | ||||||
|     Properties: |  | ||||||
|       Name: !Join ['', ['GenerateCronExpression', !Ref BUILDGUID]] |  | ||||||
|       ServiceToken: !GetAtt GenerateCronExpLambda.Arn |  | ||||||
|       ttl: !Ref 'TTL' |  | ||||||
		Loading…
	
		Reference in New Issue