From dbc61b867208b0204a4e87066bd80aa683558eb0 Mon Sep 17 00:00:00 2001 From: Kyle Corbitt Date: Mon, 26 Jun 2023 14:58:01 -0700 Subject: [PATCH] attempt render deploy --- .eslintrc.cjs | 6 ++- Dockerfile | 39 +++++++++++++++++++ render.yaml | 21 ++++++++++ run-prod.sh | 9 +++++ src/codegen/export-openai-schema.ts | 5 ++- src/components/OutputsTable/OutputCell.tsx | 1 + src/server/api/routers/modelOutputs.router.ts | 3 +- 7 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 render.yaml create mode 100755 run-prod.sh diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 016e2dd..bd5e490 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -10,6 +10,10 @@ const config = { parserOptions: { project: path.join(__dirname, "tsconfig.json"), }, + rules: { + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/no-unsafe-assignment": "off", + }, }, ], parser: "@typescript-eslint/parser", @@ -27,8 +31,6 @@ const config = { }, ], "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], - "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-assignment": "off", }, }; diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75236ae --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# Adapted from https://create.t3.gg/en/deployment/docker#3-create-dockerfile + +FROM node:20.1.0-bullseye as base +RUN yarn global add pnpm + +# DEPS +FROM base as deps + +WORKDIR /app + +COPY prisma ./ + +COPY package.json pnpm-lock.yaml ./ + +RUN pnpm install --frozen-lockfile + +# BUILDER +FROM base as builder + +# Include all NEXT_PUBLIC_* env vars here +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN SKIP_ENV_VALIDATION=1 pnpm build + +# RUNNER +FROM base as runner +WORKDIR /app + +ENV NODE_ENV production +ENV NEXT_TELEMETRY_DISABLED 1 + +COPY --from=builder /app/ ./ + +EXPOSE 3000 +ENV PORT 3000 + +# Run the "run-prod.sh" script +CMD /app/run-prod.sh \ No newline at end of file diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..34643bb --- /dev/null +++ b/render.yaml @@ -0,0 +1,21 @@ +databases: + - name: prompt-lab-prod + databaseName: prompt_lab_prod + user: prompt_lab + plan: starter + +services: + - type: web + name: prompt-lab-prod-web + env: docker + dockerfilePath: Dockerfile + dockerContext: . + plan: standard + envVars: + - key: NODE_ENV + value: production + - key: DATABASE_URL + fromDatabase: + name: prompt-lab-prod + property: connectionString + - fromGroup: prompt-lab-prod diff --git a/run-prod.sh b/run-prod.sh new file mode 100755 index 0000000..1feb207 --- /dev/null +++ b/run-prod.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +set -e + +echo "Migrating the database" +pnpm prisma migrate deploy + +echo "Starting the server" +pnpm start \ No newline at end of file diff --git a/src/codegen/export-openai-schema.ts b/src/codegen/export-openai-schema.ts index 60bba8f..9fcef20 100644 --- a/src/codegen/export-openai-schema.ts +++ b/src/codegen/export-openai-schema.ts @@ -1,8 +1,11 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ + import YAML from "yaml"; import fs from "fs"; import path from "path"; import { openapiSchemaToJsonSchema } from "@openapi-contrib/openapi-schema-to-json-schema"; import assert from "assert"; +import { AcceptibleInputSchema } from "@openapi-contrib/openapi-schema-to-json-schema/dist/mjs/openapi-schema-types"; const OPENAPI_URL = "https://raw.githubusercontent.com/openai/openai-openapi/0c432eb66fd0c758fd8b9bd69db41c1096e5f4db/openapi.yaml"; @@ -13,7 +16,7 @@ const convertOpenApiToJsonSchema = async (url: string) => { const openApiYaml = await response.text(); // Parse the yaml document - const openApiDocument = YAML.parse(openApiYaml) as unknown; + const openApiDocument = YAML.parse(openApiYaml) as AcceptibleInputSchema; // Convert the openapi schema to json schema const jsonSchema = openapiSchemaToJsonSchema(openApiDocument); diff --git a/src/components/OutputsTable/OutputCell.tsx b/src/components/OutputsTable/OutputCell.tsx index 391efa3..c05e3e0 100644 --- a/src/components/OutputsTable/OutputCell.tsx +++ b/src/components/OutputsTable/OutputCell.tsx @@ -58,6 +58,7 @@ export default function OutputCell({ if (!output.data) return No output; return ( + // @ts-expect-error TODO proper typing and error checks {JSON.stringify(output.data.output.choices[0].message.content, null, 2)} ); } diff --git a/src/server/api/routers/modelOutputs.router.ts b/src/server/api/routers/modelOutputs.router.ts index cb695e5..9c496a8 100644 --- a/src/server/api/routers/modelOutputs.router.ts +++ b/src/server/api/routers/modelOutputs.router.ts @@ -5,6 +5,7 @@ import fillTemplate, { VariableMap } from "~/server/utils/fillTemplate"; import { JSONSerializable } from "~/server/types"; import { getChatCompletion } from "~/server/utils/openai"; import crypto from "crypto"; +import type { Prisma } from "@prisma/client"; export const modelOutputsRouter = createTRPCRouter({ get: publicProcedure @@ -62,7 +63,7 @@ export const modelOutputsRouter = createTRPCRouter({ data: { promptVariantId: input.variantId, testScenarioId: input.scenarioId, - output: modelResponse, + output: modelResponse as Prisma.InputJsonObject, inputHash, }, });