Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bunify? #205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 28 additions & 53 deletions www/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,43 @@
# https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
FROM oven/bun:1 AS base
WORKDIR /usr/src/app

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache --virtual .gyp python3 build-base libc6-compat
WORKDIR /app
# Install dependencies into temp directory
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 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 corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb* /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# Rebuild the source code only when needed
# Build stage
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1


RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

# Build the app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
RUN bun run build

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Production stage
FROM base AS release
WORKDIR /app

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy production dependencies and built app
COPY --from=install /temp/prod/node_modules ./node_modules
COPY --from=builder /usr/src/app/.next/standalone ./
COPY --from=builder /usr/src/app/.next/static ./.next/static
COPY --from=builder /usr/src/app/public ./public

USER nextjs
# Run as non-root user
RUN addgroup --system --gid 1001 bunjs
RUN adduser --system --uid 1001 bunapp
USER bunapp

EXPOSE 3000

ENV PORT=3000
# set hostname to localhost
ENV HOSTNAME="0.0.0.0"

CMD ["node", "server.js"]
CMD ["bun", "run", "server.js"]
7 changes: 3 additions & 4 deletions www/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tutor-GPT Web UI

This directory contains the code for the Full Stack Web-UI of Tutor-GPT. It is developed
using [Next.js](https://nextjs.org/) and [pnpm](https://pnpm.io).
using [Next.js](https://nextjs.org/) and [bun](https://bun.sh/).

The project uses [Supabase](https://supabase.com/) for authentication and managing users subscriptions
with [stripe](https://stripe.com/)
Expand All @@ -12,14 +12,14 @@ Clone the repo and install the necessary NodeJS depenencies

```bash
git clone https://github.com/plastic-labs/tutor-gpt.git && cd tutor-gpt/www
pnpm install
bun install
```

Set up your [environment variables](#environment-variables) in a `.env.local`
file. Then launch the development server.

```bash
pnpm run dev
bun run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
Expand Down Expand Up @@ -55,7 +55,6 @@ Tutor-GPT webui. A `.env.template` file is provided to get started quickly.
- `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` — The stripe public key
- `STRIPE_WEBHOOK_SECRET` — The stripe webhook secret


Below are several optional environment variables to enable error monitoring and
analytics.

Expand Down
Binary file added www/bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion www/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "Tutor GPT Web App",
"name": "tutor-gpt",
"version": "0.6.0",
"private": true,
"scripts": {
"dev": "next dev",
"db": "supabase start",
"db:stop": "supabase stop",
"build": "next build",
"start": "next start",
"lint": "eslint components/ app/ utils/",
Expand Down
Loading
Loading