From aa28a0456aeb190d7d9bb8c0044b96e49f54a639 Mon Sep 17 00:00:00 2001 From: Leo Wen <64514456+Leado123@users.noreply.github.com> Date: Sat, 6 Dec 2025 17:25:05 -0800 Subject: [PATCH] docker deploy --- .dockerignore | 51 ++++++++++++++++++++++++++++++++++++++++++++++ .env.example | 14 +++++++++++++ Dockerfile | 45 ++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f8b272f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,51 @@ +# Dependencies +node_modules + +# Git +.git +.gitignore +.gitattributes + +# Environment files +.env +.env.local +.env.*.local + +# IDE +.idea +.vscode +*.swp +*.swo + +# OS files +.DS_Store +Thumbs.db + +# Logs +*.log +npm-debug.log* + +# Build artifacts +dist +build + +# Test files +*.test.ts +*.spec.ts +__tests__ +coverage + +# Documentation +README.md +*.md + +# Docker +Dockerfile +docker-compose.yml +.dockerignore + +# Misc +*.txt +.graphqlconfig +vercel.json +scripts diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..34be52a --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +# Database Configuration +DATABASE_URL=postgresql://sms:smspassword@db:5432/smsdb?schema=public + +# PostgreSQL settings (used by docker-compose) +POSTGRES_USER=sms +POSTGRES_PASSWORD=smspassword +POSTGRES_DB=smsdb + +# JWT Secret Key - CHANGE THIS IN PRODUCTION! +SECRET_KEY=your-super-secret-key-change-me-in-production + +# Server Configuration +NODE_ENV=production +PORT=4000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..427c310 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# Use official Bun image +FROM oven/bun:1 AS base +WORKDIR /app + +# Install dependencies into a temp directory for caching +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lockb /temp/dev/ +RUN cd /temp/dev && bun install --frozen-lockfile + +# Install production dependencies only +RUN mkdir -p /temp/prod +COPY package.json bun.lockb /temp/prod/ +RUN cd /temp/prod && bun install --frozen-lockfile --production + +# Copy node_modules from temp directory and all source files +FROM base AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# Generate Prisma client +RUN bunx prisma generate + +# Final production image +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelease /app/src ./src +COPY --from=prerelease /app/prisma ./prisma +COPY --from=prerelease /app/package.json . +COPY --from=prerelease /app/tsconfig.json . +COPY --from=prerelease /app/node_modules/.prisma ./node_modules/.prisma +COPY --from=prerelease /app/node_modules/@prisma ./node_modules/@prisma + +# Create syllabi directory for file uploads +RUN mkdir -p /app/syllabi + +# Set environment variables +ENV NODE_ENV=production +ENV PORT=4000 + +# Expose port +EXPOSE 4000 + +# Run database migrations and start the application +CMD ["sh", "-c", "bunx prisma migrate deploy && bun run src/index.ts"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6afad2c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3.8" + +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "4000:4000" + environment: + - NODE_ENV=production + - DATABASE_URL=postgresql://${POSTGRES_USER:-sms}:${POSTGRES_PASSWORD:-smspassword}@db:5432/${POSTGRES_DB:-smsdb}?schema=public + - SECRET_KEY=${SECRET_KEY:-your-secret-key-change-in-production} + depends_on: + db: + condition: service_healthy + volumes: + - syllabi_data:/app/syllabi + restart: unless-stopped + + db: + image: postgres:16-alpine + environment: + - POSTGRES_USER=${POSTGRES_USER:-sms} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-smspassword} + - POSTGRES_DB=${POSTGRES_DB:-smsdb} + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-sms} -d ${POSTGRES_DB:-smsdb}"] + interval: 5s + timeout: 5s + retries: 5 + restart: unless-stopped + +volumes: + postgres_data: + syllabi_data: