Deployment Guide

Learn how to deploy your ShipKit application to production

Deployment Guide

This guide will walk you through deploying your ShipKit application to production. We'll cover best practices, monitoring, and scaling considerations.

Prerequisites

Before you begin, make sure you have:

  • Basic Next.js knowledge
  • Git basics understanding
  • Node.js installed
  • Access to a deployment platform (Vercel, AWS, etc.)

Deployment Options

ShipKit supports multiple deployment options:

1. Vercel (Recommended)

The easiest way to deploy your ShipKit application:

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

2. Docker

For containerized deployments:

FROM node:18-alpine AS base

# Install dependencies
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN npm install -g pnpm
RUN pnpm install --frozen-lockfile

# Build the application
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build

# Production image
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production

COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]

3. Traditional Hosting

For traditional Node.js hosting:

# Build the application
pnpm build

# Start the production server
pnpm start

Environment Setup

  1. Create a .env.production file:
# Database
DATABASE_URL=your_production_db_url

# Authentication
NEXTAUTH_URL=https://your-domain.com
NEXTAUTH_SECRET=your_production_secret

# Email
RESEND_API_KEY=your_resend_api_key

# Other Services
BUILDER_PUBLIC_KEY=your_builder_key
  1. Configure your deployment platform with these environment variables

Production Checklist

Before deploying to production:

  • [ ] Run production build locally
  • [ ] Test all environment variables
  • [ ] Configure proper security headers
  • [ ] Set up monitoring and logging
  • [ ] Configure proper caching
  • [ ] Set up proper database indexes
  • [ ] Configure rate limiting
  • [ ] Set up error tracking

Monitoring and Logging

ShipKit comes with built-in monitoring support:

// Configure monitoring in your app
import { setupMonitoring } from '@/lib/monitoring';

setupMonitoring({
  service: 'your-service-name',
  environment: 'production',
});

Scaling Considerations

Database Scaling

  • Use connection pooling
  • Implement proper indexes
  • Consider read replicas
  • Set up proper backups

Application Scaling

  • Use proper caching strategies
  • Implement rate limiting
  • Consider serverless functions
  • Use CDN for static assets

Security Best Practices

  1. Enable security headers:
// next.config.js
const securityHeaders = [
  {
    key: 'X-DNS-Prefetch-Control',
    value: 'on',
  },
  {
    key: 'Strict-Transport-Security',
    value: 'max-age=63072000; includeSubDomains; preload',
  },
  // ... more headers
];

module.exports = {
  headers: async () => [
    {
      source: '/:path*',
      headers: securityHeaders,
    },
  ],
};
  1. Configure CORS properly
  2. Implement rate limiting
  3. Use secure session configuration
  4. Enable proper error handling

Troubleshooting

Common deployment issues and solutions:

Build Failures

# Clear cache and node_modules
rm -rf .next node_modules
pnpm install
pnpm build

Database Connection Issues

// Implement connection retry logic
const connectDB = async (retries = 5) => {
  try {
    await db.connect();
  } catch (error) {
    if (retries > 0) {
      await new Promise(r => setTimeout(r, 5000));
      return connectDB(retries - 1);
    }
    throw error;
  }
};

Next Steps

After deployment:

  1. Set up continuous integration
  2. Configure automated testing
  3. Implement proper backup strategies
  4. Set up alerting
  5. Monitor performance

Related Resources