Fix nested Library cache

pull/310/head
Frostebite 2022-01-12 22:56:28 +00:00
parent 8bb695773c
commit 22322303c8
4 changed files with 7 additions and 147 deletions

5
dist/index.js vendored
View File

@ -611,9 +611,10 @@ class Caching {
if (__1.Input.cloudRunnerTests) {
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)}`);
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 {
remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -96,9 +96,10 @@ export class Caching {
if (Input.cloudRunnerTests) {
await CloudRunnerSystem.Run(`tree ${destinationFolder}`);
}
RemoteClientLogger.log(`cache item exists`);
RemoteClientLogger.log(`cache item exists ${cacheSelection}.zip`);
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 {
RemoteClientLogger.logWarning(`cache item ${cacheKey} doesn't exist ${destinationFolder}`);
if (cacheSelection !== ``) {

View File

@ -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'