Skip to content

Commit

Permalink
Passing in Docs Cache endpoint as environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bsinghvi committed May 1, 2024
1 parent 62a86e8 commit 7d5950b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/diff-fdr-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Diff FDR Dev

on:
pull_request:
branches:
- "*"
paths:
- "servers/fdr-deploy/scripts/**"
- ".github/workflows/diff-fdr-dev.yml"
- "pnpm-lock.yaml"
push:
branches:
- "*"
Expand Down
5 changes: 4 additions & 1 deletion servers/fdr-deploy/scripts/elasticache-stack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EnvironmentType } from "@fern-fern/fern-cloud-sdk/api";
import { Environment, Stack, StackProps, Token } from "aws-cdk-lib";
import { CfnOutput, Environment, Stack, StackProps, Token } from "aws-cdk-lib";
import { IVpc, Peer, Port, SecurityGroup } from "aws-cdk-lib/aws-ec2";
import { CfnReplicationGroup, CfnSubnetGroup } from "aws-cdk-lib/aws-elasticache";
import { Construct } from "constructs";
Expand Down Expand Up @@ -72,5 +72,8 @@ export class ElastiCacheStack extends Stack {
Port.tcp(Token.asNumber(this.redisEndpointPort)),
"Redis Port Ingress rule",
);

new CfnOutput(this, `${props.cacheName}Host`, { value: this.redisEndpointAddress });
new CfnOutput(this, `${props.cacheName}Port`, { value: this.redisEndpointPort });
}
}
31 changes: 14 additions & 17 deletions servers/fdr-deploy/scripts/fdr-deploy-stack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EnvironmentInfo, EnvironmentType } from "@fern-fern/fern-cloud-sdk/api";
import { CfnOutput, Duration, RemovalPolicy, Stack, StackProps } from "aws-cdk-lib";
import { Duration, RemovalPolicy, Stack, StackProps } from "aws-cdk-lib";
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
import { Alarm } from "aws-cdk-lib/aws-cloudwatch";
import * as actions from "aws-cdk-lib/aws-cloudwatch-actions";
Expand All @@ -21,8 +21,6 @@ const CONTAINER_NAME = "fern-definition-registry";
const SERVICE_NAME = "fdr";

export class FdrDeployStack extends Stack {
private readonly fernDocsCacheEndpoint: string;

constructor(
scope: Construct,
id: string,
Expand Down Expand Up @@ -79,6 +77,18 @@ export class FdrDeployStack extends Stack {
versioned: true,
});

const fernDocsCache = new ElastiCacheStack(this, "FernDocsCache", {
cacheName: "FernDocsCache",
IVpc: vpc,
numCacheShards: 1,
numCacheReplicasPerShard: environmentType === EnvironmentType.Prod ? 2 : undefined,
clusterMode: "enabled",
cacheNodeType: "cache.r7g.large",
envType: environmentType,
env: props?.env,
ingressSecurityGroup: fdrSg,
});

const cloudmapNamespaceName = environmentInfo.cloudMapNamespaceInfo.namespaceName;
const cloudMapNamespace = PrivateDnsNamespace.fromPrivateDnsNamespaceAttributes(this, "private-cloudmap", {
namespaceArn: environmentInfo.cloudMapNamespaceInfo.namespaceArn,
Expand Down Expand Up @@ -111,6 +121,7 @@ export class FdrDeployStack extends Stack {
ALGOLIA_SEARCH_API_KEY: getEnvironmentVariableOrThrow("ALGOLIA_SEARCH_API_KEY"),
SLACK_TOKEN: getEnvironmentVariableOrThrow("FERNIE_SLACK_APP_TOKEN"),
LOG_LEVEL: getLogLevel(environmentType),
DOCS_CACHE_ENDPOINT: `${fernDocsCache.redisEndpointAddress}:${fernDocsCache.redisEndpointPort}`,
ENABLE_CUSTOMER_NOTIFICATIONS: (environmentType === "PROD").toString(),
},
containerName: CONTAINER_NAME,
Expand Down Expand Up @@ -197,20 +208,6 @@ export class FdrDeployStack extends Stack {
evaluationPeriods: 5,
});
lb500CountAlarm.addAlarmAction(new actions.SnsAction(snsTopic));

const fernDocsCache = new ElastiCacheStack(this, "FernDocsElastiCache", {
cacheName: "FernDocsElastiCache",
IVpc: vpc,
numCacheShards: 1,
numCacheReplicasPerShard: environmentType === EnvironmentType.Prod ? 2 : undefined,
clusterMode: "enabled",
cacheNodeType: "cache.r7g.large",
envType: environmentType,
env: props?.env,
});

this.fernDocsCacheEndpoint = `${fernDocsCache.redisEndpointAddress}:${fernDocsCache.redisEndpointPort}`;
new CfnOutput(this, "FernDocsCacheEndpoint", { value: this.fernDocsCacheEndpoint });
}
}

Expand Down

0 comments on commit 7d5950b

Please sign in to comment.