Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

fix: backend prod dockerfile #596

Merged
merged 1 commit into from
Jul 24, 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
148 changes: 148 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
FROM node:18-alpine AS build_image
WORKDIR /app

COPY ./fern /app/fern
COPY ./packages/backend /app/packages/backend
COPY ./packages/backend/tsconfig.json /app/packages/backend/tsconfig.json
COPY ./yarn.lock /app/yarn.lock
COPY ./package.json /app/package.json
COPY ./.yarnrc.yml /app/.yarnrc.yml
COPY ./.yarn /app/.yarn

ARG SERVER_PORT
ARG NODE_ENV
ARG AES_ENCRYPTION_SECRET
ARG SVIX_ENDPOINT_SECRET
ARG WHITE_LISTED_DOMAINS
ARG CLOSECRM_CLIENT_ID
ARG CLOSECRM_CLIENT_SECRET
ARG SENTRY_DSN
ARG ZOHOCRM_CLIENT_ID
ARG ZOHOCRM_CLIENT_SECRET
ARG SLACK_CLIENT_ID
ARG SLACK_CLIENT_SECRET
ARG LOOPS_API_KEY
ARG LOOPS_ONBOARDING_TXN_ID
ARG PIPEDRIVE_CLIENT_SECRET
ARG SLACK_HOOK_URL
ARG SLACK_BOT_TOKEN
ARG SVIX_AUTH_TOKEN
ARG MOESIF_APPLICATION_ID
ARG SHORTLOOP_AUTH_KEY
ARG PIPEDRIVE_CLIENT_ID
ARG DISABLE_REVERT_TELEMETRY
ARG MS_DYNAMICS_SALES_CLIENT_ID
ARG MS_DYNAMICS_SALES_CLIENT_SECRET
ARG MS_DYNAMICS_SALES_ORG_URL
ARG REDIS_SERVER_URL
ARG HUBSPOT_CLIENT_ID
ARG HUBSPOT_CLIENT_SECRET
ARG ZOHOCRM_CLIENT_ID
ARG ZOHOCRM_CLIENT_SECRET
ARG PGSQL_URL
ARG SFDC_CLIENT_ID
ARG SFDC_CLIENT_SECRET
ARG OAUTH_REDIRECT_BASE
ARG FERN_TOKEN
ARG PORT
ARG POSTMAN_API_KEY
ARG POSTMAN_WORKSPACE_ID

RUN echo $PGSQL_URL
ENV SERVER_PORT=$PORT
ENV REDIS_SERVER_URL=$REDIS_SERVER_URL
ENV HUBSPOT_CLIENT_ID=$HUBSPOT_CLIENT_ID
ENV HUBSPOT_CLIENT_SECRET=$HUBSPOT_CLIENT_SECRET
ENV ZOHOCRM_CLIENT_ID=$ZOHOCRM_CLIENT_ID
ENV ZOHOCRM_CLIENT_SECRET=$ZOHOCRM_CLIENT_SECRET
ENV PGSQL_URL=$PGSQL_URL
ENV SFDC_CLIENT_ID=$SFDC_CLIENT_ID
ENV SFDC_CLIENT_SECRET=$SFDC_CLIENT_SECRET
ENV OAUTH_REDIRECT_BASE=$OAUTH_REDIRECT_BASE
ENV PORT=$PORT
ENV FERN_TOKEN=$FERN_TOKEN
ENV POSTMAN_API_KEY=$POSTMAN_API_KEY
ENV POSTMAN_WORKSPACE_ID=$POSTMAN_WORKSPACE_ID
ENV NODE_ENV=$NODE_ENV
ENV AES_ENCRYPTION_SECRET=$AES_ENCRYPTION_SECRET
ENV SVIX_ENDPOINT_SECRET=$SVIX_ENDPOINT_SECRET
ENV WHITE_LISTED_DOMAINS=$WHITE_LISTED_DOMAINS
ENV CLOSECRM_CLIENT_ID=$CLOSECRM_CLIENT_ID
ENV CLOSECRM_CLIENT_SECRET=$CLOSECRM_CLIENT_SECRET
ENV SENTRY_DSN=$SENTRY_DSN
ENV ZOHOCRM_CLIENT_ID=$ZOHOCRM_CLIENT_ID
ENV ZOHOCRM_CLIENT_SECRET=$ZOHOCRM_CLIENT_SECRET
ENV SLACK_CLIENT_ID=$SLACK_CLIENT_ID
ENV SLACK_CLIENT_SECRET=$SLACK_CLIENT_SECRET
ENV LOOPS_API_KEY=$LOOPS_API_KEY
ENV LOOPS_ONBOARDING_TXN_ID=$LOOPS_ONBOARDING_TXN_ID
ENV PIPEDRIVE_CLIENT_SECRET=$PIPEDRIVE_CLIENT_SECRET
ENV SLACK_HOOK_URL=$SLACK_HOOK_URL
ENV SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN
ENV SVIX_AUTH_TOKEN=$SVIX_AUTH_TOKEN
ENV MOESIF_APPLICATION_ID=$MOESIF_APPLICATION_ID
ENV SHORTLOOP_AUTH_KEY=$SHORTLOOP_AUTH_KEY
ENV PIPEDRIVE_CLIENT_ID=$PIPEDRIVE_CLIENT_ID
ENV DISABLE_REVERT_TELEMETRY=$DISABLE_REVERT_TELEMETRY
ENV MS_DYNAMICS_SALES_CLIENT_ID=$MS_DYNAMICS_SALES_CLIENT_ID
ENV MS_DYNAMICS_SALES_CLIENT_SECRET=$MS_DYNAMICS_SALES_CLIENT_SECRET
ENV MS_DYNAMICS_SALES_ORG_URL=$MS_DYNAMICS_SALES_ORG_URL

# create .env from the vars passed.
RUN echo "SERVER_PORT=$SERVER_PORT" > .env \
&& echo "REDIS_SERVER_URL=$REDIS_SERVER_URL" >> .env \
&& echo "HUBSPOT_CLIENT_ID=$HUBSPOT_CLIENT_ID" >> .env \
&& echo "HUBSPOT_CLIENT_SECRET=$HUBSPOT_CLIENT_SECRET" >> .env \
&& echo "ZOHOCRM_CLIENT_ID=$ZOHOCRM_CLIENT_ID" >> .env \
&& echo "ZOHOCRM_CLIENT_SECRET=$ZOHOCRM_CLIENT_SECRET" >> .env \
&& echo "PGSQL_URL=$PGSQL_URL" >> .env \
&& echo "SFDC_CLIENT_ID=$SFDC_CLIENT_ID" >> .env \
&& echo "SFDC_CLIENT_SECRET=$SFDC_CLIENT_SECRET" >> .env \
&& echo "OAUTH_REDIRECT_BASE=$OAUTH_REDIRECT_BASE" >> .env \
&& echo "POSTMAN_API_KEY=$POSTMAN_API_KEY" >> .env \
&& echo "POSTMAN_WORKSPACE_ID=$POSTMAN_WORKSPACE_ID" >> .env \
&& echo "PORT=$PORT" >> .env \
&& echo "FERN_TOKEN=$FERN_TOKEN" >> .env \
&& echo "NODE_ENV=$NODE_ENV" >> .env \
&& echo "AES_ENCRYPTION_SECRET=$AES_ENCRYPTION_SECRET" >> .env \
&& echo "SVIX_ENDPOINT_SECRET=$REDIS_SERVER_URL" >> .env \
&& echo "WHITE_LISTED_DOMAINS=$WHITE_LISTED_DOMAINS" >> .env \
&& echo "CLOSECRM_CLIENT_ID=$CLOSECRM_CLIENT_ID" >> .env \
&& echo "CLOSECRM_CLIENT_SECRET=$CLOSECRM_CLIENT_SECRET" >> .env \
&& echo "SENTRY_DSN=$SENTRY_DSN" >> .env \
&& echo "ZOHOCRM_CLIENT_ID=$ZOHOCRM_CLIENT_ID" >> .env \
&& echo "ZOHOCRM_CLIENT_SECRET=$ZOHOCRM_CLIENT_SECRET" >> .env \
&& echo "SLACK_CLIENT_ID=$SLACK_CLIENT_ID" >> .env \
&& echo "SLACK_CLIENT_SECRET=$SLACK_CLIENT_SECRET" >> .env \
&& echo "LOOPS_API_KEY=$LOOPS_API_KEY" >> .env \
&& echo "LOOPS_ONBOARDING_TXN_ID=$LOOPS_ONBOARDING_TXN_ID" >> .env \
&& echo "PIPEDRIVE_CLIENT_SECRET=$PIPEDRIVE_CLIENT_SECRET" >> .env \
&& echo "SLACK_HOOK_URL=$SLACK_HOOK_URL" >> .env \
&& echo "SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN" >> .env \
&& echo "SVIX_AUTH_TOKEN=$SVIX_AUTH_TOKEN" >> .env \
&& echo "MOESIF_APPLICATION_ID=$MOESIF_APPLICATION_ID" >> .env \
&& echo "SHORTLOOP_AUTH_KEY=$SHORTLOOP_AUTH_KEY" >> .env \
&& echo "PIPEDRIVE_CLIENT_ID=$PIPEDRIVE_CLIENT_ID" >> .env \
&& echo "DISABLE_REVERT_TELEMETRY=$DISABLE_REVERT_TELEMETRY" >> .env \
&& echo "MS_DYNAMICS_SALES_CLIENT_ID=$MS_DYNAMICS_SALES_CLIENT_ID" >> .env \
&& echo "MS_DYNAMICS_SALES_CLIENT_SECRET=$MS_DYNAMICS_SALES_CLIENT_SECRET" >> .env \
&& echo "MS_DYNAMICS_SALES_ORG_URL=$MS_DYNAMICS_SALES_ORG_URL" >> .env

RUN rm -rf node_modules && yarn cache clean && yarn install
RUN npm install -g fern-api@0.16.22 && fern -v && fern generate --log-level debug
RUN mkdir -p /app/packages/backend/dist/generated && cp -r /app/packages/backend/generated/typescript /app/packages/backend/dist/generated
RUN yarn workspace @revertdotdev/backend build

# remove development dependencies
RUN npm prune --production

FROM node:18-alpine AS runtime_image
WORKDIR /app/

#copy from build image
COPY --from=build_image /app/packages/backend/dist ./dist
COPY --from=build_image /app/node_modules ./node_modules
COPY --from=build_image /app/.env ./dist/.env

WORKDIR /app/dist
CMD ["node", "index.js"]
4 changes: 2 additions & 2 deletions packages/backend/helpers/crm/msDynamicsSales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function handleMSDynamicsSales<T extends Record<string, any>>({
2 : High
*/
if (obj.priority !== undefined && obj.priority !== null) {
let priority = null;
let priority: number | null = null;
if (obj.priority === 'low') priority = 0;
else if (obj.priority === 'normal') priority = 1;
else if (obj.priority === 'high') priority = 2;
Expand All @@ -35,7 +35,7 @@ export function handleMSDynamicsSales<T extends Record<string, any>>({
2 : Canceled
*/
if (obj.status !== undefined && obj.status !== null) {
let status = null;
let status: number | null = null;
if (obj.status === 'open') status = 0;
else if (obj.status == 'completed') status = 1;
else if (obj.status == 'canceled') status = 2;
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/helpers/crm/transform/disunify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export async function disunifyTicketObject<T extends Record<string, any>>({
}
case TP_ID.jira: {
if (objType === 'ticketTask') {
let priorityId = undefined;
let priorityId: string | undefined = undefined;
if (obj.priority === 'urgent') priorityId = '1';
else if (obj.priority === 'high') priorityId = '2';
else if (obj.priority === 'medium') priorityId = '3';
Expand Down Expand Up @@ -245,7 +245,7 @@ export async function disunifyTicketObject<T extends Record<string, any>>({
}
case TP_ID.bitbucket: {
if (objType === 'ticketTask') {
let priorityId = undefined;
let priorityId: string | undefined = undefined;
if (obj.priority === 'urgent') priorityId = 'blocker';
else if (obj.priority === 'high') priorityId = 'critical';
else if (obj.priority === 'medium') priorityId = 'major';
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/helpers/crm/transform/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const preprocessUnifyObject = <T extends Record<string, any>>({
2 : High
*/
if (obj.prioritycode !== undefined && obj.prioritycode !== null) {
let priority = null;
let priority: string | null = null;
if (obj.prioritycode === 0) priority = 'low';
else if (obj.prioritycode === 1) priority = 'normal';
else if (obj.prioritycode === 2) priority = 'high';
Expand All @@ -110,7 +110,7 @@ export const preprocessUnifyObject = <T extends Record<string, any>>({
2 : Canceled
*/
if (obj.statecode !== undefined && obj.statecode !== null) {
let status = null;
let status: string | null = null;
if (obj.statecode === 0) status = 'open';
else if (obj.statecode == 1) status = 'completed';
else if (obj.statecode == 2) status = 'canceled';
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/services/Internal/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const analyticsService = new AnalyticsService({
distinct: ['tp_id'],
});

let connectedApps = [];
let connectedApps: any = [];
connectedApps = connections.map((connection: any) => {
let appName: any;
let imageSrc: any;
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/services/ticket/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ const commentServiceTicket = new CommentService(
);

const pageInfo = comments.pageInfo;
let next_cursor = undefined;
let next_cursor: string | undefined = undefined;
if (pageInfo.hasNextPage && pageInfo.endCursor) {
next_cursor = pageInfo.endCursor;
}

let previous_cursor = undefined;
let previous_cursor: string | undefined = undefined;
if (pageInfo.hasPreviousPage && pageInfo.startCursor) {
previous_cursor = pageInfo.startCursor;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/services/ticket/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ const taskServiceTicket = new TaskService(
Authorization: `Bearer ${thirdPartyToken}`,
},
});
let transition = null;
let transition: any = null;
if (statusval === 'open') {
transition = allTransitions.data.transitions.find(
(item: any) => item.name.toLowerCase() === 'to do'
Expand Down Expand Up @@ -745,7 +745,7 @@ const taskServiceTicket = new TaskService(
Authorization: `Bearer ${thirdPartyToken}`,
},
});
let transition = null;
let transition: any = null;
if (statusval === 'open') {
transition = allTransitions.data.transitions.find(
(item: any) => item.name.toLowerCase() === 'to do'
Expand Down
8 changes: 6 additions & 2 deletions packages/backend/tests/rateLimitMiddleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Response } from 'express';
import rateLimitMiddleware from '../helpers/rateLimitMiddleware';
import { skipRateLimitRoutes } from '../helpers/utils';
import { jest, describe, expect, it, beforeEach } from '@jest/globals';

type StatusFn = (code: number) => Response;
type SendFn = (body?: any) => Response;

jest.mock('../redis/client', () => {
return {
Expand Down Expand Up @@ -31,8 +35,8 @@ describe('Rate Limit Middleware', () => {
const res = {
locals: { account: { subscription: { rate_limit: 100 }, id: 'account123' } },
} as unknown as Response;
res.status = jest.fn().mockReturnValue(res);
res.send = jest.fn().mockReturnValue(res);
res.status = jest.fn().mockReturnValue(res) as unknown as StatusFn;
res.send = jest.fn().mockReturnValue(res) as unknown as SendFn;
return res;
};
const nextFunction = jest.fn();
Expand Down
14 changes: 4 additions & 10 deletions packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
"baseUrl": ".",
"outDir": "./dist",
"target": "ES2018",
"module": "commonjs",
"lib": [
"es2016",
"es2017.object",
"es2017.string"
],
"module": "NodeNext",
"lib": ["ESNext", "es2016", "es2017.object", "es2017.string", "DOM"],
"strict": true,
"skipLibCheck": true,
"noImplicitAny": true,
Expand All @@ -27,7 +23,5 @@
"moduleResolution": "NodeNext",
"allowSyntheticDefaultImports": true
},
"exclude": [
"**/node_modules/*.d.ts"
],
}
"exclude": ["**/node_modules/*.d.ts"]
}
Loading