Skip to content

Commit

Permalink
[Backend]: Fixed Insights build issues and Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mirai2k authored Sep 4, 2024
1 parent b2f8eae commit 731aa76
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 55 deletions.
2 changes: 1 addition & 1 deletion apps/auth-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine3.16 as base
FROM node:20-alpine3.16 AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
Expand Down
6 changes: 3 additions & 3 deletions apps/auth-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codemod-com/auth-service",
"version": "0.0.17",
"version": "0.0.18",
"scripts": {
"build": "tsc && node esbuild.config.js",
"start": "node build/index.js"
Expand All @@ -21,11 +21,11 @@
"tsx": "^4.7.1"
},
"dependencies": {
"@clerk/backend": "catalog:",
"@clerk/fastify": "catalog:",
"@codemod-com/auth": "workspace:*",
"@codemod-com/database": "workspace:*",
"@codemod-com/utilities": "workspace:*",
"@clerk/backend": "catalog:",
"@clerk/fastify": "catalog:",
"@fastify/busboy": "catalog:",
"@fastify/cors": "catalog:",
"@fastify/rate-limit": "catalog:",
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine3.16 as base
FROM node:20-alpine3.16 AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codemod-com/backend",
"version": "0.0.160",
"version": "0.0.161",
"imports": {
"#*": "./src/*"
},
Expand Down Expand Up @@ -34,12 +34,12 @@
"vitest": "1.1.0"
},
"dependencies": {
"@aws-sdk/client-s3": "catalog:",
"@aws-sdk/s3-request-presigner": "catalog:",
"@codemod-com/auth": "workspace:*",
"@codemod-com/database": "workspace:*",
"@codemod-com/runner": "workspace:*",
"@codemod-com/utilities": "workspace:*",
"@aws-sdk/client-s3": "catalog:",
"@aws-sdk/s3-request-presigner": "catalog:",
"@fastify/busboy": "catalog:",
"@fastify/cors": "catalog:",
"@fastify/multipart": "catalog:",
Expand Down
7 changes: 5 additions & 2 deletions apps/backend/src/handlers/insights/insight-new.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { ApiResponse, CodemodRunResponse } from "@codemod-com/api-types";
import { parsePostInsightBody } from "@codemod-com/api-types";
import type { ApiResponse } from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import { type Insight, prisma } from "@codemod-com/database";
import {
type CodemodRunResponse,
parsePostInsightBody,
} from "@codemod-com/utilities";
import axios from "axios";
import type { FastifyReply, RouteHandler } from "fastify";
import { environment } from "#util.js";
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/handlers/insights/insight.put.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
type ApiResponse,
type CodemodRunResponse,
parsePutInsightBody,
} from "@codemod-com/api-types";
import type { ApiResponse } from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import { prisma } from "@codemod-com/database";
import type { Insight } from "@codemod-com/database";
import {
type CodemodRunResponse,
parsePutInsightBody,
} from "@codemod-com/utilities";
import axios from "axios";
import type { FastifyReply, RouteHandler } from "fastify";
import { environment } from "#util.js";
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/handlers/widgets/widget.put.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type ApiResponse, parsePutWidgetBody } from "@codemod-com/api-types";
import type { ApiResponse } from "@codemod-com/api-types";
import type { UserDataPopulatedRequest } from "@codemod-com/auth";
import { prisma } from "@codemod-com/database";
import type { Widget } from "@codemod-com/database";
import { parsePutWidgetBody } from "@codemod-com/utilities";
import type { FastifyReply, RouteHandler } from "fastify";

export type PutWidgetResponse = ApiResponse<Widget>;
Expand Down
66 changes: 46 additions & 20 deletions apps/run-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
FROM node:20-alpine3.16 as builder
FROM node:20-alpine3.16 AS base

WORKDIR /app
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN npm install -g pnpm
RUN npm install -g pnpm@latest
RUN pnpm -g add turbo@^1

COPY ./package.json ./turbo.json ./pnpm-workspace.yaml ./pnpm-lock.yaml /app/
COPY ./apps/run-service/package.json /app/apps/run-service/

COPY ./packages/tsconfig /app/packages/tsconfig/
COPY ./packages/utilities /app/packages/utilities/
COPY ./packages/filemod /app/packages/filemod/

RUN pnpm install
FROM base AS builder
WORKDIR /app

COPY ./apps/run-service/tsconfig.json /app/apps/run-service/
COPY ./apps/run-service/esbuild.config.js /app/apps/run-service/
COPY ./apps/run-service/src /app/apps/run-service/src/
RUN apk update
RUN apk add --no-cache libc6-compat

RUN pnpm build --filter @codemod-com/utilities --filter @codemod-com/run-service
COPY package.json turbo.json pnpm-workspace.yaml pnpm-lock.yaml /app/
COPY apps/run-service /app/apps/run-service/

FROM node:20-alpine3.16
COPY packages/tsconfig /app/packages/tsconfig/
COPY packages/utilities /app/packages/utilities/
COPY packages/filemod /app/packages/filemod/
COPY packages/telemetry /app/packages/telemetry/
COPY packages/database /app/packages/database/
COPY packages/runner /app/packages/runner/
COPY packages/printer /app/packages/printer/
COPY packages/workflow /app/packages/workflow/
COPY packages/api-types /app/packages/api-types/
COPY packages/codemod-utils /app/packages/codemod-utils/
COPY packages/auth /app/packages/auth/

RUN npm install -g pnpm
RUN turbo prune @codemod-com/run-service --docker



FROM base AS installer
WORKDIR /app

COPY --from=builder /app/apps/run-service/package.json /app
COPY --from=builder /app/apps/run-service/build /app/build
COPY --from=builder /app/packages /app/packages
RUN apk update
RUN apk add --no-cache libc6-compat

# First install the dependencies (as they change less often)
COPY --from=builder /app/out/json/ .
RUN pnpm install

# Build the project
COPY --from=builder /app/out/full/ .
RUN pnpm build --filter @codemod-com/run-service


EXPOSE 8086

CMD node build/index.js
FROM base AS runner
# Copy stuff for prisma to work
COPY --from=installer /app/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/ ./node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/

WORKDIR /app
COPY --from=installer /app/apps/run-service ./apps/run-service
COPY --from=installer /app/packages/database ./packages/database

CMD cd packages/database && pnpm dlx prisma@latest migrate deploy && cd - && node apps/run-service/build/index.js
4 changes: 2 additions & 2 deletions apps/run-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codemod-com/run-service",
"version": "0.0.4",
"version": "0.0.5",
"scripts": {
"build": "tsc && node esbuild.config.js",
"start": "node build/index.js",
Expand All @@ -9,6 +9,7 @@
"author": "Codemod inc.",
"private": true,
"devDependencies": {
"@codemod-com/api-types": "workspace:*",
"@codemod-com/tsconfig": "workspace:*",
"@types/node": "20.10.5",
"@types/parse-github-url": "catalog:",
Expand All @@ -20,7 +21,6 @@
"tsx": "^4.7.1"
},
"dependencies": {
"@codemod-com/api-types": "workspace:*",
"@codemod-com/auth": "workspace:*",
"@codemod-com/database": "workspace:*",
"@codemod-com/utilities": "workspace:*",
Expand Down
3 changes: 1 addition & 2 deletions apps/run-service/src/schemata/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {
codemodRunBodySchema,
codemodRunStatusSchema,
validateCodemodStatusParamsSchema,
} from "@codemod-com/api-types";

} from "@codemod-com/utilities";
import { parse } from "valibot";

export const parseCodemodRunBody = (input: unknown) =>
Expand Down
15 changes: 7 additions & 8 deletions apps/run-service/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import fastifyMultipart from "@fastify/multipart";
import fastifyRateLimit from "@fastify/rate-limit";
import Fastify, { type FastifyPluginCallback } from "fastify";

import {
type ApiResponse,
type CodemodRunJobData,
type CodemodRunResponse,
type CodemodRunStatus,
type CodemodRunStatusResponse,
UNAUTHORIZED,
} from "@codemod-com/api-types";
import { type ApiResponse, UNAUTHORIZED } from "@codemod-com/api-types";
import {
type UserDataPopulatedRequest,
getAuthPlugin,
} from "@codemod-com/auth";
import { prisma } from "@codemod-com/database";
import type {
CodemodRunJobData,
CodemodRunResponse,
CodemodRunStatus,
CodemodRunStatusResponse,
} from "@codemod-com/utilities";
import {
parseCodemodRunBody,
parseCodemodStatusData,
Expand Down
2 changes: 1 addition & 1 deletion apps/run-service/src/services/Redis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CodemodRunJobData } from "@codemod-com/api-types";
import type { CodemodRunJobData } from "@codemod-com/utilities";
import { Queue } from "bullmq";
import { Redis } from "ioredis";
import { environment } from "../util.js";
Expand Down
1 change: 1 addition & 0 deletions packages/api-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@clerk/backend": "catalog:",
"@codemod-com/database": "workspace:*",
"@codemod-com/filemod": "workspace:*"
}
}
2 changes: 0 additions & 2 deletions packages/api-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export * from "./campaign.js";
export * from "./clerk.js";
export * from "./codemod-run.js";
export * from "./errors.js";
export * from "./github.js";
export * from "./insights.js";
export * from "./responses.js";
1 change: 0 additions & 1 deletion packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"devDependencies": {
"@codemod-com/utilities": "workspace:*",
"@codemod-com/api-types": "workspace:*",
"@faker-js/faker": "catalog:",
"prisma": "catalog:",
"tsx": "^4.11.0"
Expand Down
8 changes: 5 additions & 3 deletions packages/database/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { CodemodRunStatus } from "@codemod-com/api-types/src/codemod-run.js";
import type { WidgetData as WidgetDataInput } from "@codemod-com/api-types/src/insights.js";
import type { CodemodConfig } from "@codemod-com/utilities";
import type {
CodemodConfig,
CodemodRunStatus,
WidgetData as WidgetDataInput,
} from "@codemod-com/utilities";
import { PrismaClient } from "@prisma/client";

declare global {
Expand Down
2 changes: 2 additions & 0 deletions packages/utilities/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export * from "./schemata/codemod-config.js";
export * from "./schemata/codemod.js";
export * from "./schemata/engine-options.js";
export * from "./schemata/file-commands.js";
export * from "./schemata/codemod-run.js";
export * from "./schemata/insights.js";
File renamed without changes.
File renamed without changes.

0 comments on commit 731aa76

Please sign in to comment.