nimbusdotstorage-nimbus
SUCCESS
5m 25s
History Source
SummaryIterations1Transcript5Dockerfile
Dockerfile51 lines · 1425 chars
FROM oven/bun AS builder
WORKDIR /app

# Copy package files
COPY package.json bun.lock ./
COPY apps/server/package.json ./apps/server/
COPY packages/ ./packages/

# Install dependencies
RUN bun install

# Copy source code
COPY . .

# Build the application from server source directly (bypassing the tsc check in the npm script)
RUN bun build apps/server/src/index.ts --target bun --minify --outdir apps/server/dist

# Production image
FROM oven/bun AS runner
WORKDIR /app

# Set environment variables
ENV NODE_ENV=production
ENV PORT=1284

# Create non-root user
RUN groupadd -r nodejs && useradd -r -g nodejs nodejs

# Create app directory in runner
RUN mkdir -p /app/apps/server/dist /app/packages/db

# Copy built application and db package
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nodejs:nodejs /app/apps/server/dist/ /app/apps/server/dist/
COPY --from=builder --chown=nodejs:nodejs /app/packages/db /app/packages/db

# Switch to non-root user
USER nodejs

WORKDIR /app/apps/server

EXPOSE ${PORT}

# Optional: skip migrations at build time to avoid missing DB credentials during image build
# If needed, you can enable with build-time ARG DB_PUSH
ARG DB_PUSH
RUN ["bash", "-lc", "if [ -n \"$DB_PUSH\" ]; then bun --cwd /app/packages/db push; fi"]

# Start the application with db push (the actual run happens at container start)
CMD ["bun", "dist/index.js"]