From c95ca8fc7e297711d7a90f81cf77c851a2824fad Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Sun, 29 Oct 2023 14:28:00 +0800 Subject: [PATCH 01/23] init --- .dockerignore | 11 ++++-- Dockerfile | 66 +++++++++++++++++++++++++++++++++++ next.config.mjs | 13 +++++++ prisma/mongodb/schema.prisma | 1 + prisma/postgres/schema.prisma | 1 + src/env.mjs | 26 +++++++------- 6 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore index 04a99a2..dd02b1b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,8 @@ -/node_modules -/.next -/npm-debug.log \ No newline at end of file +.env +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b80fa18 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +# Dockerfile + +##### DEPENDENCIES + +FROM node:18-alpine AS deps +RUN apk add --no-cache libc6-compat openssl1.1-compat +WORKDIR /app + +# Install Prisma Client - remove if not using Prisma +COPY prisma ./prisma + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml\* ./ + +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ + else echo "Lockfile not found." && exit 1; \ + fi + +##### BUILDER + +FROM node:18-alpine AS builder + +# ARG DATABASE_URL + +ARG NEXTAUTH_URL +ARG NEXT_PUBLIC_WS_PORT + +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN \ + if [ -f yarn.lock ]; then SKIP_ENV_VALIDATION=1 yarn build; \ + elif [ -f package-lock.json ]; then SKIP_ENV_VALIDATION=1 npm run build; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && SKIP_ENV_VALIDATION=1 pnpm run build; \ + else echo "Lockfile not found." && exit 1; \ + fi + +##### RUNNER + +FROM node:18-alpine AS runner +WORKDIR /app + +ENV NODE_ENV production +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/next.config.mjs ./ +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs +EXPOSE 3000 +ENV PORT 3000 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 3b26405..ab4c2a1 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -28,6 +28,19 @@ const config = { locales: ["en"], defaultLocale: "en", }, + typescript: { + // !! WARN !! + // Dangerously allow production builds to successfully complete even if + // your project has type errors. + // !! WARN !! + ignoreBuildErrors: true, + }, + eslint: { + // Warning: This allows production builds to successfully complete even if + // your project has ESLint errors. + ignoreDuringBuilds: true, + }, + output: "standalone", }; export default config; diff --git a/prisma/mongodb/schema.prisma b/prisma/mongodb/schema.prisma index a79922e..139e32e 100644 --- a/prisma/mongodb/schema.prisma +++ b/prisma/mongodb/schema.prisma @@ -4,6 +4,7 @@ generator client { provider = "prisma-client-js" output = "../../node_modules/@prisma-db-mongo/client" + binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db { diff --git a/prisma/postgres/schema.prisma b/prisma/postgres/schema.prisma index a18a115..e5817b3 100644 --- a/prisma/postgres/schema.prisma +++ b/prisma/postgres/schema.prisma @@ -4,6 +4,7 @@ generator client { provider = "prisma-client-js" output = "../../node_modules/@prisma-db-psql/client" + binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db { diff --git a/src/env.mjs b/src/env.mjs index 3a2fc2b..57ca9fe 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -7,12 +7,12 @@ export const env = createEnv({ * isn't built with invalid env vars. */ server: { - POSTGRES_USER: z.string().min(1), - POSTGRES_PASSWORD: z.string().min(1), - POSTGRES_URL: z.string().url(), - MONGO_USER: z.string().min(1), - MONGO_PASSWORD: z.string().min(1), - MONGO_URL: z.string().url(), + // POSTGRES_USER: z.string().min(1), + // POSTGRES_PASSWORD: z.string().min(1), + // POSTGRES_URL: z.string().url(), + // MONGO_USER: z.string().min(1), + // MONGO_PASSWORD: z.string().min(1), + // MONGO_URL: z.string().url(), NODE_ENV: z.enum(["development", "test", "production"]), NEXTAUTH_SECRET: process.env.NODE_ENV === "production" @@ -46,14 +46,14 @@ export const env = createEnv({ * middlewares) or client-side so we need to destruct manually. */ runtimeEnv: { - POSTGRES_USER: process.env.POSTGRES_USER, - POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD, - POSTGRES_URL: process.env.POSTGRES_URL, - MONGO_USER: process.env.MONGO_USER, - MONGO_PASSWORD: process.env.MONGO_PASSWORD, - MONGO_URL: process.env.MONGO_URL, + // POSTGRES_USER: process.env.POSTGRES_USER, + // POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD, + // POSTGRES_URL: process.env.POSTGRES_URL, + // MONGO_USER: process.env.MONGO_USER, + // MONGO_PASSWORD: process.env.MONGO_PASSWORD, + // MONGO_URL: process.env.MONGO_URL, NODE_ENV: process.env.NODE_ENV, - NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, + NEXTAUTH_SECRET: process.env.NEXT_AUTH_SECRET, NEXT_PUBLIC_WS_PORT: process.env.NODE_ENV === "production" ? process.env.NEXT_PUBLIC_WS_PORT : "3002", NEXTAUTH_URL: process.env.NEXTAUTH_URL, S3_BUCKET_NAME: process.env.S3_BUCKET_NAME, From f1506db76ac88a4fb3d464786298637b2130deb1 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 15:16:09 +0800 Subject: [PATCH 02/23] fix url issues --- Dockerfile | 2 -- README.md | 7 +++++++ src/env.mjs | 8 +------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b80fa18..8204f2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,8 +24,6 @@ RUN \ FROM node:18-alpine AS builder # ARG DATABASE_URL - -ARG NEXTAUTH_URL ARG NEXT_PUBLIC_WS_PORT WORKDIR /app diff --git a/README.md b/README.md index 3d802f3..d728b0f 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,13 @@ Notes: - If postgres is running on 5432, kill the process `sudo pkill -u postgres` - If you have trouble starting the `judge0` container, or encounter `Incorrect type. Expected "include".` in `compose.yml`, try updating `docker-compose` to `v2.20` (Docker Desktop `4.42.1`) or later. +## Building and Running Image + +```bash + docker build -t peer-prep --build-arg NEXT_PUBLIC_WS_PORT=3002 . + docker run --env-file ./.env -e NODE_ENV=production -e PORT=3000 -p 3000:3000 peer-prep +``` + ## What's next? How do I make an app with this? We try to keep this project as simple as possible, so you can start with just the scaffolding we set up for you, and add additional things later when they become necessary. diff --git a/src/env.mjs b/src/env.mjs index 57ca9fe..6cd39f9 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -18,13 +18,7 @@ export const env = createEnv({ process.env.NODE_ENV === "production" ? z.string().min(1) : z.string().min(1).optional(), - NEXTAUTH_URL: z.preprocess( - // This makes Vercel deployments not fail if you don't set NEXTAUTH_URL - // Since NextAuth.js automatically uses the VERCEL_URL if present. - (str) => process.env.VERCEL_URL ?? str, - // VERCEL_URL doesn't include `https` so it cant be validated as a URL - process.env.VERCEL ? z.string().min(1) : z.string().url(), - ), + NEXTAUTH_URL: z.string().min(1), S3_BUCKET_NAME: z.string().min(1), // Add `.min(1) on ID and SECRET if you want to make sure they're not empty GITHUB_ID: z.string().min(1), From 5eb5074486e9ec0407bf5c3adcf97b434b429fdd Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 16:49:26 +0800 Subject: [PATCH 03/23] simpl --- .dockerignore | 3 +++ Dockerfile | 30 ++---------------------------- next.config.mjs | 1 - 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/.dockerignore b/.dockerignore index dd02b1b..1b45fc4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,7 @@ node_modules npm-debug.log README.md .next +.server +data +judge0-* .git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8204f2c..4f8a4cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,10 @@ # Dockerfile -##### DEPENDENCIES - FROM node:18-alpine AS deps RUN apk add --no-cache libc6-compat openssl1.1-compat WORKDIR /app -# Install Prisma Client - remove if not using Prisma -COPY prisma ./prisma - -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml\* ./ +COPY . . RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ @@ -19,17 +13,9 @@ RUN \ else echo "Lockfile not found." && exit 1; \ fi -##### BUILDER - -FROM node:18-alpine AS builder - # ARG DATABASE_URL ARG NEXT_PUBLIC_WS_PORT -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . - ENV NEXT_TELEMETRY_DISABLED 1 RUN \ @@ -39,26 +25,14 @@ RUN \ else echo "Lockfile not found." && exit 1; \ fi -##### RUNNER - -FROM node:18-alpine AS runner -WORKDIR /app - ENV NODE_ENV production ENV NEXT_TELEMETRY_DISABLED 1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -COPY --from=builder /app/next.config.mjs ./ -COPY --from=builder /app/public ./public -COPY --from=builder /app/package.json ./package.json - -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - USER nextjs EXPOSE 3000 ENV PORT 3000 -CMD ["node", "server.js"] \ No newline at end of file +CMD ["yarn", "start"] \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index ab4c2a1..432b9cf 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -40,7 +40,6 @@ const config = { // your project has ESLint errors. ignoreDuringBuilds: true, }, - output: "standalone", }; export default config; From 480f4cff0c36571b0db83a07ee9df5fe5688f679 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 17:45:51 +0800 Subject: [PATCH 04/23] p1 --- .dockerignore | 1 - Dockerfile | 2 +- README.md | 2 +- compose.yml | 10 ++++++++++ src/env.mjs | 24 ++++++++++++------------ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1b45fc4..ea76ab4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -.env Dockerfile .dockerignore node_modules diff --git a/Dockerfile b/Dockerfile index 4f8a4cb..dad3964 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN \ fi # ARG DATABASE_URL -ARG NEXT_PUBLIC_WS_PORT +# ARG NEXT_PUBLIC_WS_PORT ENV NEXT_TELEMETRY_DISABLED 1 diff --git a/README.md b/README.md index d728b0f..19a0eca 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Notes: ```bash docker build -t peer-prep --build-arg NEXT_PUBLIC_WS_PORT=3002 . - docker run --env-file ./.env -e NODE_ENV=production -e PORT=3000 -p 3000:3000 peer-prep + docker run -p 3000:3000 -p 3002:3002 peer-prep ``` ## What's next? How do I make an app with this? diff --git a/compose.yml b/compose.yml index 6972d9c..04c5949 100644 --- a/compose.yml +++ b/compose.yml @@ -1,6 +1,16 @@ include: - judge0-v1.13.0/docker-compose.yml services: + # app: + # platform: "linux/amd64" + # build: + # context: . + # dockerfile: Dockerfile + # working_dir: /app + # ports: + # - "3000:3000" + # - "3002:3002" + # image: t3-app postgres_db: image: postgres:12.16 container_name: postgresdb-dev diff --git a/src/env.mjs b/src/env.mjs index 6cd39f9..ff6a973 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -7,12 +7,12 @@ export const env = createEnv({ * isn't built with invalid env vars. */ server: { - // POSTGRES_USER: z.string().min(1), - // POSTGRES_PASSWORD: z.string().min(1), - // POSTGRES_URL: z.string().url(), - // MONGO_USER: z.string().min(1), - // MONGO_PASSWORD: z.string().min(1), - // MONGO_URL: z.string().url(), + POSTGRES_USER: z.string().min(1), + POSTGRES_PASSWORD: z.string().min(1), + POSTGRES_URL: z.string().url(), + MONGO_USER: z.string().min(1), + MONGO_PASSWORD: z.string().min(1), + MONGO_URL: z.string().url(), NODE_ENV: z.enum(["development", "test", "production"]), NEXTAUTH_SECRET: process.env.NODE_ENV === "production" @@ -40,12 +40,12 @@ export const env = createEnv({ * middlewares) or client-side so we need to destruct manually. */ runtimeEnv: { - // POSTGRES_USER: process.env.POSTGRES_USER, - // POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD, - // POSTGRES_URL: process.env.POSTGRES_URL, - // MONGO_USER: process.env.MONGO_USER, - // MONGO_PASSWORD: process.env.MONGO_PASSWORD, - // MONGO_URL: process.env.MONGO_URL, + POSTGRES_USER: process.env.POSTGRES_USER, + POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD, + POSTGRES_URL: process.env.POSTGRES_URL, + MONGO_USER: process.env.MONGO_USER, + MONGO_PASSWORD: process.env.MONGO_PASSWORD, + MONGO_URL: process.env.MONGO_URL, NODE_ENV: process.env.NODE_ENV, NEXTAUTH_SECRET: process.env.NEXT_AUTH_SECRET, NEXT_PUBLIC_WS_PORT: process.env.NODE_ENV === "production" ? process.env.NEXT_PUBLIC_WS_PORT : "3002", From 53ee024bcab6b722a3fd37798ccd47d5d7cbfe55 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 17:55:36 +0800 Subject: [PATCH 05/23] compose --- compose.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compose.yml b/compose.yml index 04c5949..4c36f30 100644 --- a/compose.yml +++ b/compose.yml @@ -1,16 +1,17 @@ include: - judge0-v1.13.0/docker-compose.yml services: - # app: - # platform: "linux/amd64" - # build: - # context: . - # dockerfile: Dockerfile - # working_dir: /app - # ports: - # - "3000:3000" - # - "3002:3002" - # image: t3-app + app: + platform: "linux/amd64" + build: + context: . + dockerfile: Dockerfile + working_dir: /app + ports: + - "3000:3000" + - "3002:3002" + image: t3-app + network_mode: host postgres_db: image: postgres:12.16 container_name: postgresdb-dev From 793e997dbc9927d33989a6172be07350e62adf2f Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 18:17:09 +0800 Subject: [PATCH 06/23] new s3 endpoint --- .env.example | 1 + compose.yml | 1 - src/env.mjs | 2 ++ src/server/api/routers/form.ts | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 04f13da..ecab9c2 100644 --- a/.env.example +++ b/.env.example @@ -36,6 +36,7 @@ NEXTAUTH_URL="http://localhost:${PORT}" # S3 S3_BUCKET_NAME=s3 +S3_ENDPOINT="http://localhost:9000" # Github OAuth Provider GITHUB_ID=EXAMPLE_GITHUB_ID diff --git a/compose.yml b/compose.yml index 4c36f30..657b582 100644 --- a/compose.yml +++ b/compose.yml @@ -11,7 +11,6 @@ services: - "3000:3000" - "3002:3002" image: t3-app - network_mode: host postgres_db: image: postgres:12.16 container_name: postgresdb-dev diff --git a/src/env.mjs b/src/env.mjs index ff6a973..1f0b789 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -20,6 +20,7 @@ export const env = createEnv({ : z.string().min(1).optional(), NEXTAUTH_URL: z.string().min(1), S3_BUCKET_NAME: z.string().min(1), + S3_ENDPOINT: z.string().min(1), // Add `.min(1) on ID and SECRET if you want to make sure they're not empty GITHUB_ID: z.string().min(1), GITHUB_SECRET: z.string().min(1), @@ -51,6 +52,7 @@ export const env = createEnv({ NEXT_PUBLIC_WS_PORT: process.env.NODE_ENV === "production" ? process.env.NEXT_PUBLIC_WS_PORT : "3002", NEXTAUTH_URL: process.env.NEXTAUTH_URL, S3_BUCKET_NAME: process.env.S3_BUCKET_NAME, + S3_ENDPOINT: process.env.S3_ENDPOINT, GITHUB_ID: process.env.GITHUB_ID, GITHUB_SECRET: process.env.GITHUB_SECRET, }, diff --git a/src/server/api/routers/form.ts b/src/server/api/routers/form.ts index fd9b8da..608e66a 100644 --- a/src/server/api/routers/form.ts +++ b/src/server/api/routers/form.ts @@ -8,7 +8,7 @@ const UPLOAD_MAX_FILE_SIZE = 400000; const s3Client = new S3Client({ region: "us-east-1", - endpoint: "http://localhost:9000", + endpoint: env.S3_ENDPOINT, forcePathStyle: true, credentials: { accessKeyId: "S3RVER", From 61c3248462c859b8b39fb7cdcfd303620eed2547 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 20:11:28 +0800 Subject: [PATCH 07/23] networking --- compose.yml | 12 +++++++++++- judge0-v1.13.0/docker-compose.yml | 2 +- src/env.mjs | 2 ++ src/server/api/routers/answer.ts | 20 ++++++++++---------- src/server/api/routers/judge.ts | 9 +++++---- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/compose.yml b/compose.yml index 657b582..9b3aded 100644 --- a/compose.yml +++ b/compose.yml @@ -11,6 +11,8 @@ services: - "3000:3000" - "3002:3002" image: t3-app + networks: + - network1 postgres_db: image: postgres:12.16 container_name: postgresdb-dev @@ -23,6 +25,8 @@ services: - "5432:5432" volumes: - ./data/postgres:/var/lib/postgresql/data + networks: + - network1 mongo_db: image: mongo:7.0.0 container_name: mongodb-dev @@ -37,6 +41,8 @@ services: - ./data/mongo:/data/db - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js # - ./.docker/mongo/replica.key:/data/replica.key + networks: + - network1 s3-bucket: build: ./s3/ restart: always @@ -46,6 +52,8 @@ services: S3_BUCKET_NAME: ${S3_BUCKET_NAME} volumes: - "./data/s3:/home/app/public/peer-prep" + networks: + - network1 rabbitmq: image: rabbitmq:3.11.23-management-alpine restart: always @@ -58,9 +66,11 @@ services: RABBITMQ_DEFAULT_USER: guest RABBITMQ_DEFAULT_PASS: guest command: sh -c "rabbitmq-plugins enable rabbitmq_web_stomp && rabbitmq-server" - networks: - rabbitmq_go_net + - network1 networks: rabbitmq_go_net: driver: bridge + network1: + driver: bridge diff --git a/judge0-v1.13.0/docker-compose.yml b/judge0-v1.13.0/docker-compose.yml index d1a78d4..6a57db0 100644 --- a/judge0-v1.13.0/docker-compose.yml +++ b/judge0-v1.13.0/docker-compose.yml @@ -8,7 +8,7 @@ x-logging: max-size: 100m services: - server: + j0-server: image: judge0/judge0:1.13.0 volumes: - ./judge0.conf:/judge0.conf:ro diff --git a/src/env.mjs b/src/env.mjs index 1f0b789..bba4e29 100644 --- a/src/env.mjs +++ b/src/env.mjs @@ -21,6 +21,7 @@ export const env = createEnv({ NEXTAUTH_URL: z.string().min(1), S3_BUCKET_NAME: z.string().min(1), S3_ENDPOINT: z.string().min(1), + J0_URL: z.string().min(1), // Add `.min(1) on ID and SECRET if you want to make sure they're not empty GITHUB_ID: z.string().min(1), GITHUB_SECRET: z.string().min(1), @@ -53,6 +54,7 @@ export const env = createEnv({ NEXTAUTH_URL: process.env.NEXTAUTH_URL, S3_BUCKET_NAME: process.env.S3_BUCKET_NAME, S3_ENDPOINT: process.env.S3_ENDPOINT, + J0_URL: process.env.J0_URL, GITHUB_ID: process.env.GITHUB_ID, GITHUB_SECRET: process.env.GITHUB_SECRET, }, diff --git a/src/server/api/routers/answer.ts b/src/server/api/routers/answer.ts index e758a7d..44b4b16 100644 --- a/src/server/api/routers/answer.ts +++ b/src/server/api/routers/answer.ts @@ -1,18 +1,18 @@ +import type { Answer } from "@prisma-db-mongo/client"; +import type { AnswerResult } from "@prisma-db-psql/client"; +import { TRPCError } from "@trpc/server"; +import axios from "axios"; +import { type Session } from "next-auth"; import { z } from "zod"; -import { createTRPCRouter, protectedProcedure } from "../trpc"; import { - PrismaMongoT, + type PrismaMongoT, + type PrismaPostgresT, prismaMongo, prismaPostgres, - PrismaPostgresT, } from "~/server/db"; -import type { AnswerResult } from "@prisma-db-psql/client"; -import type { Answer } from "@prisma-db-mongo/client"; -import { TRPCError } from "@trpc/server"; import { appRouter } from "../root"; -import { Session } from "next-auth"; -import { api } from "~/utils/api"; -import axios from "axios"; +import { createTRPCRouter, protectedProcedure } from "../trpc"; +import { env as penv } from "~/env.mjs"; const createAnswerInput = z.object({ body: z.string(), @@ -80,7 +80,7 @@ const answerRouter = createTRPCRouter({ }); const languages = await axios - .get("http://localhost:2358/languages") + .get(`${penv.J0_URL}:2358/languages`) .then((res) => { return res.data as { id: number; name: string }[]; }); diff --git a/src/server/api/routers/judge.ts b/src/server/api/routers/judge.ts index 40f7171..aab5c39 100644 --- a/src/server/api/routers/judge.ts +++ b/src/server/api/routers/judge.ts @@ -6,6 +6,7 @@ import { protectedProcedure, publicProcedure, } from "../trpc"; +import { env } from "~/env.mjs"; // TODO: Multifile @@ -43,7 +44,7 @@ const executionObject = z.object({ export const judgeRouter = createTRPCRouter({ getLanguages: maintainerProcedure.query(async () => { - return axios.get("http://localhost:2358/languages").then((res) => { + return axios.get(`${env.J0_URL}:2358/languages`).then((res) => { return res.data as Language[]; }); }), @@ -52,7 +53,7 @@ export const judgeRouter = createTRPCRouter({ .query(async ({ input }) => { const languageIdSet = new Set(); input.languages.forEach((val) => languageIdSet.add(val)); - return axios.get("http://localhost:2358/languages").then((res) => { + return axios.get(`${env.J0_URL}:2358/languages`).then((res) => { return (res.data as Language[]).filter((value) => languageIdSet.has(value.id)); }); }), @@ -61,7 +62,7 @@ export const judgeRouter = createTRPCRouter({ .mutation(async ({ input }) => { return axios .post( - "http://localhost:2358/submissions/?base64_encoded=false&wait=true", + `${env.J0_URL}:2358/submissions/?base64_encoded=false&wait=true`, input, ) .then((res) => { @@ -101,7 +102,7 @@ export const judgeRouter = createTRPCRouter({ }; return axios .post( - "http://localhost:2358/submissions/?base64_encoded=false&wait=true", + `${env.J0_URL}:2358/submissions/?base64_encoded=false&wait=true`, newInput, ) .then((res) => { From 16417428d2c346bb459079448dececafbc375c5e Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 20:21:18 +0800 Subject: [PATCH 08/23] env example --- .env.example | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.env.example b/.env.example index ecab9c2..4973a9c 100644 --- a/.env.example +++ b/.env.example @@ -38,6 +38,9 @@ NEXTAUTH_URL="http://localhost:${PORT}" S3_BUCKET_NAME=s3 S3_ENDPOINT="http://localhost:9000" +# JUDGE0 +J0_URL="http://j0-server:2358" + # Github OAuth Provider GITHUB_ID=EXAMPLE_GITHUB_ID GITHUB_SECRET=EXAMPLE_GITHUB_SECRET \ No newline at end of file From ac97d76bdcb6de50b8b52e75d0ff0aae401b5daa Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 20:29:49 +0800 Subject: [PATCH 09/23] rm port --- src/server/api/routers/answer.ts | 2 +- src/server/api/routers/judge.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/api/routers/answer.ts b/src/server/api/routers/answer.ts index 44b4b16..3062ba9 100644 --- a/src/server/api/routers/answer.ts +++ b/src/server/api/routers/answer.ts @@ -80,7 +80,7 @@ const answerRouter = createTRPCRouter({ }); const languages = await axios - .get(`${penv.J0_URL}:2358/languages`) + .get(`${penv.J0_URL}/languages`) .then((res) => { return res.data as { id: number; name: string }[]; }); diff --git a/src/server/api/routers/judge.ts b/src/server/api/routers/judge.ts index aab5c39..3318b9d 100644 --- a/src/server/api/routers/judge.ts +++ b/src/server/api/routers/judge.ts @@ -44,7 +44,7 @@ const executionObject = z.object({ export const judgeRouter = createTRPCRouter({ getLanguages: maintainerProcedure.query(async () => { - return axios.get(`${env.J0_URL}:2358/languages`).then((res) => { + return axios.get(`${env.J0_URL}/languages`).then((res) => { return res.data as Language[]; }); }), @@ -53,7 +53,7 @@ export const judgeRouter = createTRPCRouter({ .query(async ({ input }) => { const languageIdSet = new Set(); input.languages.forEach((val) => languageIdSet.add(val)); - return axios.get(`${env.J0_URL}:2358/languages`).then((res) => { + return axios.get(`${env.J0_URL}/languages`).then((res) => { return (res.data as Language[]).filter((value) => languageIdSet.has(value.id)); }); }), @@ -62,7 +62,7 @@ export const judgeRouter = createTRPCRouter({ .mutation(async ({ input }) => { return axios .post( - `${env.J0_URL}:2358/submissions/?base64_encoded=false&wait=true`, + `${env.J0_URL}/submissions/?base64_encoded=false&wait=true`, input, ) .then((res) => { @@ -102,7 +102,7 @@ export const judgeRouter = createTRPCRouter({ }; return axios .post( - `${env.J0_URL}:2358/submissions/?base64_encoded=false&wait=true`, + `${env.J0_URL}/submissions/?base64_encoded=false&wait=true`, newInput, ) .then((res) => { From 66166dd37c22cf2817a4fdb714f159a4b204aa39 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 20:46:47 +0800 Subject: [PATCH 10/23] pr changes --- Dockerfile | 3 +-- compose.yml | 2 +- prisma/mongodb/schema.prisma | 1 - prisma/postgres/schema.prisma | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index dad3964..760616b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ # Dockerfile -FROM node:18-alpine AS deps -RUN apk add --no-cache libc6-compat openssl1.1-compat +FROM node:18-alpine WORKDIR /app COPY . . diff --git a/compose.yml b/compose.yml index 9b3aded..3793e74 100644 --- a/compose.yml +++ b/compose.yml @@ -9,7 +9,7 @@ services: working_dir: /app ports: - "3000:3000" - - "3002:3002" + - ${NEXT_PUBLIC_WS_PORT}:${NEXT_PUBLIC_WS_PORT} image: t3-app networks: - network1 diff --git a/prisma/mongodb/schema.prisma b/prisma/mongodb/schema.prisma index 139e32e..a79922e 100644 --- a/prisma/mongodb/schema.prisma +++ b/prisma/mongodb/schema.prisma @@ -4,7 +4,6 @@ generator client { provider = "prisma-client-js" output = "../../node_modules/@prisma-db-mongo/client" - binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db { diff --git a/prisma/postgres/schema.prisma b/prisma/postgres/schema.prisma index e5817b3..a18a115 100644 --- a/prisma/postgres/schema.prisma +++ b/prisma/postgres/schema.prisma @@ -4,7 +4,6 @@ generator client { provider = "prisma-client-js" output = "../../node_modules/@prisma-db-psql/client" - binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db { From 8866529c1cc950eaab35ab5a2a296986117fee8c Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 21:40:01 +0800 Subject: [PATCH 11/23] rm network --- compose.yml | 12 +----------- judge0-v1.13.0/docker-compose.yml | 1 + 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/compose.yml b/compose.yml index 3793e74..23e8aa1 100644 --- a/compose.yml +++ b/compose.yml @@ -11,8 +11,6 @@ services: - "3000:3000" - ${NEXT_PUBLIC_WS_PORT}:${NEXT_PUBLIC_WS_PORT} image: t3-app - networks: - - network1 postgres_db: image: postgres:12.16 container_name: postgresdb-dev @@ -25,8 +23,6 @@ services: - "5432:5432" volumes: - ./data/postgres:/var/lib/postgresql/data - networks: - - network1 mongo_db: image: mongo:7.0.0 container_name: mongodb-dev @@ -41,8 +37,6 @@ services: - ./data/mongo:/data/db - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js # - ./.docker/mongo/replica.key:/data/replica.key - networks: - - network1 s3-bucket: build: ./s3/ restart: always @@ -52,8 +46,7 @@ services: S3_BUCKET_NAME: ${S3_BUCKET_NAME} volumes: - "./data/s3:/home/app/public/peer-prep" - networks: - - network1 + container_name: s3-bucket rabbitmq: image: rabbitmq:3.11.23-management-alpine restart: always @@ -68,9 +61,6 @@ services: command: sh -c "rabbitmq-plugins enable rabbitmq_web_stomp && rabbitmq-server" networks: - rabbitmq_go_net - - network1 networks: rabbitmq_go_net: driver: bridge - network1: - driver: bridge diff --git a/judge0-v1.13.0/docker-compose.yml b/judge0-v1.13.0/docker-compose.yml index 6a57db0..596f4dd 100644 --- a/judge0-v1.13.0/docker-compose.yml +++ b/judge0-v1.13.0/docker-compose.yml @@ -17,6 +17,7 @@ services: privileged: true <<: *default-logging restart: always + container_name: j0-server workers: image: judge0/judge0:1.13.0 From fe6ed867df89dcaa53b3ef4f24c17db25843d875 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 22:48:04 +0800 Subject: [PATCH 12/23] add network --- .dockerignore | 1 + compose.yml | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/.dockerignore b/.dockerignore index ea76ab4..b762432 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,5 +6,6 @@ README.md .next .server data +docs judge0-* .git \ No newline at end of file diff --git a/compose.yml b/compose.yml index 23e8aa1..197674b 100644 --- a/compose.yml +++ b/compose.yml @@ -11,6 +11,8 @@ services: - "3000:3000" - ${NEXT_PUBLIC_WS_PORT}:${NEXT_PUBLIC_WS_PORT} image: t3-app + networks: + - network1 postgres_db: image: postgres:12.16 container_name: postgresdb-dev @@ -23,6 +25,8 @@ services: - "5432:5432" volumes: - ./data/postgres:/var/lib/postgresql/data + networks: + - network1 mongo_db: image: mongo:7.0.0 container_name: mongodb-dev @@ -37,6 +41,8 @@ services: - ./data/mongo:/data/db - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js # - ./.docker/mongo/replica.key:/data/replica.key + networks: + - network1 s3-bucket: build: ./s3/ restart: always @@ -46,6 +52,8 @@ services: S3_BUCKET_NAME: ${S3_BUCKET_NAME} volumes: - "./data/s3:/home/app/public/peer-prep" + networks: + - network1 container_name: s3-bucket rabbitmq: image: rabbitmq:3.11.23-management-alpine @@ -61,6 +69,9 @@ services: command: sh -c "rabbitmq-plugins enable rabbitmq_web_stomp && rabbitmq-server" networks: - rabbitmq_go_net + - network1 networks: rabbitmq_go_net: driver: bridge + network1: + driver: bridge From ba9c625afb9f92d902b514bfb2e4cbe5a93c295d Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 23:38:54 +0800 Subject: [PATCH 13/23] done1 --- compose.yml | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/compose.yml b/compose.yml index 197674b..6ac6efd 100644 --- a/compose.yml +++ b/compose.yml @@ -11,8 +11,6 @@ services: - "3000:3000" - ${NEXT_PUBLIC_WS_PORT}:${NEXT_PUBLIC_WS_PORT} image: t3-app - networks: - - network1 postgres_db: image: postgres:12.16 container_name: postgresdb-dev @@ -25,24 +23,20 @@ services: - "5432:5432" volumes: - ./data/postgres:/var/lib/postgresql/data - networks: - - network1 - mongo_db: - image: mongo:7.0.0 - container_name: mongodb-dev - command: ["--replSet", "rs0", "--bind_ip_all"] - restart: always - # environment: - # MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} - # MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD} - ports: - - "27017:27017" - volumes: - - ./data/mongo:/data/db - - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js - # - ./.docker/mongo/replica.key:/data/replica.key - networks: - - network1 + # mongo_db: + # image: mongo:7.0.0 + # container_name: mongodb-dev + # command: ["--replSet", "rs0", "--bind_ip_all"] + # restart: always + # # environment: + # # MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} + # # MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD} + # ports: + # - "27017:27017" + # volumes: + # - ./data/mongo:/data/db + # - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js + # # - ./.docker/mongo/replica.key:/data/replica.key s3-bucket: build: ./s3/ restart: always @@ -52,8 +46,6 @@ services: S3_BUCKET_NAME: ${S3_BUCKET_NAME} volumes: - "./data/s3:/home/app/public/peer-prep" - networks: - - network1 container_name: s3-bucket rabbitmq: image: rabbitmq:3.11.23-management-alpine @@ -69,9 +61,6 @@ services: command: sh -c "rabbitmq-plugins enable rabbitmq_web_stomp && rabbitmq-server" networks: - rabbitmq_go_net - - network1 networks: rabbitmq_go_net: driver: bridge - network1: - driver: bridge From 7f36d39d546b591c34e6d4d96e6d57226e68dc51 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Thu, 9 Nov 2023 23:48:17 +0800 Subject: [PATCH 14/23] edits --- src/server/api/routers/judge.ts | 328 ++++++++++++++++---------------- src/server/wssServer.ts | 6 +- 2 files changed, 164 insertions(+), 170 deletions(-) diff --git a/src/server/api/routers/judge.ts b/src/server/api/routers/judge.ts index 09b0981..7bf1e07 100644 --- a/src/server/api/routers/judge.ts +++ b/src/server/api/routers/judge.ts @@ -1,16 +1,14 @@ +import { type AnswerResult } from "@prisma-db-psql/client"; +import { TRPCError } from "@trpc/server"; import axios from "axios"; -import { number, z } from "zod"; +import { z } from "zod"; +import { env } from "~/env.mjs"; +import { prismaMongo, prismaPostgres } from "~/server/db"; import { createTRPCRouter, maintainerProcedure, protectedProcedure, - publicProcedure, } from "../trpc"; -import { env } from "~/env.mjs"; -import { prismaMongo, prismaPostgres } from "~/server/db"; -import { type AnswerResult } from "@prisma-db-psql/client"; -import { TRPCClientError } from "@trpc/client"; -import { TRPCError } from "@trpc/server"; // TODO: Multifile @@ -23,7 +21,6 @@ type BatchSubmissionOutput = { token: string; }[]; - type Output = { stdout: string | null; time: string; @@ -35,9 +32,8 @@ type Output = { status: { id: number; description: string }; }; - type BatchSubmissionRequestOutput = { - submissions: Output[] + submissions: Output[]; }; const judgeStatusCodeMap = new Map([ @@ -46,14 +42,10 @@ const judgeStatusCodeMap = new Map([ [5, "TIME_LIMITED_ERROR"], [6, "COMPILE_ERROR"], [13, "JUDGE_ERROR"], - [14, "JUDGE_ERROR"] + [14, "JUDGE_ERROR"], ]); - - function fromStatusCode(code: number): AnswerResult | "WAITING" { - - if (code == 1 || code == 0) { return "WAITING"; } @@ -66,16 +58,12 @@ function fromStatusCode(code: number): AnswerResult | "WAITING" { return judgeStatusCodeMap.get(code)!; } - async function getLanguageFromCode(code: number): Promise { - const languages = await axios - .get("http://localhost:2358/languages") - .then((res) => { - return res.data as { id: number; name: string }[]; - }); + const languages = await axios.get(`${env.J0_URL}/languages`).then((res) => { + return res.data as { id: number; name: string }[]; + }); return languages?.find((l) => l.id === code)?.name ?? ""; - } const testCaseExecutionObject = z.object({ @@ -103,12 +91,14 @@ export const judgeRouter = createTRPCRouter({ getSpecificLanguages: protectedProcedure .input(z.object({ languages: z.array(z.number()) })) .query(async ({ input }) => { - const languageIdSet = new Set(); - input.languages.forEach((val) => languageIdSet.add(val)); - return axios.get(`${env.J0_URL}/languages`).then((res) => { - return (res.data as Language[]).filter((value) => languageIdSet.has(value.id)); - }); - }), + const languageIdSet = new Set(); + input.languages.forEach((val) => languageIdSet.add(val)); + return axios.get(`${env.J0_URL}/languages`).then((res) => { + return (res.data as Language[]).filter((value) => + languageIdSet.has(value.id), + ); + }); + }), run: maintainerProcedure .input(executionObject) .mutation(async ({ input }) => { @@ -161,157 +151,161 @@ export const judgeRouter = createTRPCRouter({ return res.data as Output; }); }), - checkAnswer: protectedProcedure - .input(z.object({ submissionId: z.string() })) - .query(async ({ ctx, input }) => { - // check if question attempt already exists - const questionAttempt = await ctx.prismaPostgres.questionAttempt.findUnique({ + checkAnswer: protectedProcedure + .input(z.object({ submissionId: z.string() })) + .query(async ({ ctx, input }) => { + // check if question attempt already exists + const questionAttempt = + await ctx.prismaPostgres.questionAttempt.findUnique({ where: { userId_submissionId: { userId: ctx.session.user.id, - submissionId: input.submissionId - } - } - }) - if (questionAttempt) { - return { - status: questionAttempt.result, - complete: true, - numOfTests: questionAttempt.numOfTests, - passed: questionAttempt.passed - }; - } - const submission = await ctx.prismaPostgres.submission.findUnique({ - where: { - userId_id: { - userId: ctx.session.user.id, - id: input.submissionId - } - } + submissionId: input.submissionId, + }, + }, }); - const answer = await ctx.prismaMongo.answer.findUnique({ - where: { - id: submission?.answerId + if (questionAttempt) { + return { + status: questionAttempt.result, + complete: true, + numOfTests: questionAttempt.numOfTests, + passed: questionAttempt.passed, + }; + } + const submission = await ctx.prismaPostgres.submission.findUnique({ + where: { + userId_id: { + userId: ctx.session.user.id, + id: input.submissionId, }, - include: { - environment: true - } + }, + }); + const answer = await ctx.prismaMongo.answer.findUnique({ + where: { + id: submission?.answerId, + }, + include: { + environment: true, + }, + }); + if (!submission || !answer) + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Failed to find submission", }); - if (!submission || !answer) throw new TRPCError({ code: "BAD_REQUEST", message: "Failed to find submission" }); - const tokens = submission.token.join(','); - const status = await axios.get(`http://localhost:2358/submissions/batch?tokens=${tokens}&base64_encoded=false`); - // check if we finished evaluation - const result = status.data as BatchSubmissionRequestOutput; - let currentStatus: AnswerResult = "ACCEPTED"; - let passed = 0; - for (const submission of result.submissions) { - const status = fromStatusCode(submission.status.id); - if (status === "WAITING") { - return { - complete: false, - passed, - status: "WAITING", - numOfTests: result.submissions.length - } - } - if (status !== "ACCEPTED") { - // return the first error - currentStatus = status; - break; - } - passed += 1; - } - await prismaPostgres.questionAttempt.create({ - data: { - userId: ctx.session.user.id, - answerId: submission.answerId, - language: await getLanguageFromCode(answer.environment.languageId), - result: currentStatus, - questionId: answer.environment.questionId, + const tokens = submission.token.join(","); + const status = await axios.get( + `${env.J0_URL}/submissions/batch?tokens=${tokens}&base64_encoded=false`, + ); + // check if we finished evaluation + const result = status.data as BatchSubmissionRequestOutput; + let currentStatus: AnswerResult = "ACCEPTED"; + let passed = 0; + for (const submission of result.submissions) { + const status = fromStatusCode(submission.status.id); + if (status === "WAITING") { + return { + complete: false, passed, + status: "WAITING", numOfTests: result.submissions.length, - submissionId: input.submissionId, - } - }); - - await prismaPostgres.submission.delete({ - where: { - userId_id: { - userId: ctx.session.user.id, - id: input.submissionId, - } - } - }) - - return { - status: currentStatus, - passed, - complete: true, - numOfTests: result.submissions.length + }; } + if (status !== "ACCEPTED") { + // return the first error + currentStatus = status; + break; + } + passed += 1; + } + await prismaPostgres.questionAttempt.create({ + data: { + userId: ctx.session.user.id, + answerId: submission.answerId, + language: await getLanguageFromCode(answer.environment.languageId), + result: currentStatus, + questionId: answer.environment.questionId, + passed, + numOfTests: result.submissions.length, + submissionId: input.submissionId, + }, + }); - }), - submitCode: - protectedProcedure - .input(z.object({ source_code: z.string(), environmentId: z.string()})) - .mutation(async ({ ctx, input }) => { - // create a submissions batch for all the test cases - // which satisfy the envid - const { source_code, environmentId } = input; - const environment = await prismaMongo.environment.findUnique({ - where: { - id: environmentId, - } - }); - if (!environment) { - throw new TRPCError({ - code: "BAD_REQUEST", - message: "Invalid environmentId" - }); - } - const testCases = await prismaMongo.testCase.findMany({ - where: { - environmentId - } - }); - const judgeInput = testCases.map((testCase) => ({ - source_code: `${environment.prepend}\n${source_code}\n${environment.append}\n${testCase.test}`, - language_id: environment.languageId, - stdin: testCase.input, - expected_output: testCase.output, - cpu_time_limit: testCase.timeLimit, - memory_limit: testCase.memoryLimit - ? Math.max(testCase.memoryLimit, 2048) - : undefined, - })); + await prismaPostgres.submission.delete({ + where: { + userId_id: { + userId: ctx.session.user.id, + id: input.submissionId, + }, + }, + }); + return { + status: currentStatus, + passed, + complete: true, + numOfTests: result.submissions.length, + }; + }), + submitCode: protectedProcedure + .input(z.object({ source_code: z.string(), environmentId: z.string() })) + .mutation(async ({ ctx, input }) => { + // create a submissions batch for all the test cases + // which satisfy the envid + const { source_code, environmentId } = input; + const environment = await prismaMongo.environment.findUnique({ + where: { + id: environmentId, + }, + }); + if (!environment) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Invalid environmentId", + }); + } + const testCases = await prismaMongo.testCase.findMany({ + where: { + environmentId, + }, + }); + const judgeInput = testCases.map((testCase) => ({ + source_code: `${environment.prepend}\n${source_code}\n${environment.append}\n${testCase.test}`, + language_id: environment.languageId, + stdin: testCase.input, + expected_output: testCase.output, + cpu_time_limit: testCase.timeLimit, + memory_limit: testCase.memoryLimit + ? Math.max(testCase.memoryLimit, 2048) + : undefined, + })); - const result = (await axios - .post( - "http://localhost:2358/submissions/batch?base64_encoded=false", - { - submissions: judgeInput - }, - )).data as BatchSubmissionOutput; - const answer = await prismaMongo.answer.create({ - data: { - body: source_code, - envId: environmentId - } - }); - // place this submission in memory - const submission = await prismaPostgres - .submission.create({ - data: { - token: result.map(({ token }) => token), - userId: ctx.session.user.id, - answerId: answer.id - } - }); + const result = ( + await axios.post( + `${env.J0_URL}/submissions/batch?base64_encoded=false`, + { + submissions: judgeInput, + }, + ) + ).data as BatchSubmissionOutput; + const answer = await prismaMongo.answer.create({ + data: { + body: source_code, + envId: environmentId, + }, + }); + // place this submission in memory + const submission = await prismaPostgres.submission.create({ + data: { + token: result.map(({ token }) => token), + userId: ctx.session.user.id, + answerId: answer.id, + }, + }); - return { - submissionId: submission.id - }; - }) + return { + submissionId: submission.id, + }; + }), }); diff --git a/src/server/wssServer.ts b/src/server/wssServer.ts index 26d4fc8..fc1fab7 100644 --- a/src/server/wssServer.ts +++ b/src/server/wssServer.ts @@ -1,6 +1,6 @@ -import { AppRouter, appRouter } from "./api/root"; +import { type AppRouter, appRouter } from "./api/root"; import { applyWSSHandler } from "@trpc/server/adapters/ws"; -import ws, { WebSocketServer } from "ws"; +import ws, { type WebSocketServer } from "ws"; import { createWSTRPCContext } from "./api/trpc"; import { env } from "~/env.mjs"; @@ -25,7 +25,7 @@ export const wssEE = wss.on("connection", (ws) => { console.log(`➖➖ Connection (${wss.clients.size})`); }); }); -console.log("✅ WebSocket Server listening on ws://localhost:${env.NEXT_PUBLIC_WS_PORT}"); +console.log(`✅ WebSocket Server listening on ws://localhost:${env.NEXT_PUBLIC_WS_PORT}`); process.on("SIGTERM", () => { console.log("SIGTERM"); From 354294d57baddc515a67c8d26d62d6616688af3a Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Fri, 10 Nov 2023 00:12:37 +0800 Subject: [PATCH 15/23] answer imports --- src/server/api/routers/answer.ts | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/server/api/routers/answer.ts b/src/server/api/routers/answer.ts index 6b82f20..c5d8305 100644 --- a/src/server/api/routers/answer.ts +++ b/src/server/api/routers/answer.ts @@ -1,23 +1,8 @@ -import type { Answer } from "@prisma-db-mongo/client"; -import type { AnswerResult } from "@prisma-db-psql/client"; import { TRPCError } from "@trpc/server"; -import axios from "axios"; -import { type Session } from "next-auth"; import { z } from "zod"; -import { - type PrismaMongoT, - type PrismaPostgresT, - prismaMongo, - prismaPostgres, -} from "~/server/db"; -import { appRouter } from "../root"; -import { Session } from "next-auth"; -import { api } from "~/utils/api"; -import axios from "axios"; +import { prismaMongo, prismaPostgres } from "~/server/db"; import { appRouter } from "../root"; import { createTRPCRouter, protectedProcedure } from "../trpc"; -import { env as penv } from "~/env.mjs"; - const answerRouter = createTRPCRouter({ getUserSubmissions: protectedProcedure.query(async ({ ctx }) => { @@ -25,14 +10,14 @@ const answerRouter = createTRPCRouter({ // update all the remaining submissions const temporarySubmissions = await prismaPostgres.submission.findMany({ where: { - userId: ctx.session.user.id - } + userId: ctx.session.user.id, + }, }); const caller = appRouter.createCaller(ctx); for (const tmpSubmssion of temporarySubmissions) { await caller.judge.checkAnswer({ - submissionId: tmpSubmssion.id - }) + submissionId: tmpSubmssion.id, + }); } const submissions = await prismaPostgres.questionAttempt.findMany({ where: { From 67c054d4acb9dd126ad8c54cc4dafcd443b71acc Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Fri, 10 Nov 2023 14:16:29 +0800 Subject: [PATCH 16/23] prod envs --- .dockerignore | 3 ++- .env.example | 2 +- Dockerfile | 1 + README.md | 4 ++-- compose.yml | 30 +++++++++++++------------ package.json | 4 ++-- production/.env.example | 50 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 production/.env.example diff --git a/.dockerignore b/.dockerignore index b762432..0bb219d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,4 +8,5 @@ README.md data docs judge0-* -.git \ No newline at end of file +.git +/.env \ No newline at end of file diff --git a/.env.example b/.env.example index 0554f83..aa2b57c 100644 --- a/.env.example +++ b/.env.example @@ -11,7 +11,7 @@ ## Node NODE_ENV=development -PORT=3000 +PORT=4000 # Websocket port NEXT_PUBLIC_WS_PORT=3002 diff --git a/Dockerfile b/Dockerfile index 760616b..d3e22cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ FROM node:18-alpine WORKDIR /app COPY . . +COPY /production/.env .env RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ diff --git a/README.md b/README.md index 19a0eca..86d16a5 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ Notes: ## Building and Running Image ```bash - docker build -t peer-prep --build-arg NEXT_PUBLIC_WS_PORT=3002 . - docker run -p 3000:3000 -p 3002:3002 peer-prep + docker build -t peer-prep . + docker compose --profile prod up ``` ## What's next? How do I make an app with this? diff --git a/compose.yml b/compose.yml index 6ac6efd..ef9ddaf 100644 --- a/compose.yml +++ b/compose.yml @@ -11,6 +11,8 @@ services: - "3000:3000" - ${NEXT_PUBLIC_WS_PORT}:${NEXT_PUBLIC_WS_PORT} image: t3-app + profiles: + - prod postgres_db: image: postgres:12.16 container_name: postgresdb-dev @@ -23,20 +25,20 @@ services: - "5432:5432" volumes: - ./data/postgres:/var/lib/postgresql/data - # mongo_db: - # image: mongo:7.0.0 - # container_name: mongodb-dev - # command: ["--replSet", "rs0", "--bind_ip_all"] - # restart: always - # # environment: - # # MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} - # # MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD} - # ports: - # - "27017:27017" - # volumes: - # - ./data/mongo:/data/db - # - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js - # # - ./.docker/mongo/replica.key:/data/replica.key + mongo_db: + image: mongo:7.0.0 + container_name: mongodb-dev + command: ["--replSet", "rs0", "--bind_ip_all"] + restart: always + # environment: + # MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} + # MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD} + ports: + - "27017:27017" + volumes: + - ./data/mongo:/data/db + - ./.docker/mongo/rs-initiate.js:/docker-entrypoint-initdb.d/rs-initiate.js + # - ./.docker/mongo/replica.key:/data/replica.key s3-bucket: build: ./s3/ restart: always diff --git a/package.json b/package.json index 292326b..0d4aece 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "prisma:generate": "prisma generate --schema prisma/mongodb/schema.prisma && prisma generate --schema prisma/postgres/schema.prisma", "prisma:push": "prisma db push --schema prisma/mongodb/schema.prisma && prisma db push --schema prisma/postgres/schema.prisma", "prisma:studio": "prisma studio --schema prisma/mongodb/schema.prisma | prisma studio --schema prisma/postgres/schema.prisma -p 5556", - "docker:up": "docker-compose up -d", - "docker:down": "docker-compose down", + "docker:up": "docker compose up", + "docker:down": "docker compose down", "start-dev": "./start-dev-script.sh" }, "dependencies": { diff --git a/production/.env.example b/production/.env.example new file mode 100644 index 0000000..aa2b57c --- /dev/null +++ b/production/.env.example @@ -0,0 +1,50 @@ +# Since the ".env" file is gitignored, you can use the ".env.example" file to +# build a new ".env" file when you clone the repo. Keep this file up-to-date +# when you add new variables to `.env`. + +# This file will be committed to version control, so make sure not to have any +# secrets in it. If you are cloning this repo, create a copy of this file named +# ".env" and populate it with your secrets. + +# When adding additional environment variables, the schema in "/src/env.mjs" +# should be updated accordingly. + +## Node +NODE_ENV=development +PORT=4000 +# Websocket port +NEXT_PUBLIC_WS_PORT=3002 + +# PostgreSQL +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password +POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/db?schema=public" + +## MongoDB + +MONGO_USER=root +MONGO_PASSWORD=password +# MONGO_URL="mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/db?authSource=admin" +MONGO_URL="mongodb://localhost:27017/db" + +# Next Auth +# You can generate a new secret on the command line with: +# openssl rand -base64 32 +# https://next-auth.js.org/configuration/options#secret +NEXTAUTH_SECRET=NEXTAUTH_SECRET +NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET +NEXTAUTH_URL="http://localhost:${PORT}" + +# S3 +S3_BUCKET_NAME=s3 +S3_ENDPOINT="http://localhost:9000" + +# JUDGE0 +J0_URL="http://j0-server:2358" + +# Github OAuth Provider +GITHUB_ID=EXAMPLE_GITHUB_ID +GITHUB_SECRET=EXAMPLE_GITHUB_SECRET + +# OpenAI +OPENAI_API_KEY=EXAMPLE_OPENAI_API_KEY \ No newline at end of file From 853c7a7258697ab725989470b3abb23c79acdd64 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Fri, 10 Nov 2023 14:26:39 +0800 Subject: [PATCH 17/23] re-add checks --- next.config.mjs | 12 ------------ production/.env.example | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index 432b9cf..3b26405 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -28,18 +28,6 @@ const config = { locales: ["en"], defaultLocale: "en", }, - typescript: { - // !! WARN !! - // Dangerously allow production builds to successfully complete even if - // your project has type errors. - // !! WARN !! - ignoreBuildErrors: true, - }, - eslint: { - // Warning: This allows production builds to successfully complete even if - // your project has ESLint errors. - ignoreDuringBuilds: true, - }, }; export default config; diff --git a/production/.env.example b/production/.env.example index aa2b57c..b62c708 100644 --- a/production/.env.example +++ b/production/.env.example @@ -10,7 +10,7 @@ # should be updated accordingly. ## Node -NODE_ENV=development +NODE_ENV=production PORT=4000 # Websocket port NEXT_PUBLIC_WS_PORT=3002 From 3f85a4a7053b720e1ad4e651181dd1fa47ddb3ab Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Fri, 10 Nov 2023 14:28:20 +0800 Subject: [PATCH 18/23] diff envs --- .env.example | 36 ++++++++++++++---------------------- production/.env.example | 41 ++++++++++++++++------------------------- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/.env.example b/.env.example index aa2b57c..9e6ea45 100644 --- a/.env.example +++ b/.env.example @@ -1,17 +1,7 @@ -# Since the ".env" file is gitignored, you can use the ".env.example" file to -# build a new ".env" file when you clone the repo. Keep this file up-to-date -# when you add new variables to `.env`. - -# This file will be committed to version control, so make sure not to have any -# secrets in it. If you are cloning this repo, create a copy of this file named -# ".env" and populate it with your secrets. - -# When adding additional environment variables, the schema in "/src/env.mjs" -# should be updated accordingly. ## Node NODE_ENV=development -PORT=4000 +PORT=3000 # Websocket port NEXT_PUBLIC_WS_PORT=3002 @@ -21,30 +11,32 @@ POSTGRES_PASSWORD=password POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/db?schema=public" ## MongoDB +# MONGO_USER=mongodb +# MONGO_PASSWORD=DNs3kNlSnV9Q8iBO +# MONGO_URL="mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@cs3219test.heahtzv.mongodb.net/db" MONGO_USER=root MONGO_PASSWORD=password -# MONGO_URL="mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/db?authSource=admin" MONGO_URL="mongodb://localhost:27017/db" # Next Auth # You can generate a new secret on the command line with: # openssl rand -base64 32 # https://next-auth.js.org/configuration/options#secret -NEXTAUTH_SECRET=NEXTAUTH_SECRET -NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET +NEXTAUTH_SECRET=EXAMPLE_NEXTAUTH_SEC NEXTAUTH_URL="http://localhost:${PORT}" -# S3 -S3_BUCKET_NAME=s3 S3_ENDPOINT="http://localhost:9000" + # JUDGE0 -J0_URL="http://j0-server:2358" +J0_URL="http://localhost:2358" -# Github OAuth Provider -GITHUB_ID=EXAMPLE_GITHUB_ID -GITHUB_SECRET=EXAMPLE_GITHUB_SECRET +S3_BUCKET_NAME=some +# Next auth secret +NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET -# OpenAI -OPENAI_API_KEY=EXAMPLE_OPENAI_API_KEY \ No newline at end of file +# Github OAuth Provider +GITHUB_ID=423856fc5cae959fe4c4 +GITHUB_SECRET=96df1e12eeb67a9359213ff14826c538522fdea4 +OPENAI_API_KEY=apple diff --git a/production/.env.example b/production/.env.example index b62c708..f7e8b37 100644 --- a/production/.env.example +++ b/production/.env.example @@ -1,50 +1,41 @@ -# Since the ".env" file is gitignored, you can use the ".env.example" file to -# build a new ".env" file when you clone the repo. Keep this file up-to-date -# when you add new variables to `.env`. - -# This file will be committed to version control, so make sure not to have any -# secrets in it. If you are cloning this repo, create a copy of this file named -# ".env" and populate it with your secrets. - -# When adding additional environment variables, the schema in "/src/env.mjs" -# should be updated accordingly. ## Node NODE_ENV=production -PORT=4000 +PORT=3000 # Websocket port NEXT_PUBLIC_WS_PORT=3002 # PostgreSQL POSTGRES_USER=postgres POSTGRES_PASSWORD=password -POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/db?schema=public" +POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgresdb-dev:5432/db?schema=public" ## MongoDB +MONGO_USER=mongodb +MONGO_PASSWORD=DNs3kNlSnV9Q8iBO +MONGO_URL="mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@cs3219test.heahtzv.mongodb.net/db" -MONGO_USER=root -MONGO_PASSWORD=password -# MONGO_URL="mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/db?authSource=admin" -MONGO_URL="mongodb://localhost:27017/db" +# MONGO_URL="mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongodb-dev:27017/db?authSource=admin" +# MONGO_URL="mongodb://mongodb-dev:27017/db" # Next Auth # You can generate a new secret on the command line with: # openssl rand -base64 32 # https://next-auth.js.org/configuration/options#secret -NEXTAUTH_SECRET=NEXTAUTH_SECRET -NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET +NEXTAUTH_SECRET=EXAMPLE_NEXTAUTH_SEC NEXTAUTH_URL="http://localhost:${PORT}" -# S3 -S3_BUCKET_NAME=s3 S3_ENDPOINT="http://localhost:9000" + # JUDGE0 J0_URL="http://j0-server:2358" -# Github OAuth Provider -GITHUB_ID=EXAMPLE_GITHUB_ID -GITHUB_SECRET=EXAMPLE_GITHUB_SECRET +S3_BUCKET_NAME=some +# Next auth secret +NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET -# OpenAI -OPENAI_API_KEY=EXAMPLE_OPENAI_API_KEY \ No newline at end of file +# Github OAuth Provider +GITHUB_ID=423856fc5cae959fe4c4 +GITHUB_SECRET=96df1e12eeb67a9359213ff14826c538522fdea4 +OPENAI_API_KEY=apple From cc048197e99a88fe8c705c1825521e6cd1019326 Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Sat, 11 Nov 2023 12:48:51 +0800 Subject: [PATCH 19/23] clean --- .env.example | 21 ++++++++------------- production/.env.example | 21 +++++++++------------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/.env.example b/.env.example index 9e6ea45..68f14a1 100644 --- a/.env.example +++ b/.env.example @@ -6,17 +6,12 @@ PORT=3000 NEXT_PUBLIC_WS_PORT=3002 # PostgreSQL -POSTGRES_USER=postgres -POSTGRES_PASSWORD=password +POSTGRES_USER= +POSTGRES_PASSWORD= POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/db?schema=public" -## MongoDB -# MONGO_USER=mongodb -# MONGO_PASSWORD=DNs3kNlSnV9Q8iBO -# MONGO_URL="mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@cs3219test.heahtzv.mongodb.net/db" - -MONGO_USER=root -MONGO_PASSWORD=password +MONGO_USER= +MONGO_PASSWORD= MONGO_URL="mongodb://localhost:27017/db" # Next Auth @@ -34,9 +29,9 @@ J0_URL="http://localhost:2358" S3_BUCKET_NAME=some # Next auth secret -NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET +NEXT_AUTH_SECRET= # Github OAuth Provider -GITHUB_ID=423856fc5cae959fe4c4 -GITHUB_SECRET=96df1e12eeb67a9359213ff14826c538522fdea4 -OPENAI_API_KEY=apple +GITHUB_ID= +GITHUB_SECRET= +OPENAI_API_KEY= diff --git a/production/.env.example b/production/.env.example index f7e8b37..e85f3ee 100644 --- a/production/.env.example +++ b/production/.env.example @@ -6,17 +6,14 @@ PORT=3000 NEXT_PUBLIC_WS_PORT=3002 # PostgreSQL -POSTGRES_USER=postgres -POSTGRES_PASSWORD=password -POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgresdb-dev:5432/db?schema=public" +POSTGRES_USER= +POSTGRES_PASSWORD= +POSTGRES_URL= ## MongoDB -MONGO_USER=mongodb -MONGO_PASSWORD=DNs3kNlSnV9Q8iBO -MONGO_URL="mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@cs3219test.heahtzv.mongodb.net/db" - -# MONGO_URL="mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongodb-dev:27017/db?authSource=admin" -# MONGO_URL="mongodb://mongodb-dev:27017/db" +MONGO_USER= +MONGO_PASSWORD= +MONGO_URL= # Next Auth # You can generate a new secret on the command line with: @@ -36,6 +33,6 @@ S3_BUCKET_NAME=some NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET # Github OAuth Provider -GITHUB_ID=423856fc5cae959fe4c4 -GITHUB_SECRET=96df1e12eeb67a9359213ff14826c538522fdea4 -OPENAI_API_KEY=apple +GITHUB_ID= +GITHUB_SECRET= +OPENAI_API_KEY= From 6b517b3bfb1f07e55c09a11dc6b1960f3294b8bc Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Sun, 12 Nov 2023 11:11:53 +0800 Subject: [PATCH 20/23] readd env --- .env.example | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/.env.example b/.env.example index 68f14a1..d45c9d0 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,13 @@ +# Since the ".env" file is gitignored, you can use the ".env.example" file to +# build a new ".env" file when you clone the repo. Keep this file up-to-date +# when you add new variables to `.env`. + +# This file will be committed to version control, so make sure not to have any +# secrets in it. If you are cloning this repo, create a copy of this file named +# ".env" and populate it with your secrets. + +# When adding additional environment variables, the schema in "/src/env.mjs" +# should be updated accordingly. ## Node NODE_ENV=development @@ -6,32 +16,31 @@ PORT=3000 NEXT_PUBLIC_WS_PORT=3002 # PostgreSQL -POSTGRES_USER= -POSTGRES_PASSWORD= +POSTGRES_USER=postgres +POSTGRES_PASSWORD=password POSTGRES_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/db?schema=public" -MONGO_USER= -MONGO_PASSWORD= +## MongoDB + +MONGO_USER=root +MONGO_PASSWORD=password +# MONGO_URL="mongodb://${MONGO_USER}:${MONGO_PASSWORD}@localhost:27017/db?authSource=admin" MONGO_URL="mongodb://localhost:27017/db" # Next Auth # You can generate a new secret on the command line with: # openssl rand -base64 32 # https://next-auth.js.org/configuration/options#secret -NEXTAUTH_SECRET=EXAMPLE_NEXTAUTH_SEC +NEXTAUTH_SECRET=NEXTAUTH_SECRET +NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET NEXTAUTH_URL="http://localhost:${PORT}" -S3_ENDPOINT="http://localhost:9000" - - -# JUDGE0 -J0_URL="http://localhost:2358" - -S3_BUCKET_NAME=some -# Next auth secret -NEXT_AUTH_SECRET= +# S3 +S3_BUCKET_NAME=s3 # Github OAuth Provider -GITHUB_ID= -GITHUB_SECRET= -OPENAI_API_KEY= +GITHUB_ID=EXAMPLE_GITHUB_ID +GITHUB_SECRET=EXAMPLE_GITHUB_SECRET + +# OpenAI +OPENAI_API_KEY=EXAMPLE_OPENAI_ID From 9eef9f156c9dd688c3bfd9d23c19795872f4643d Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Sun, 12 Nov 2023 11:15:07 +0800 Subject: [PATCH 21/23] add env --- .env.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.env.example b/.env.example index d45c9d0..bd0b0ee 100644 --- a/.env.example +++ b/.env.example @@ -35,7 +35,11 @@ NEXTAUTH_SECRET=NEXTAUTH_SECRET NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET NEXTAUTH_URL="http://localhost:${PORT}" +# Judge0 +JUDGE0_URL="http://localhost:2358" + # S3 +S3_ENDPOINT="http://localhost:9000" S3_BUCKET_NAME=s3 # Github OAuth Provider From 0e13522faaeea170d6a50ff12a8596a146f1633d Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Sun, 12 Nov 2023 11:16:26 +0800 Subject: [PATCH 22/23] env --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index bd0b0ee..af47573 100644 --- a/.env.example +++ b/.env.example @@ -36,7 +36,7 @@ NEXT_AUTH_SECRET=EXAMPLE_JWT_SECRET NEXTAUTH_URL="http://localhost:${PORT}" # Judge0 -JUDGE0_URL="http://localhost:2358" +J0_URL="http://localhost:2358" # S3 S3_ENDPOINT="http://localhost:9000" From 6ff332cb09cc28cb71ce1a9634e46cad4708ff2b Mon Sep 17 00:00:00 2001 From: Wang Jiefan Date: Sun, 12 Nov 2023 14:34:05 +0800 Subject: [PATCH 23/23] add detatch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c0ed16..c718275 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "prisma:generate": "prisma generate --schema prisma/mongodb/schema.prisma && prisma generate --schema prisma/postgres/schema.prisma", "prisma:push": "prisma db push --schema prisma/mongodb/schema.prisma && prisma db push --schema prisma/postgres/schema.prisma", "prisma:studio": "prisma studio --schema prisma/mongodb/schema.prisma | prisma studio --schema prisma/postgres/schema.prisma -p 5556", - "docker:up": "docker compose up", + "docker:up": "docker compose up -d", "docker:down": "docker compose down", "start-dev": "./start-dev-script.sh" },