Skip to content
Merged
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ dist
build
.turbo


27 changes: 7 additions & 20 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,24 @@ jobs:
uses: actions/checkout@v5

- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v5
with:
node-version: "20"
node-version: "22"

- name: Install bun
uses: oven-sh/setup-bun@v2

- name: Cache Bun dependencies
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
node_modules
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Install dependencies
run: npm install -g pnpm && pnpm install --frozen-lockfile

- name: Cache Next.js build
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lockb') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lockb') }}-

- name: Install dependencies
run: bun install
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-

- name: Run tests
run: bun run build
run: npm run build
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXT_PUBLIC_STREAM_API_KEY: ${{ secrets.NEXT_PUBLIC_STREAM_API_KEY }}
Expand Down
70 changes: 45 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
FROM oven/bun:1.2-debian AS base
WORKDIR /app
FROM node:23-alpine AS base

FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lock /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# Required for some native modules on Alpine
RUN apk add --no-cache libc6-compat

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lock /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
ENV NODE_ENV=production
ENV NPM_CONFIG_REGISTRY=https://registry.npmjs.org/
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate

FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
FROM base AS deps
ENV HUSKY=0
ENV SKIP_HUSKY=1

# Use Node.js for build (Bun has compatibility issues with Next.js 16 Turbopack)
FROM node:20-slim AS build
# Copy package files only to cache deps layer
COPY package.json pnpm-lock.yaml .npmrc* ./
RUN corepack enable pnpm && pnpm install --frozen-lockfile

FROM base AS builder
WORKDIR /app
COPY --from=prerelease /app ./
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Ensure standalone output is generated
ENV NEXT_PRIVATE_STANDALONE=true
ARG NEXT_PUBLIC_APP_URL
ARG DATABASE_URL
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
ENV DATABASE_URL=$DATABASE_URL
RUN npm run build
RUN corepack enable pnpm && pnpm run build

FROM base AS release
FROM node:23-alpine AS runner
WORKDIR /app
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static/
COPY --from=build /app/public ./public
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

# Create non-root user
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

# Fix permissions: remove write where not needed and add execute where required
# Ensure .next cache exists and is owned by nextjs so server can write runtime cache
RUN mkdir -p .next/cache && \
chown -R nextjs:nodejs .next /app && \
chmod -R u+rwX .next && chmod -R u+rwX .next/cache && \
chmod -R a-w+x . && chmod -R a+x .next node_modules

USER nextjs

EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="localhost"
ENV NETWORK="0.0.0.0"
CMD ["bun", "server.js"]
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
Loading