Add Docker deployment support for Dokploy
- Add Dockerfile with multi-stage build - Add docker-compose.yml with Traefik labels - Add .dockerignore for optimal build context - Update next.config.ts for standalone output - Update DEPLOYMENT.md with Dokploy instructions Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
51
.dockerignore
Normal file
51
.dockerignore
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# Dependencies
|
||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
|
||||||
|
# Next.js
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# Debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Local env files
|
||||||
|
.env
|
||||||
|
.env*.local
|
||||||
|
.env.production
|
||||||
|
|
||||||
|
# Vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# TypeScript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
README.md
|
||||||
|
DEPLOYMENT.md
|
||||||
|
|
||||||
|
# BMAD (development only)
|
||||||
|
_bmad
|
||||||
|
_agent
|
||||||
|
.claude
|
||||||
148
DEPLOYMENT.md
148
DEPLOYMENT.md
@@ -1,12 +1,12 @@
|
|||||||
# Deployment Instructions - Test01
|
# Deployment Instructions - Brachnha Insights
|
||||||
|
|
||||||
This guide provides instructions for deploying the **Test01** application to production environments.
|
This guide provides instructions for deploying **Brachnha Insights** to production environments.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- **Node.js**: v18 or higher
|
- **Node.js**: v18 or higher
|
||||||
- **npm**: v9 or higher
|
- **npm**: v9 or higher
|
||||||
- **Vercel Account** (Recommended for hosting)
|
- **Docker** & **Docker Compose** (for Dokploy deployment)
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
@@ -20,52 +20,138 @@ Ensure the following environment variables are configured in your production env
|
|||||||
|
|
||||||
> **Note:** The application uses a local-first architecture (IndexedDB), so no external database connection strings (Postgres/MySQL) are required for the core journaling features.
|
> **Note:** The application uses a local-first architecture (IndexedDB), so no external database connection strings (Postgres/MySQL) are required for the core journaling features.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Deployment Options
|
## Deployment Options
|
||||||
|
|
||||||
### Option 1: Vercel (Recommended)
|
### Option 1: Dokploy with Docker Compose (Recommended for Self-Hosting)
|
||||||
|
|
||||||
|
Dokploy provides an easy way to deploy and manage your applications with Docker.
|
||||||
|
|
||||||
|
#### Files Included
|
||||||
|
- `Dockerfile` - Multi-stage build for optimal image size
|
||||||
|
- `docker-compose.yml` - Service configuration with Traefik labels
|
||||||
|
- `.dockerignore` - Excludes unnecessary files from build
|
||||||
|
|
||||||
|
#### Deployment Steps
|
||||||
|
|
||||||
|
**1. Deploy from Git Repository (Recommended)**
|
||||||
|
|
||||||
|
In your Dokploy Dashboard:
|
||||||
|
- Click "Create Project"
|
||||||
|
- Select "Compose" as project type
|
||||||
|
- Choose "From Git Repository"
|
||||||
|
- Enter your Git URL: `https://gitea.brachnha.com/Brachnha/brachnha-insight.git`
|
||||||
|
- Add your Git credentials (token)
|
||||||
|
- Set branch to `master`
|
||||||
|
- Click "Create"
|
||||||
|
|
||||||
|
**2. Configure Domain (Optional)**
|
||||||
|
|
||||||
|
Edit `docker-compose.yml` and replace `your-domain.com`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
labels:
|
||||||
|
- "traefik.http.routers.brachnha-insights.rule=Host(`insights.brachnha.com`)"
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Deploy**
|
||||||
|
- Click "Deploy" button in Dokploy
|
||||||
|
- Dokploy will build and start the container
|
||||||
|
|
||||||
|
**Manual Deployment (Alternative)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone repository
|
||||||
|
git clone https://gitea.brachnha.com/Brachnha/brachnha-insight.git
|
||||||
|
cd brachnha-insight
|
||||||
|
|
||||||
|
# Build and start
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
**Updating:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git pull origin master
|
||||||
|
docker-compose down
|
||||||
|
docker-compose build
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Or trigger a redeploy from the Dokploy dashboard.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Option 2: Vercel (Recommended for Managed Hosting)
|
||||||
|
|
||||||
Vercel provides the best support for Next.js applications, including PWA headers and caching.
|
Vercel provides the best support for Next.js applications, including PWA headers and caching.
|
||||||
|
|
||||||
1. **Push to GitHub**: Ensure your code is pushed to a remote repository.
|
1. **Push to GitHub**: Ensure your code is pushed to a remote repository.
|
||||||
2. **Import Project**: Go to [Vercel Dashboard](https://vercel.com/new) and import your repository.
|
2. **Import Project**: Go to [Vercel Dashboard](https://vercel.com/new) and import your repository.
|
||||||
3. **Configure**:
|
3. **Configure**:
|
||||||
- **Framework Preset**: Next.js
|
- **Framework Preset**: Next.js
|
||||||
- **Build Command**: `next build`
|
- **Build Command**: `next build`
|
||||||
- **Output Directory**: `.next`
|
- **Output Directory**: `.next`
|
||||||
- **Environment Variables**: Add any keys defined above.
|
- **Environment Variables**: Add any keys defined above.
|
||||||
4. **Deploy**: Click "Deploy".
|
4. **Deploy**: Click "Deploy".
|
||||||
|
|
||||||
Vercel will automatically detect the `manifest.webmanifest` and service worker configurations.
|
Vercel will automatically detect the `manifest.webmanifest` and service worker configurations.
|
||||||
|
|
||||||
### Option 2: Docker / Custom Server
|
---
|
||||||
|
|
||||||
|
### Option 3: Traditional Node.js Server
|
||||||
|
|
||||||
To deploy as a standalone Node.js application:
|
To deploy as a standalone Node.js application:
|
||||||
|
|
||||||
1. **Build the application**:
|
1. **Build the application**:
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
2. **Start the server**:
|
2. **Start the server**:
|
||||||
```bash
|
```bash
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
The app will be available at `http://localhost:3000`.
|
The app will be available at `http://localhost:3000`.
|
||||||
|
|
||||||
**Docker Strategy:**
|
Use a process manager like PM2 for production:
|
||||||
You can use the official [Next.js Docker example](https://github.com/vercel/next.js/tree/canary/examples/with-docker) for a containerized deployment.
|
```bash
|
||||||
|
npm install -g pm2
|
||||||
|
pm2 start npm --name "brachnha-insights" -- start
|
||||||
|
pm2 startup
|
||||||
|
pm2 save
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Docker/Dokploy Issues
|
||||||
|
|
||||||
|
**Container won't start:**
|
||||||
|
```bash
|
||||||
|
docker-compose logs brachnha-insights
|
||||||
|
```
|
||||||
|
|
||||||
|
**Build fails:**
|
||||||
|
- Ensure `next.config.ts` has `output: 'standalone'`
|
||||||
|
- Check that all dependencies are in `package.json`
|
||||||
|
|
||||||
|
**Port conflicts:**
|
||||||
|
- Change the port mapping in `docker-compose.yml`
|
||||||
|
- Update the Traefik labels accordingly
|
||||||
|
|
||||||
### Build Failures
|
### Build Failures
|
||||||
|
|
||||||
- **Google Fonts / Network Errors**: The build process requires internet access to download fonts from Google. If building in a restricted environment (like a corporate firewall or offline CI), you may see TLS/Network errors.
|
- **Google Fonts / Network Errors**: The build process requires internet access to download fonts from Google. If building in a restricted environment (like a corporate firewall or offline CI), you may see TLS/Network errors.
|
||||||
- *Workaround*: Set `NEXT_TURBOPACK_EXPERIMENTAL_USE_SYSTEM_TLS_CERTS=1` or temporarily disable `next/font/google` in `src/app/layout.tsx`.
|
- *Workaround*: Set `NEXT_TURBOPACK_EXPERIMENTAL_USE_SYSTEM_TLS_CERTS=1` or temporarily disable `next/font/google` in `src/app/layout.tsx`.
|
||||||
- **Manifest Errors**: If you see `manifest.ts` type errors, ensure you are using a compatible Next.js version (14+ recommended) or check `purpose` fields in icon definitions.
|
|
||||||
|
- **Manifest Errors**: If you see `manifest.ts` type errors, ensure you are using a compatible Next.js version (14+ recommended) or check `purpose` fields in icon definitions.
|
||||||
|
|
||||||
### PWA Verification
|
### PWA Verification
|
||||||
|
|
||||||
After deployment, verify the PWA features:
|
After deployment, verify the PWA features:
|
||||||
1. Open the deployed URL (e.g., `https://test01.vercel.app`) on a mobile device or Chrome.
|
1. Open the deployed URL on a mobile device or Chrome.
|
||||||
2. Look for the "Install Test01" prompt (bottom banner) or the Install icon in the address bar.
|
2. Look for the "Install Brachnha Insights" prompt (bottom banner) or the Install icon in the address bar.
|
||||||
3. Install the app and verify it opens in standalone mode.
|
3. Install the app and verify it opens in standalone mode.
|
||||||
4. Disconnect internet and verify you can still create/save drafts (Offline support).
|
4. Disconnect internet and verify you can still create/save drafts (Offline support).
|
||||||
|
|||||||
50
Dockerfile
Normal file
50
Dockerfile
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Build stage
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy all source files
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Production stage
|
||||||
|
FROM node:20-alpine AS runner
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Set environment to production
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
# Create a non-root user
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
# Copy necessary files from builder
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder /app/.next/standalone ./
|
||||||
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# Change ownership to nextjs user
|
||||||
|
RUN chown -R nextjs:nodejs /app
|
||||||
|
|
||||||
|
# Switch to nextjs user
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
# Expose port 3000
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Set hostname
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
|
||||||
|
# Start the application
|
||||||
|
CMD ["node", "server.js"]
|
||||||
23
docker-compose.yml
Normal file
23
docker-compose.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
services:
|
||||||
|
brachnha-insights:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: brachnha-insights
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
networks:
|
||||||
|
- dokploy-network
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.brachnha-insights.rule=Host(`your-domain.com`)"
|
||||||
|
- "traefik.http.routers.brachnha-insights.tls=true"
|
||||||
|
- "traefik.http.routers.brachnha-insights.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.services.brachnha-insights.loadbalancer.server.port=3000"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
dokploy-network:
|
||||||
|
external: true
|
||||||
@@ -2,6 +2,7 @@ import type { NextConfig } from "next";
|
|||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
/* config options here */
|
/* config options here */
|
||||||
|
output: 'standalone',
|
||||||
experimental: {
|
experimental: {
|
||||||
optimizePackageImports: ['lucide-react']
|
optimizePackageImports: ['lucide-react']
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user