Skip to content

Commit

Permalink
changing from esbuild to tsc because we are not bundling dist anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio Stutz committed Jan 13, 2024
1 parent 0e3ccdf commit 21196dc
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 1,228 deletions.
15 changes: 4 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@ SHELL := /bin/bash
build: install
rm -rf dist

@# TODO bundle dist after stabilisation
@# pnpm exec esbuild src/index.ts --bundle --minify --platform=node --outfile=dist/index.js
@# Don't bundle so internal CDK constructs continue working on clients
pnpm exec tsc --outDir dist

@# don't bundle dist for now (helps with debugging in clients)
pnpm exec esbuild src/*.ts src/**/*.ts --platform=node --format=cjs --outdir=dist

pnpm exec tsc --emitDeclarationOnly --outDir dist

-find ./dist -name "*.test.js" -exec rm -rf {} \;
-find ./dist -name "*.test.d.ts" -exec rm -rf {} \;
-find ./dist -name "__tests__" -exec rm -rf {} \;
@# remove all tests from distribution
@-find -E ./dist -regex '.*\.test\..*|.*__tests.*' -exec rm -rf {} \;

lint:
pnpm exec eslint ./src --ext .ts
pnpm exec tsc -noEmit --skipLibCheck
pnpm audit

test: unit-tests
Expand Down
22 changes: 22 additions & 0 deletions example/cdk/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable no-new */
import { App } from 'aws-cdk-lib/core';

import { resolveStackNameAndPropsForStage } from '../cdk-shared2-nn/stack';
import { globalConfig } from '../cdk-shared3-monorepo/globals';

import { AppStack } from './stack';

const { STAGE } = requireEnvVars(['STAGE']);

const app = new App();

const { stackName, stackProps } = resolveStackNameAndPropsForStage({
stage: STAGE,
globalConfig,
serviceName: 'splunk-forward-service',
snowApplicationServiceNamePrefix: 'Splunk Forward Service',
});

new AppStack(app, stackName, stackProps);

app.synth();
35 changes: 35 additions & 0 deletions example/cdk/global-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable camelcase */

import { RetentionDays } from 'aws-cdk-lib/aws-logs';

// Global configs
export const globalConfig = {
default: {
env: {
region: 'us-east-1',
},
lambda: {
allowTLSOutboundTo: '10.0.0.0/8',
logRetention: RetentionDays.ONE_WEEK,
},
services: defaultServicesConfig,
},
dev: {
lambda: {},
},
tst: {
lambda: {
logRetention: RetentionDays.ONE_WEEK,
},
},
acc: {
lambda: {
logRetention: RetentionDays.ONE_MONTH,
},
},
prd: {
lambda: {
logRetention: RetentionDays.SIX_MONTHS,
},
},
};
48 changes: 48 additions & 0 deletions example/cdk/stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable camelcase */
import { ScopedAws } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { Peer, Port } from 'aws-cdk-lib/aws-ec2';
import { StringParameter } from 'aws-cdk-lib/aws-ssm';

import { DefaultStackProps } from '../cdk-shared2-nn/stack';
import { EventType } from '../cdk-shared1-public/constructs/lambda/types';
import { BaseNodeJsFunction } from '../cdk-shared1-public/constructs/lambda/lambda-base';
import { DefaultStack } from '../cdk-shared2-nn/constructs/default-stack';

export class AppStack extends DefaultStack {
constructor(scope: Construct, id: string, props: DefaultStackProps) {
super(scope, id, props);

const { accountId, region } = new ScopedAws(this);

// eslint-disable-next-line no-new
const func = new BaseNodeJsFunction(this, 'splunkForward', {
...props.stageConfig.lambda,
stage: props.stage,
network: props.stageConfig.network,
eventType: EventType.Cloudwatch,
description: 'Forwards Cloudwatch events to Splunk',
initialPolicy: [
PolicyStatement.fromJson({
Effect: 'Allow',
Action: 'secretsmanager:GetSecretValue',
Resource: `arn:aws:secretsmanager:${region}:${accountId}:secret:services/splunk-forward-service/splunk-hec-token*`,
}),
],
});
func.defaultSecurityGroup.addEgressRule(
Peer.ipv4('10.109.0.0/16'),
Port.tcp(8088),
'Allow connection to Splunk Collector',
);

// Store splunk forward lambda arn in parameter store
// eslint-disable-next-line no-new
new StringParameter(this, 'SplunkForwardLambdaArn', {
parameterName: `/${props.stage}/services/splunk-forward-service/lambda-arn`,
description: 'Cloudwatch to Splunk log forwarder Lambda ARN',
stringValue: func.nodeJsFunction.functionArn,
});
}
}
31 changes: 31 additions & 0 deletions example/cdk/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable camelcase */

import { NetworkConfig } from '../../src/lambda/types';

// https://stackoverflow.com/questions/43159887/make-a-single-property-optional-in-typescript
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

/**
* Configurations resolved for a specific stage
*/
export type StageConfig = {
services: ServiceConfig;
lambda: GlobalLambdaConfig;
env: {
account?: string;
region: string;
};
network?: NetworkConfig;
};

/**
* Global configurations
* This will be used to resolve configurations for specific stages
*/
export type GlobalConfig = {
default: StageConfig;
dev?: StageConfig;
tst: StageConfig;
acc: StageConfig;
prd: StageConfig;
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
"@stutzlab/eslint-config": "^3.0.2",
"@tsconfig/node16": "16.1.1",
"@types/jest": "^29.4.0",
"esbuild": "^0.19.11",
"esbuild-jest": "^0.5.0",
"jest": "^29.4.2",
"typescript": "^4.9.5"
},
Expand All @@ -41,7 +39,7 @@
"fs": "0.0.1-security",
"npm-which": "^3.0.1",
"openapi3-ts": "^4.2.1",
"scoperjs": "^1.0.0",
"scoperjs": "^1.0.1",
"tmp": "^0.2.1",
"zod": "^3.22.4"
},
Expand Down
Loading

0 comments on commit 21196dc

Please sign in to comment.