Skip to content

Commit

Permalink
push up deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Oct 1, 2024
1 parent 3f0b401 commit 57ceee4
Show file tree
Hide file tree
Showing 15 changed files with 1,059 additions and 245 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/deploy-grpc-proxy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy FDR Dev

on:
push:
branches:
- main

env:
PACKAGE_NAME: "@fern-platform/grpc-proxy"
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: "buildwithfern"
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FERNIE_SLACK_APP_TOKEN: ${{ secrets.FERNIE_SLACK_APP_TOKEN }}
GITHUB_TOKEN: ${{ secrets.FERN_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.FERN_NPM_TOKEN }}

jobs:
deploy_dev:
runs-on: ubuntu-latest
environment: Fern Dev
strategy:
matrix:
concurrency: [1]
env:
APPLICATION_ENVIRONMENT: dev
steps:
- uses: actions/checkout@v4
- name: 📥 Install
uses: ./.github/actions/install

- name: 🧪 Build and test
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
pnpm turbo codegen build test --filter=${{ env.PACKAGE_NAME }}
pnpm --filter "@fern-platform/grpc-proxy" sentry:sourcemaps
- name: 💻 Setup AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: 🚀 cdk deploy
run: |
git_version="$(scripts/git-version.sh)"
pnpm --filter=@fern-platform/grpc-proxy run docker:dev "${git_version}"
npm install -g aws-cdk
cd servers/grpc-proxy-deploy
VERSION="${git_version}" pnpm --filter=@fern-platform/grpc-proxy-deploy deploy:dev
800 changes: 555 additions & 245 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions servers/grpc-proxy-deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out
6 changes: 6 additions & 0 deletions servers/grpc-proxy-deploy/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
1 change: 1 addition & 0 deletions servers/grpc-proxy-deploy/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@fern-fern:registry=https://npm.buildwithfern.com
1 change: 1 addition & 0 deletions servers/grpc-proxy-deploy/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("../../.prettierrc.json");
14 changes: 14 additions & 0 deletions servers/grpc-proxy-deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Welcome to your CDK TypeScript project

This is a blank project for CDK development with TypeScript.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

## Useful commands

- `npm run build` compile typescript to js
- `npm run watch` watch for changes and compile
- `npm run test` perform the vitest unit tests
- `cdk deploy` deploy this stack to your default AWS account/region
- `cdk diff` compare deployed stack with current state
- `cdk synth` emits the synthesized CloudFormation template
75 changes: 75 additions & 0 deletions servers/grpc-proxy-deploy/bin/grpc-proxy-deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env node
import { Environments, EnvironmentType } from "@fern-fern/fern-cloud-sdk/api/";
import * as cdk from "aws-cdk-lib";
import axios from "axios";
import { GrpcDeployStack } from "../scripts/grpc-deploy-stack";

void main();

async function main() {
const version = process.env["VERSION"];
if (version === undefined) {
throw new Error("Version is not specified!");
}
const environments = await getEnvironments();
const app = new cdk.App();
for (const [environmentType, environmentInfo] of Object.entries(environments)) {
if (environmentInfo == null) {
throw new Error(`No info for environment ${environmentType}`);
}
switch (environmentType) {
case EnvironmentType.Dev:
case EnvironmentType.Dev2:
new GrpcDeployStack(
app,
`grpc-proxy-${environmentType.toLowerCase()}`,
version,
environmentType,
environmentInfo,
{
desiredTaskCount: 2,
maxTaskCount: 4,
memory: 4096,
cpu: 2048,
},
{
env: { account: "985111089818", region: "us-east-1" },
},
);
break;
case EnvironmentType.Prod:
new GrpcDeployStack(
app,
`grpc-proxy-${environmentType.toLowerCase()}`,
version,
environmentType,
environmentInfo,
{
desiredTaskCount: 2,
maxTaskCount: 4,
memory: 4096,
cpu: 2048,
},
{
env: { account: "985111089818", region: "us-east-1" },
},
);
break;
default:
return;
}
}
}

async function getEnvironments(): Promise<Environments> {
const response = await axios(
"https://raw.githubusercontent.com/fern-api/fern-cloud/main/env-scoped-resources/environments.json",
{
method: "GET",
headers: {
Authorization: "Bearer " + process.env["GITHUB_TOKEN"],
},
},
);
return response.data as Environments;
}
55 changes: 55 additions & 0 deletions servers/grpc-proxy-deploy/cdk.context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"vpc-provider:account=985111089818:filter.vpc-id=vpc-77ec960a:region=us-east-1:returnAsymmetricSubnets=true": {
"vpcId": "vpc-77ec960a",
"vpcCidrBlock": "172.31.0.0/16",
"availabilityZones": [],
"subnetGroups": [
{
"name": "Public",
"type": "Public",
"subnets": [
{
"subnetId": "subnet-9bdc25d7",
"cidr": "172.31.16.0/20",
"availabilityZone": "us-east-1a",
"routeTableId": "rtb-22b17153"
},
{
"subnetId": "subnet-8e567cd1",
"cidr": "172.31.32.0/20",
"availabilityZone": "us-east-1b",
"routeTableId": "rtb-22b17153"
},
{
"subnetId": "subnet-7f341d19",
"cidr": "172.31.0.0/20",
"availabilityZone": "us-east-1c",
"routeTableId": "rtb-22b17153"
},
{
"subnetId": "subnet-d5c1f5f4",
"cidr": "172.31.80.0/20",
"availabilityZone": "us-east-1d",
"routeTableId": "rtb-22b17153"
},
{
"subnetId": "subnet-ed473adc",
"cidr": "172.31.48.0/20",
"availabilityZone": "us-east-1e",
"routeTableId": "rtb-22b17153"
},
{
"subnetId": "subnet-7efc1f7f",
"cidr": "172.31.64.0/20",
"availabilityZone": "us-east-1f",
"routeTableId": "rtb-22b17153"
}
]
}
]
},
"security-group:account=985111089818:region=us-east-1:securityGroupName=fern-dev-efs-sg:vpcId=vpc-77ec960a": {
"securityGroupId": "sg-0a30296043014c627",
"allowAllOutbound": false
}
}
34 changes: 34 additions & 0 deletions servers/grpc-proxy-deploy/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"app": "npx ts-node bin/fdr-deploy.ts",
"watch": {
"include": ["**"],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
"@aws-cdk/core:stackRelativeExports": true,
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"]
}
}
32 changes: 32 additions & 0 deletions servers/grpc-proxy-deploy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@fern-platform/grpc-proxy-deploy",
"version": "0.1.0",
"bin": "bin/grpc-proxydeploy.js",
"scripts": {
"watch": "tsc -w",
"cdk": "cdk",
"deploy:dev": "cdk deploy grpc-proxy-dev2 --require-approval never --progress events",
"deploy:prod": "cdk deploy grpc-proxy-prod --require-approval never --progress events",
"rediscli": "node ./node_modules/redis-cli/index.js"
},
"devDependencies": {
"@fern-platform/configs": "workspace:*",
"@types/node": "^18.7.18",
"@types/prettier": "2.6.0",
"aws-cdk": "^2.139.0",
"vitest": "^1.5.0",
"prettier": "^3.3.2",
"ts-node": "^10.9.1",
"@types/jest": "^29.5.12",
"redis-cli": "^2.1.2",
"typescript": "5.4.3"
},
"dependencies": {
"@fern-fern/fern-cloud-sdk": "^0.0.257",
"aws-cdk-lib": "^2.122.0",
"axios": "^1.6.5",
"constructs": "^10.3.0",
"redis": "^4.6.13",
"source-map-support": "^0.5.21"
}
}
Loading

0 comments on commit 57ceee4

Please sign in to comment.