Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumped dependencies and fixed lints #20

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,8 @@
},
"plugins": ["prettier", "@typescript-eslint"],
"rules": {
"prettier/prettier": "error",
"react/react-in-jsx-scope": "off",
"react/jsx-filename-extension": [
1,
{
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
]
"prettier/prettier": "error"
},
"settings": {
"react": {
"version": "detect"
}
}
}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: 22.3.0
hooks:
- id: black
language_version: python3.9
language_version: python3.10

- repo: https:/Yelp/detect-secrets
rev: v1.2.0
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ install:
@pre-commit install

check:
@yarn audit
@yarn lint
@pre-commit run --all-files

build:
for dir in $(shell find ./lib/workload/stateless/layers -maxdepth 1 -mindepth 1 -type d -exec basename {} \;); do ./lib/workload/stateless/layers/create_layer_package.sh $$dir; done

test:
@yarn test
@pytest

build:
@for dir in $(shell find ./lib/workload/stateless/layers -maxdepth 1 -mindepth 1 -type d -exec basename {} \;); do ./lib/workload/stateless/layers/create_layer_package.sh $$dir; done

clean:
@yarn clean
@for zf in $(shell find ./lib/workload/stateless/layers -maxdepth 1 -mindepth 1 -type f -iname '*.zip'); do rm -v $$zf; done
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,73 @@ UMCCR Orchestration Bus that leverage AWS EventBridge as Event Bus to automate t

## Development

### Toolchain

```
conda create -n orcabus python=3.9
docker --version
>Docker version 23.0.5

conda create -n orcabus python=3.10
conda activate orcabus
python -V
>Python 3.10.10

node -v
>v16.15.0

npm i -g yarn
yarn --version
>1.22.19
```

### TL;DR

_Heads up: Polyglot programming environment. So we wrap couple of different tool trivial steps into Makefile target as one-go shortcut! You may deduce step-by-step from Makefile, if any._

```
make install
make check
make test
make build

npx cdk list
npx cdk synth OrcaBusStatefulStack
npx cdk diff OrcaBusStatefulStack
npx cdk deploy OrcaBusStatefulStack

npx cdk synth
npx cdk diff
npx cdk deploy OrcaBusStatefulStack
npx cdk deploy --all
```

### Lint

- Run lint: `yarn lint`
- Fix lint issue: `yarn lint --fix`

### Audit

- Run `yarn audit` for package security vulnerabilities
- Recommend fixing/updating any package with _direct_ dependencies
- If vulnerabilities found in transitive dependency, but it has yet to resolve, then list them in `package.json > resolutions` node as [Selective Dependency Resolutions condition explained here](https://classic.yarnpkg.com/en/docs/selective-version-resolutions/).

### Pre-commit Hook

> NOTE: We use [pre-commit](https:/umccr/wiki/blob/master/computing/dev-environment/git-hooks.md). It will guard and enforce static code analysis such as `lint` and any security `audit` via pre-commit hook. You are encouraged to fix those. If you wish to skip this for good reason, you can by-pass [Git pre-commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) by using `git commit --no-verify` flag.

```commandline
git config --unset core.hooksPath
pre-commit install
pre-commit run --all-files
```

### IDE

- Recommended to use JetBrains IDE
- Code style
- no tab
- indent with `2` spaces for JS/TS/JSON/YAML
- indent with `4` spaces for Python
- For Visual Studio Code, the following extensions are recommended
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
1 change: 0 additions & 1 deletion bin/orcabus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const props: cdk.StackProps = {
},
};


new OrcaBusStatefulStack(app, 'OrcaBusStatefulStack', { ...props, ...orcaBusStatefulConfig });

new OrcaBusStatelessStack(app, 'OrcaBusStatelessStack', { ...props, ...orcaBusStatelessConfig });
6 changes: 3 additions & 3 deletions config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { OrcaBusStatefulConfig } from '../lib/workload/orcabus-stateful-stack';
import { AuroraPostgresEngineVersion } from 'aws-cdk-lib/aws-rds';
import { OrcaBusStatelessConfig } from '../lib/workload/orcabus-stateless-stack';

const regName: string = 'OrcaBusSchemaRegistry';
const eventBusName: string = 'OrcaBusMain';
const lambdaSecurityGroupName: string = 'OrcaBusLambdaSecurityGroup';
const regName = 'OrcaBusSchemaRegistry';
const eventBusName = 'OrcaBusMain';
const lambdaSecurityGroupName = 'OrcaBusLambdaSecurityGroup';

export const orcaBusStatefulConfig: OrcaBusStatefulConfig = {
schemaRegistryProps: {
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
'^.+\\.tsx?$': 'ts-jest',
},
};
14 changes: 9 additions & 5 deletions lib/workload/orcabus-stateful-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { SecurityGroupConstruct, SecurityGroupProps } from './stateful/securityg
import { SchemaRegistryConstruct, SchemaRegistryProps } from './stateful/schemaregistry/component';

export interface OrcaBusStatefulConfig {
schemaRegistryProps: SchemaRegistryProps,
eventBusProps: EventBusProps,
databaseProps: DatabaseProps,
schemaRegistryProps: SchemaRegistryProps;
eventBusProps: EventBusProps;
databaseProps: DatabaseProps;
securityGroupProps: SecurityGroupProps;
}

export class OrcaBusStatefulStack extends cdk.Stack {

constructor(scope: Construct, id: string, props: cdk.StackProps & OrcaBusStatefulConfig) {
super(scope, id, props);

Expand All @@ -26,7 +25,12 @@ export class OrcaBusStatefulStack extends cdk.Stack {

new EventBusConstruct(this, 'OrcaBusEventBusConstruct', props.eventBusProps);
new DatabaseConstruct(this, 'OrcaBusDatabaseConstruct', vpc, props.databaseProps);
new SecurityGroupConstruct(this, 'OrcaBusSecurityGroupConstruct', vpc, props.securityGroupProps);
new SecurityGroupConstruct(
this,
'OrcaBusSecurityGroupConstruct',
vpc,
props.securityGroupProps
);
new SchemaRegistryConstruct(this, 'SchemaRegistryConstruct', props.schemaRegistryProps);
}
}
11 changes: 5 additions & 6 deletions lib/workload/orcabus-stateless-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { BclConvertConstruct, BclConvertProps } from './stateless/bcl_convert/co
import { MultiSchemaConstruct, MultiSchemaConstructProps } from './stateless/schema/component';

export interface OrcaBusStatelessConfig {
multiSchemaConstructProps: MultiSchemaConstructProps,
eventBusName: string,
lambdaSecurityGroupName: string,
bclConvertFunctionName: string,
multiSchemaConstructProps: MultiSchemaConstructProps;
eventBusName: string;
lambdaSecurityGroupName: string;
bclConvertFunctionName: string;
}


export class OrcaBusStatelessStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps & OrcaBusStatelessConfig) {
super(scope, id, props);
Expand All @@ -28,7 +27,7 @@ export class OrcaBusStatelessStack extends cdk.Stack {
this,
'LambdaSecurityGroup',
props.lambdaSecurityGroupName,
vpc,
vpc
),
];

Expand Down
13 changes: 6 additions & 7 deletions lib/workload/stateful/database/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { AuroraPostgresEngineVersion, Credentials } from 'aws-cdk-lib/aws-rds';
import { IVpc } from 'aws-cdk-lib/aws-ec2';

export interface DatabaseProps {
clusterIdentifier: string,
defaultDatabaseName: string,
version: AuroraPostgresEngineVersion,
parameterGroupName: string,
username: string
clusterIdentifier: string;
defaultDatabaseName: string;
version: AuroraPostgresEngineVersion;
parameterGroupName: string;
username: string;
}

export class DatabaseConstruct extends Construct {

constructor(scope: Construct, id: string, vpc: IVpc, props: DatabaseProps) {
super(scope, id);

Expand All @@ -32,7 +31,7 @@ export class DatabaseConstruct extends Construct {
parameterGroup: aws_rds.ParameterGroup.fromParameterGroupName(
this,
id + 'ParameterGroup',
props.parameterGroupName,
props.parameterGroupName
),
removalPolicy: RemovalPolicy.DESTROY,
scaling: {
Expand Down
9 changes: 4 additions & 5 deletions lib/workload/stateful/eventbridge/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { EventBus } from 'aws-cdk-lib/aws-events';
import { Duration, Stack } from 'aws-cdk-lib';

export interface EventBusProps {
eventBusName: string,
archiveName: string,
archiveDescription: string,
archiveRetention: number,
eventBusName: string;
archiveName: string;
archiveDescription: string;
archiveRetention: number;
}

export class EventBusConstruct extends Construct {

constructor(scope: Construct, id: string, props: EventBusProps) {
super(scope, id);
this.createMainBus(props);
Expand Down
9 changes: 3 additions & 6 deletions lib/workload/stateful/schemaregistry/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import { Construct } from 'constructs';
import { aws_eventschemas as eventschemas } from 'aws-cdk-lib';

export interface SchemaRegistryProps {
registryName: string,
description: string
registryName: string;
description: string;
}

export class SchemaRegistryConstruct extends Construct {

constructor(scope: Construct, id: string, props: SchemaRegistryProps) {
super(scope, id);
this.createConstruct(props);
}

private createConstruct(props: SchemaRegistryProps) {

const cfnRegistry = new eventschemas.CfnRegistry(this, props.registryName, {
new eventschemas.CfnRegistry(this, props.registryName, {
description: props.description,
registryName: props.registryName,
});
}

}
11 changes: 7 additions & 4 deletions lib/workload/stateful/securitygroup/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { IVpc, SecurityGroup } from 'aws-cdk-lib/aws-ec2';
import { aws_ec2 } from 'aws-cdk-lib';

export interface SecurityGroupProps {
securityGroupName: string,
securityGroupDescription: string,
securityGroupName: string;
securityGroupDescription: string;
}

export class SecurityGroupConstruct extends Construct {

constructor(scope: Construct, id: string, vpc: IVpc, props: SecurityGroupProps) {
super(scope, id);

Expand All @@ -17,6 +16,10 @@ export class SecurityGroupConstruct extends Construct {
vpc: vpc,
allowAllOutbound: true,
});
lambdaSecurityGroup.addIngressRule(lambdaSecurityGroup, aws_ec2.Port.allTraffic(), props.securityGroupDescription);
lambdaSecurityGroup.addIngressRule(
lambdaSecurityGroup,
aws_ec2.Port.allTraffic(),
props.securityGroupDescription
);
}
}
2 changes: 1 addition & 1 deletion lib/workload/stateful/vpc/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Construct } from 'constructs';
export function getVpc(scope: Construct) {
const vpcName = 'main-vpc';
const vpcTags = {
'Stack': 'networking',
Stack: 'networking',
};

return aws_ec2.Vpc.fromLookup(scope, 'MainVpc', {
Expand Down
13 changes: 6 additions & 7 deletions lib/workload/stateless/bcl_convert/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { IEventBus, Rule } from 'aws-cdk-lib/aws-events';
import { ILayerVersion } from 'aws-cdk-lib/aws-lambda';

export interface BclConvertProps {
layers: ILayerVersion[],
securityGroups: ISecurityGroup[],
vpc: IVpc,
mainBus: IEventBus,
functionName: string,
layers: ILayerVersion[];
securityGroups: ISecurityGroup[];
vpc: IVpc;
mainBus: IEventBus;
functionName: string;
}

export class BclConvertConstruct extends Construct {

constructor(scope: Construct, id: string, props: BclConvertProps) {
super(scope, id);

Expand Down Expand Up @@ -48,7 +47,7 @@ export class BclConvertConstruct extends Construct {

bclConvertEventRule.addTarget(new aws_events_targets.LambdaFunction(bclConvertLambda));
bclConvertEventRule.addEventPattern({
source: ['ORCHESTRATOR'], // FIXME how to impl? how to share a "code construct" between TS and Py... One way is jsii
source: ['ORCHESTRATOR'], // FIXME how to impl? how to share a "code construct" between TS and Py... One way is jsii
detailType: ['SequenceRunStateChange'],
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/workload/stateless/layers/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class LambdaLayerConstruct extends Construct {

constructor(scope: Construct, id: string) {
super(scope, id);
this._eb_util = this.createLambdaLayer('eb_util'); // FIXME refactor, externalise the deps dir, see todo in orcabus-stateless-stack.ts
this._eb_util = this.createLambdaLayer('eb_util'); // FIXME refactor, externalise the deps dir, see todo in orcabus-stateless-stack.ts
this._schema = this.createLambdaLayer('schema');

this._all.push(this._eb_util);
Expand Down
2 changes: 1 addition & 1 deletion lib/workload/stateless/layers/create_layer_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ docker run \
--rm \
-v ${SCRIPT_PATH}/python:/foo \
-w /foo \
public.ecr.aws/sam/build-python3.9 \
public.ecr.aws/sam/build-python3.10 \
pip install -r requirements.txt --no-deps -t ./

# clean the lib directory
Expand Down
Loading