-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from umccr/deploy/filemanager
filemanager: deploy changes and fixes
- Loading branch information
Showing
33 changed files
with
2,505 additions
and
331 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// generated by `sqlx migrate build-script` | ||
fn main() { | ||
// trigger recompilation when a new migration is added | ||
println!("cargo:rerun-if-changed=migrations"); | ||
} | ||
println!("cargo:rerun-if-changed=database/migrations"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lib/workload/stateful/filemanager/deploy/bin/filemanager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
import 'source-map-support/register'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { FilemanagerStack } from '../lib/filemanager_stack'; | ||
import { Tags } from 'aws-cdk-lib'; | ||
|
||
export const STACK_NAME = 'FilemanagerStack'; | ||
const STACK_DESCRIPTION = 'A stack deploying filemanager to dev.'; | ||
|
||
const app = new cdk.App(); | ||
new FilemanagerStack( | ||
app, | ||
STACK_NAME, | ||
{ | ||
stackName: STACK_NAME, | ||
description: STACK_DESCRIPTION, | ||
tags: { | ||
Stack: STACK_NAME, | ||
}, | ||
env: { | ||
region: 'ap-southeast-2', | ||
}, | ||
}, | ||
{ | ||
destroyOnRemove: true, | ||
enableMonitoring: { | ||
enablePerformanceInsights: true, | ||
}, | ||
public: [ | ||
// Put your IP here if you want the database to be reachable. | ||
], | ||
migrateDatabase: process.env.FILEMANAGER_DEPLOY_MIGRATE_DATABASE == 'true', | ||
} | ||
); | ||
|
||
Tags.of(app).add('Stack', STACK_NAME); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
lib/workload/stateful/filemanager/deploy/constructs/cdk_resource_invoke.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { Construct, IDependable } from 'constructs'; | ||
import { | ||
AwsCustomResource, | ||
AwsCustomResourcePolicy, | ||
AwsSdkCall, | ||
PhysicalResourceId, | ||
} from 'aws-cdk-lib/custom-resources'; | ||
import { IVpc, SubnetType } from 'aws-cdk-lib/aws-ec2'; | ||
import * as fn from './functions/function'; | ||
import { ManagedPolicy, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; | ||
import { CfnOutput, Stack, Token } from 'aws-cdk-lib'; | ||
|
||
/** | ||
* Props for the resource invoke construct. | ||
*/ | ||
export type CdkResourceInvokeProps = { | ||
/** | ||
* Vpc for the function. | ||
*/ | ||
vpc: IVpc; | ||
/** | ||
* The function to create. This will override the function name to ensure that it remains | ||
* callable using the singleton function created by `AwsCustomResource`. See | ||
* https://github.com/aws-samples/amazon-rds-init-cdk/blob/239626632f399ebe4928410a49d5ac5d009a6502/lib/resource-initializer.ts#L69-L71. | ||
*/ | ||
createFunction: (scope: Construct, id: string, props: fn.FunctionPropsNoPackage) => fn.Function; | ||
/** | ||
* Function props when creating the Lambda function. | ||
*/ | ||
functionProps: fn.FunctionPropsNoPackage; | ||
/** | ||
* Name to use when creating the function. | ||
*/ | ||
id: string; | ||
/** | ||
* Dependencies for this resource. | ||
*/ | ||
dependencies?: IDependable[]; | ||
}; | ||
|
||
/** | ||
* A construct for invoking a Lambda function for resource initialization. | ||
*/ | ||
export class CdkResourceInvoke extends Construct { | ||
private readonly _response: string; | ||
private readonly _customResource: AwsCustomResource; | ||
private readonly _function: fn.Function; | ||
|
||
constructor(scope: Construct, id: string, props: CdkResourceInvokeProps) { | ||
super(scope, id); | ||
|
||
const stack = Stack.of(this); | ||
this._function = props.createFunction(this, props.id, { | ||
...props.functionProps, | ||
functionName: `${stack.stackName}-ResourceInvokeFunction-${props.id}`, | ||
}); | ||
|
||
// Call another lambda function with no arguments. | ||
const sdkCall: AwsSdkCall = { | ||
service: 'Lambda', | ||
action: 'invoke', | ||
parameters: { | ||
FunctionName: this.function.functionName(), | ||
}, | ||
physicalResourceId: PhysicalResourceId.of( | ||
`${id}-AwsSdkCall-${this.function.currentVersion()}` | ||
), | ||
}; | ||
|
||
const role = new Role(this, 'AwsCustomResourceRole', { | ||
assumedBy: new ServicePrincipal('lambda.amazonaws.com'), | ||
}); | ||
role.addToPolicy( | ||
new PolicyStatement({ | ||
resources: [ | ||
// This needs to have permissions to run any `ResourceInvokeFunction` because it is deployed as a | ||
// singleton Lambda function. | ||
`arn:aws:lambda:${stack.region}:${stack.account}:function:${stack.stackName}-ResourceInvokeFunction-*`, | ||
], | ||
actions: ['lambda:InvokeFunction'], | ||
}) | ||
); | ||
// Also require VPC access for a Lambda function within the VPC. | ||
role.addManagedPolicy( | ||
ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaVPCAccessExecutionRole') | ||
); | ||
|
||
this._customResource = new AwsCustomResource(this, 'AwsCustomResource', { | ||
policy: AwsCustomResourcePolicy.fromSdkCalls({ | ||
resources: AwsCustomResourcePolicy.ANY_RESOURCE, | ||
}), | ||
onUpdate: sdkCall, | ||
role: role, | ||
vpc: props.vpc, | ||
vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS }, | ||
}); | ||
|
||
this._response = this.customResource.getResponseField('Payload'); | ||
|
||
// Add any dependencies. | ||
props.dependencies?.forEach((dependency) => this.addDependency(dependency)); | ||
|
||
// Output the result. | ||
new CfnOutput(this, 'MigrateDatabaseResponse', { | ||
value: Token.asString(this.response), | ||
}); | ||
} | ||
|
||
/** | ||
* Add a dependency to this resource. | ||
*/ | ||
addDependency(dependency: IDependable) { | ||
this.customResource.node.addDependency(dependency); | ||
} | ||
|
||
/** | ||
* Get the function response. | ||
*/ | ||
get response(): string { | ||
return this._response; | ||
} | ||
|
||
/** | ||
* Get the custom resource. | ||
*/ | ||
get customResource(): AwsCustomResource { | ||
return this._customResource; | ||
} | ||
|
||
/** | ||
* Get the function. | ||
*/ | ||
get function(): fn.Function { | ||
return this._function; | ||
} | ||
} |
Oops, something went wrong.