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

Add eslint linting for CDK code #39

Merged
merged 3 commits into from
Dec 20, 2024
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
21 changes: 21 additions & 0 deletions aoe-infra/infra/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
extends: ['plugin:prettier/recommended'],
plugins: ['prettier'],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true
}, ecmaVersion: 2018, sourceType: 'module'
},
rules: {
curly: 'error',
'no-magic-numbers': 'off',
eqeqeq: 'error',
'no-undef-init': 'error',
'no-unneeded-ternary': 'error',
'no-var': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-template': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off'
}
}
1 change: 1 addition & 0 deletions aoe-infra/infra/.package-lock.json.checksum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions aoe-infra/infra/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"arrowParens": "always",
"bracketSameLine": true,
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"insertPragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
}
48 changes: 26 additions & 22 deletions aoe-infra/infra/bin/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ const app = new cdk.App();
// Load up configuration for the environment
const environmentName: string = app.node.tryGetContext("environment");
const utilityAccountId: string = app.node.tryGetContext("UTILITY_ACCOUNT_ID")

// Allow any in this case, since we don't want to explicitely type json data
/* eslint-disable @typescript-eslint/no-explicit-any */
let environmentConfig: any;
if (environmentName == 'utility') {

if (environmentName === 'utility') {
environmentConfig = utility;
}
else if (environmentName == 'dev') {
else if (environmentName === 'dev') {
environmentConfig = dev;
}
else if (environmentName == 'qa') {
else if (environmentName === 'qa') {
environmentConfig = qa;
}
else if (environmentName == 'prod') {
else if (environmentName === 'prod') {
environmentConfig = prod;
}
else {
Expand All @@ -58,9 +62,9 @@ else {
}

// dev, qa & prod account resources..
if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'prod') {
if (environmentName === 'dev' || environmentName === 'qa' || environmentName === 'prod') {

const githubActionsStack = new GithubActionsStack(app, 'GithubActionsStack', {
new GithubActionsStack(app, 'GithubActionsStack', {
environment: environmentName
})

Expand All @@ -84,7 +88,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
availability_zones: environmentConfig.aws.availability_zones
})

const HostedZones = new HostedZoneStack(app, 'HostedZoneStack', {
new HostedZoneStack(app, 'HostedZoneStack', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-hosted-zone`,
domain: environmentConfig.aws.domain,
Expand All @@ -97,7 +101,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
vpc: Network.vpc,
})

const BastionHost = new BastionStack(app, 'BastionStack', {
new BastionStack(app, 'BastionStack', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-bastion`,
vpc: Network.vpc,
Expand Down Expand Up @@ -203,7 +207,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
env: { region: "eu-west-1" }
})

const FrontEndBucketDeployment = new FrontendStaticContentDeploymentStack(app, 'FrontEndContentDeploymentStack', {
new FrontendStaticContentDeploymentStack(app, 'FrontEndContentDeploymentStack', {
env: { region: "eu-west-1" },
crossRegionReferences: true,
stackName: `${environmentName}-frontend-deployment`,
Expand Down Expand Up @@ -289,7 +293,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
],
})

const DataAnalyticsService = new EcsServiceStack(app, 'DataAnalyticsEcsService', {
new EcsServiceStack(app, 'DataAnalyticsEcsService', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-data-analytics-service`,
serviceName: 'data-analytics',
Expand Down Expand Up @@ -333,7 +337,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
iAmPolicyStatements: [kafkaClusterIamPolicy, kafkaTopicIamPolicy, kafkaGroupIamPolicy]
})

const StreamingAppService = new EcsServiceStack(app, 'StreamingEcsService', {
new EcsServiceStack(app, 'StreamingEcsService', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-streaming-app-service`,
serviceName: 'streaming-app',
Expand Down Expand Up @@ -364,7 +368,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
privateDnsNamespace: namespace.privateDnsNamespace
})

const DataServices = new EcsServiceStack(app, 'DataServicesEcsService', {
new EcsServiceStack(app, 'DataServicesEcsService', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-data-services`,
serviceName: 'data-services',
Expand Down Expand Up @@ -421,7 +425,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
resources: [efs.fileSystem.fileSystemArn]
});

const WebBackendService = new EcsServiceStack(app, 'WebBackendEcsService', {
new EcsServiceStack(app, 'WebBackendEcsService', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-web-backend-service`,
serviceName: 'web-backend',
Expand Down Expand Up @@ -495,7 +499,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
}
})

const WebFrontendService = new EcsServiceStack(app, 'WebFrontendEcsService', {
new EcsServiceStack(app, 'WebFrontendEcsService', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-web-frontend-service`,
serviceName: 'web-frontend',
Expand Down Expand Up @@ -526,7 +530,7 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
privateDnsNamespace: namespace.privateDnsNamespace,
})

const SemanticApisService = new EcsServiceStack(app, 'SemanticApisEcsService', {
new EcsServiceStack(app, 'SemanticApisEcsService', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-semantic-apis-service`,
serviceName: 'semantic-apis',
Expand Down Expand Up @@ -563,44 +567,44 @@ if (environmentName == 'dev' || environmentName == 'qa' || environmentName == 'p
})

}
else if (environmentName == 'utility') {
else if (environmentName === 'utility') {

const Utility = new UtilityStack(app, 'UtilityStack', {
env: { region: "eu-west-1" },
stackName: `${environmentName}-utility`,
})

const FrontendEcr = new EcrStack(app, 'FrontendEcrStack', {
new EcrStack(app, 'FrontendEcrStack', {
env: { region: "eu-west-1" },
stackName: 'aoe-web-frontend-ecr',
serviceName: 'aoe-web-frontend',
githubActionsDeploymentRole: Utility.githubActionsDeploymentRole
})
const BackendEcr = new EcrStack(app, 'BackendEcrStack', {
new EcrStack(app, 'BackendEcrStack', {
env: { region: "eu-west-1" },
stackName: 'aoe-web-backend-ecr',
serviceName: 'aoe-web-backend',
githubActionsDeploymentRole: Utility.githubActionsDeploymentRole
})
const SemanticApisEcr = new EcrStack(app, 'SemanticApisEcrStack', {
new EcrStack(app, 'SemanticApisEcrStack', {
env: { region: "eu-west-1" },
stackName: 'aoe-semantic-apis-ecr',
serviceName: 'aoe-semantic-apis',
githubActionsDeploymentRole: Utility.githubActionsDeploymentRole
})
const StreamingAppEcr = new EcrStack(app, 'StreamingAppEcrStack', {
new EcrStack(app, 'StreamingAppEcrStack', {
env: { region: "eu-west-1" },
stackName: 'aoe-streaming-app-ecr',
serviceName: 'aoe-streaming-app',
githubActionsDeploymentRole: Utility.githubActionsDeploymentRole
})
const DataServicesEcr = new EcrStack(app, 'DataServicesEcrStack', {
new EcrStack(app, 'DataServicesEcrStack', {
env: { region: "eu-west-1" },
stackName: 'aoe-data-services-ecr',
serviceName: 'aoe-data-services',
githubActionsDeploymentRole: Utility.githubActionsDeploymentRole
})
const DataAnalyticsEcr = new EcrStack(app, 'DataAnalyticsEcrStack', {
new EcrStack(app, 'DataAnalyticsEcrStack', {
env: { region: "eu-west-1" },
stackName: 'aoe-data-analytics-ecr',
serviceName: 'aoe-data-analytics',
Expand Down
38 changes: 38 additions & 0 deletions aoe-infra/infra/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import prettier from 'eslint-plugin-prettier'
import tsParser from '@typescript-eslint/parser'
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
{
plugins: {
prettier
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2018,
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
jsx: true
}
}
},

rules: {
curly: 'error',
'no-magic-numbers': 'off',
eqeqeq: 'error',
'no-undef-init': 'error',
'no-unneeded-ternary': 'error',
'no-var': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-template': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off'
}
}
)
121 changes: 58 additions & 63 deletions aoe-infra/infra/lib/alb-stack.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// Create a new cdk stack with a public ALB and a security group for it. Add a https listener with http redirect rule to https. Create outputs for alb and listener.
import * as cdk from 'aws-cdk-lib';
import * as cdk from 'aws-cdk-lib';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as targets from 'aws-cdk-lib/aws-route53-targets';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as log from 'aws-cdk-lib/aws-logs';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as globalaccelerator from 'aws-cdk-lib/aws-globalaccelerator';
import * as ga_endpoints from 'aws-cdk-lib/aws-globalaccelerator-endpoints';
import { Construct } from 'constructs';

interface AlbStackProps extends cdk.StackProps {
Expand All @@ -24,68 +19,68 @@ export class AlbStack extends cdk.Stack {
readonly albListener: elbv2.ApplicationListener;
readonly certificate: acm.ICertificate;
constructor(scope: Construct, id: string, props: AlbStackProps) {
super(scope, id, props);
super(scope, id, props);

// New internet-facing application load balancer, import vpc from the VpcStack
this.alb = new elbv2.ApplicationLoadBalancer(this, 'alb', {
vpc: props.vpc,
vpcSubnets: {
onePerAz: true,
subnetType: ec2.SubnetType.PUBLIC
},
internetFacing: true,
http2Enabled: true,
securityGroup: ec2.SecurityGroup.fromSecurityGroupId(
this,
"ImmutableSecurityGroup",
props.securityGroupId,
{ mutable: false }
)
});
// Use this when an actual domain is available for ACM certs
// new alb listener
this.certificate = new acm.Certificate(this, 'Certificate', {
domainName: `${props.domain}`,
validation: acm.CertificateValidation.fromDns(props.publicHostedZone),
subjectAlternativeNames: [`alb.${props.domain}`],
});
// New internet-facing application load balancer, import vpc from the VpcStack
this.alb = new elbv2.ApplicationLoadBalancer(this, 'alb', {
vpc: props.vpc,
vpcSubnets: {
onePerAz: true,
subnetType: ec2.SubnetType.PUBLIC
},
internetFacing: true,
http2Enabled: true,
securityGroup: ec2.SecurityGroup.fromSecurityGroupId(
this,
"ImmutableSecurityGroup",
props.securityGroupId,
{ mutable: false }
)
});
// Use this when an actual domain is available for ACM certs
// new alb listener
this.certificate = new acm.Certificate(this, 'Certificate', {
domainName: `${props.domain}`,
validation: acm.CertificateValidation.fromDns(props.publicHostedZone),
subjectAlternativeNames: [`alb.${props.domain}`],
});


// route53 alias record for cloudfront
new route53.ARecord(this, 'AliasRecord', {
zone: props.publicHostedZone,
recordName: `alb.${props.domain}`,
target: route53.RecordTarget.fromAlias(new targets.LoadBalancerTarget(this.alb)),
});
// route53 alias record for cloudfront
new route53.ARecord(this, 'AliasRecord', {
zone: props.publicHostedZone,
recordName: `alb.${props.domain}`,
target: route53.RecordTarget.fromAlias(new targets.LoadBalancerTarget(this.alb)),
});

this.albListener = this.alb.addListener('alb-listener', {
port: 443,
protocol: elbv2.ApplicationProtocol.HTTPS,
open: false,
certificates: [this.certificate],
sslPolicy: elbv2.SslPolicy.TLS12,
});
this.albListener = this.alb.addListener('alb-listener', {
port: 443,
protocol: elbv2.ApplicationProtocol.HTTPS,
open: false,
certificates: [this.certificate],
sslPolicy: elbv2.SslPolicy.TLS12,
});


// create ALB default target group
const albDefaultTargetGroup = new elbv2.ApplicationTargetGroup(this, 'alb-target-group', {
vpc: props.vpc,
port: 80,
protocol: elbv2.ApplicationProtocol.HTTP,
targetType: elbv2.TargetType.IP,
healthCheck: {
healthyThresholdCount: 5,
interval: cdk.Duration.seconds(30),
path: '/',
protocol: elbv2.Protocol.HTTP,
timeout: cdk.Duration.seconds(5),
unhealthyThresholdCount: 2
},
});
// create ALB default target group
const albDefaultTargetGroup = new elbv2.ApplicationTargetGroup(this, 'alb-target-group', {
vpc: props.vpc,
port: 80,
protocol: elbv2.ApplicationProtocol.HTTP,
targetType: elbv2.TargetType.IP,
healthCheck: {
healthyThresholdCount: 5,
interval: cdk.Duration.seconds(30),
path: '/',
protocol: elbv2.Protocol.HTTP,
timeout: cdk.Duration.seconds(5),
unhealthyThresholdCount: 2
},
});

this.albListener.addTargetGroups('dummyTargetGroup', {
targetGroups: [albDefaultTargetGroup]
});
this.albListener.addTargetGroups('dummyTargetGroup', {
targetGroups: [albDefaultTargetGroup]
});

}
}
}
}
Loading
Loading