diff --git a/apps/auth-service/Dockerfile b/apps/auth-service/Dockerfile index ea3bbf94d..f55a2c718 100644 --- a/apps/auth-service/Dockerfile +++ b/apps/auth-service/Dockerfile @@ -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" diff --git a/apps/auth-service/package.json b/apps/auth-service/package.json index 0d2c2a132..26f07c82b 100644 --- a/apps/auth-service/package.json +++ b/apps/auth-service/package.json @@ -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" @@ -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:", diff --git a/apps/backend/Dockerfile b/apps/backend/Dockerfile index eddd87484..b5bf61dc8 100644 --- a/apps/backend/Dockerfile +++ b/apps/backend/Dockerfile @@ -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" diff --git a/apps/backend/package.json b/apps/backend/package.json index d0062d427..a09c4e853 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -1,6 +1,6 @@ { "name": "@codemod-com/backend", - "version": "0.0.160", + "version": "0.0.161", "imports": { "#*": "./src/*" }, @@ -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:", diff --git a/apps/backend/src/handlers/insights/insight-new.post.ts b/apps/backend/src/handlers/insights/insight-new.post.ts index ebfc54fbd..80d7442c4 100644 --- a/apps/backend/src/handlers/insights/insight-new.post.ts +++ b/apps/backend/src/handlers/insights/insight-new.post.ts @@ -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"; diff --git a/apps/backend/src/handlers/insights/insight.put.ts b/apps/backend/src/handlers/insights/insight.put.ts index cd492c7c8..981cc475c 100644 --- a/apps/backend/src/handlers/insights/insight.put.ts +++ b/apps/backend/src/handlers/insights/insight.put.ts @@ -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"; diff --git a/apps/backend/src/handlers/widgets/widget.put.ts b/apps/backend/src/handlers/widgets/widget.put.ts index bc0bdd445..eec05cf9c 100644 --- a/apps/backend/src/handlers/widgets/widget.put.ts +++ b/apps/backend/src/handlers/widgets/widget.put.ts @@ -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; diff --git a/apps/run-service/Dockerfile b/apps/run-service/Dockerfile index df8bcf17c..5c1404d71 100644 --- a/apps/run-service/Dockerfile +++ b/apps/run-service/Dockerfile @@ -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/@prisma+client@5.15.1_prisma@5.15.1/node_modules/.prisma/ ./node_modules/.pnpm/@prisma+client@5.15.1_prisma@5.15.1/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 diff --git a/apps/run-service/package.json b/apps/run-service/package.json index 823e2d460..1a6ed6613 100644 --- a/apps/run-service/package.json +++ b/apps/run-service/package.json @@ -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", @@ -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:", @@ -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:*", diff --git a/apps/run-service/src/schemata/schema.ts b/apps/run-service/src/schemata/schema.ts index 99ccaf79b..72648ab4e 100644 --- a/apps/run-service/src/schemata/schema.ts +++ b/apps/run-service/src/schemata/schema.ts @@ -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) => diff --git a/apps/run-service/src/server.ts b/apps/run-service/src/server.ts index d6eed09de..b377475b5 100644 --- a/apps/run-service/src/server.ts +++ b/apps/run-service/src/server.ts @@ -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, diff --git a/apps/run-service/src/services/Redis.ts b/apps/run-service/src/services/Redis.ts index 06ebe710c..134dd26ff 100644 --- a/apps/run-service/src/services/Redis.ts +++ b/apps/run-service/src/services/Redis.ts @@ -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"; diff --git a/packages/api-types/package.json b/packages/api-types/package.json index af4cd422e..934227bbd 100644 --- a/packages/api-types/package.json +++ b/packages/api-types/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@clerk/backend": "catalog:", + "@codemod-com/database": "workspace:*", "@codemod-com/filemod": "workspace:*" } } diff --git a/packages/api-types/src/index.ts b/packages/api-types/src/index.ts index 8e9eaefee..8b3f4b04d 100644 --- a/packages/api-types/src/index.ts +++ b/packages/api-types/src/index.ts @@ -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"; diff --git a/packages/database/package.json b/packages/database/package.json index 71f3ea217..76eee9c65 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -25,7 +25,6 @@ }, "devDependencies": { "@codemod-com/utilities": "workspace:*", - "@codemod-com/api-types": "workspace:*", "@faker-js/faker": "catalog:", "prisma": "catalog:", "tsx": "^4.11.0" diff --git a/packages/database/src/index.ts b/packages/database/src/index.ts index 6b4ace00b..3972480db 100644 --- a/packages/database/src/index.ts +++ b/packages/database/src/index.ts @@ -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 { diff --git a/packages/utilities/src/index.ts b/packages/utilities/src/index.ts index 589e9ab4c..c5a0fdbb9 100644 --- a/packages/utilities/src/index.ts +++ b/packages/utilities/src/index.ts @@ -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"; diff --git a/packages/api-types/src/codemod-run.ts b/packages/utilities/src/schemata/codemod-run.ts similarity index 100% rename from packages/api-types/src/codemod-run.ts rename to packages/utilities/src/schemata/codemod-run.ts diff --git a/packages/api-types/src/insights.ts b/packages/utilities/src/schemata/insights.ts similarity index 100% rename from packages/api-types/src/insights.ts rename to packages/utilities/src/schemata/insights.ts