Skip to content

Commit

Permalink
Add aws-mysql-rotator agent
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanoogian committed Jul 13, 2022
1 parent c3cda7d commit f297131
Show file tree
Hide file tree
Showing 10 changed files with 676 additions and 162 deletions.
40 changes: 40 additions & 0 deletions apps/aws-mysql-rotator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM node:16-alpine as build

WORKDIR /usr/src/app

# Copy package files and install all dependencies
COPY ./package*.json ./
COPY ./agent-core/package*.json ./agent-core/
COPY ./rotators/mysql/package*.json ./rotators/mysql/
COPY ./utils/aws/package*.json ./utils/aws/
COPY ./apps/aws-mysql-rotator/package*.json ./apps/aws-mysql-rotator/
RUN npm install --workspace apps/aws-mysql-rotator

RUN ls -l node_modules

# Copy sources
COPY ./tsconfig* ./
COPY ./agent-core ./agent-core
COPY ./rotators/mysql ./rotators/mysql
COPY ./utils/aws ./utils/aws
COPY ./apps/aws-mysql-rotator ./apps/aws-mysql-rotator

# Build dependencies and app
RUN npm --prefix ./agent-core run build
RUN npm --prefix ./rotators/mysql run build
RUN npm --prefix ./utils/aws run build
RUN npm --prefix ./apps/aws-mysql-rotator run build

# Remove node_modules to be reinstalled later
RUN rm -r node_modules

FROM public.ecr.aws/lambda/nodejs:16

WORKDIR ${LAMBDA_TASK_ROOT}

COPY --from=build /usr/src/app .

# Only install production dependencies
RUN npm install --production

CMD [ "apps/aws-mysql-rotator/dist/app.handler" ]
13 changes: 13 additions & 0 deletions apps/aws-mysql-rotator/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { JWKSOption, processRequest } from "agent-core";
import mysqlHandler from "mysql-rotator";
import { fetchS3KeySet } from "aws-utils";

export async function handler(event: { body: string }) {
let keySetOption: JWKSOption;
if (process.env.OVERRIDE_KEY_SET) {
keySetOption = { type: "local", keySet: JSON.parse(process.env.OVERRIDE_KEY_SET) };
} else {
keySetOption = { type: "local", keySet: await fetchS3KeySet(process.env.OVERRIDE_KEY_SET_S3_BUCKET ?? undefined) };
}
return await processRequest(event.body, mysqlHandler, { overrideKeySet: keySetOption });
}
25 changes: 25 additions & 0 deletions apps/aws-mysql-rotator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "aws-mysql-rotator",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "dist/app.js",
"types": "dist/app.d.ts",
"engines": {
"node": "16.x"
},
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^4.6.4"
},
"dependencies": {
"agent-core": "*",
"mysql-rotator": "*",
"aws-utils": "*"
}
}
7 changes: 7 additions & 0 deletions apps/aws-mysql-rotator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"references": [{ "path": "../../agent-core" }, { "path": "../../rotators/mysql" }, { "path": "../../utils/aws" }]
}
Loading

0 comments on commit f297131

Please sign in to comment.