Skip to content

Commit

Permalink
[Backend] Codemod table, Prisma integration, Dockerfile tweaks, seedi…
Browse files Browse the repository at this point in the history
…ng script (CDMD-2634, CDMD-2637, CDMD-2693) (codemod-com#109)
  • Loading branch information
r4zendev authored Mar 6, 2024
1 parent 7587e1b commit 6729324
Show file tree
Hide file tree
Showing 30 changed files with 1,544 additions and 7,585 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ yarn-debug.log*
.vercel

# Backend
build-ncc
build
4 changes: 4 additions & 0 deletions apps/studio-backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
prisma/generated
# Keep environment variables out of version control
.env
27 changes: 14 additions & 13 deletions apps/studio-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# stage0
FROM node:19-alpine3.16 as stage0
FROM node:19-alpine3.16

WORKDIR /opt/studio-backend
WORKDIR /app/

RUN npm install -g pnpm

COPY ./package.json ./pnpm-lock.yaml /opt/studio-backend/
COPY ./apps/studio-backend/package.json ./apps/studio-backend/pnpm-lock.yaml /app/apps/studio-backend/
COPY ./pnpm-workspace.yaml /app/
COPY ./packages /app/packages/

RUN pnpm install

COPY ./tsconfig.json /opt/studio-backend/
COPY ./src /opt/studio-backend/src
COPY ./apps/studio-backend/prisma /app/apps/studio-backend/prisma/
COPY ./apps/studio-backend/.env /app/apps/studio-backend/
COPY ./apps/studio-backend/tsconfig.json /app/apps/studio-backend/
COPY ./apps/studio-backend/esbuild.config.js /app/apps/studio-backend/
COPY ./apps/studio-backend/src /app/apps/studio-backend/src/

RUN pnpm run build:ncc
WORKDIR /app/apps/studio-backend

# stage 1
FROM node:19-alpine3.16 as stage1
RUN pnpm db:generate

WORKDIR /opt/studio-backend

COPY --from=stage0 /opt/studio-backend/build-ncc/ /opt/studio-backend
RUN pnpm build

EXPOSE 8081

CMD ["node", "./index.js"]
CMD ["node", "./build/server.js"]
14 changes: 10 additions & 4 deletions apps/studio-backend/development.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
FROM node:19-alpine3.16

WORKDIR /opt/studio-backend
WORKDIR /app/

RUN npm install -g pnpm

COPY ./package.json ./pnpm-lock.yaml /opt/studio-backend/
COPY ./apps/studio-backend/package.json ./apps/studio-backend/pnpm-lock.yaml /app/apps/studio-backend/
COPY ./pnpm-workspace.yaml /app/
COPY ./packages /app/packages/

RUN pnpm install

COPY ./tsconfig.json /opt/studio-backend/
COPY ./src /opt/studio-backend/src
COPY ./apps/studio-backend/prisma /app/apps/studio-backend/prisma/
COPY ./apps/studio-backend/tsconfig.json /app/apps/studio-backend/
COPY ./apps/studio-backend/src /app/apps/studio-backend/src/

# WORKDIR /app/studio-backend

CMD pnpm --filter studio-backend watch
9 changes: 4 additions & 5 deletions apps/studio-backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ services:
- 'codemod-local-network'
studio-backend:
build:
context: .
dockerfile: development.Dockerfile
context: ../..
dockerfile: apps/studio-backend/development.Dockerfile
environment:
PORT: '8081'
CLERK_DISABLED: 'true'
DATABASE_URL: 'postgres://postgres:postgres@studio-database:5432/studio'
DATABASE_URI: 'postgres://postgres:postgres@studio-database:5432/studio'
ports:
- '8081:8081'
networks:
- 'codemod-local-network'
command: ['pnpm', 'watch']
volumes:
- ./src:/opt/studio-backend/src
- ./src:/app/studio-backend/src

networks:
codemod-local-network:
16 changes: 16 additions & 0 deletions apps/studio-backend/esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import esbuild from "esbuild";

esbuild
.build({
entryPoints: ["src/server.ts"],
bundle: true,
minify: true,
platform: "node",
outfile: "build/server.js",
external: ["@prisma/client", "pg-hstore"],
banner: {
js: `import { createRequire } from 'module';\nconst require = createRequire(import.meta.url);`,
},
format: "esm",
})
.catch(() => process.exit(1));
41 changes: 28 additions & 13 deletions apps/studio-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,65 @@
"name": "studio-backend",
"version": "1.0.0",
"scripts": {
"start:ncc": "node ./build-ncc/index.js",
"build": "node esbuild.config.js",
"start": "node build/server.js",
"test": "vitest --run",
"watch": "nodemon --exec ./node_modules/.bin/ts-node --esm ./src/index.ts",
"build:ncc": "ncc build ./src/index.ts -m -o ./build-ncc"
"watch": "pnpm db:generate && nodemon --exec ./node_modules/.bin/ts-node --esm ./src/server.ts",
"db:push": "prisma db push",
"db:generate": "prisma generate",
"db:migrate:generate": "prisma migrate dev --name",
"db:migrate:apply": "prisma migrate deploy",
"db:seed": "tsx prisma/seed.ts",
"db:studio": "prisma studio"
},
"author": "Codemod inc.",
"private": true,
"devDependencies": {
"@biomejs/biome": "1.5.3",
"@codemod-com/tsconfig": "workspace:*",
"@faker-js/faker": "^8.4.1",
"@types/node": "20.10.5",
"@types/parse-github-url": "1.0.3",
"@vercel/ncc": "0.38.1",
"@types/pg": "^8.11.2",
"esbuild": "^0.19.12",
"fastify-plugin": "4.5.1",
"nodemon": "3.0.2",
"sqlite3": "^5.1.7",
"ts-node": "10.9.2",
"tsx": "^4.7.1",
"typescript": "5.3.3",
"vitest": "1.1.0",
"@biomejs/biome": "1.5.3"
"vitest": "1.1.0"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.478.0",
"@clerk/fastify": "0.6.27",
"@aws-sdk/client-s3": "^3.525.0",
"@clerk/backend": "0.36.0",
"@clerk/fastify": "0.6.27",
"@effect/schema": "0.54.0",
"@fastify/busboy": "^2.1.0",
"@fastify/busboy": "^2.1.1",
"@fastify/cors": "8.5.0",
"@fastify/multipart": "^8.0.0",
"@fastify/multipart": "^8.1.0",
"@fastify/rate-limit": "9.0.1",
"@types/tar": "^6.1.10",
"@prisma/client": "5.10.2",
"@types/tar": "^6.1.11",
"ai": "2.2.29",
"axios": "1.6.2",
"chatgpt": "5.2.5",
"chromadb": "1.7.2",
"dotenv": "^16.4.5",
"fastify": "4.25.1",
"langchain": "0.0.209",
"lru-cache": "10.1.0",
"openai": "4.23.0",
"openai-edge": "1.2.2",
"parse-github-url": "1.0.2",
"pg": "^8.11.3",
"prisma": "^5.10.2",
"replicate": "0.25.2",
"sequelize": "^6.36.0",
"sequelize": "^6.37.1",
"tar": "^6.2.0",
"valibot": "^0.24.1"
"valibot": "^0.24.1",
"zod": "3.21.4",
"zod-prisma-types": "^3.1.6"
},
"type": "module",
"peerDependencies": {
Expand Down
Loading

0 comments on commit 6729324

Please sign in to comment.