prepare for oss release: docker compose

This commit is contained in:
ajvpot
2025-08-01 00:00:00 +00:00
parent f8584f8e1c
commit 47af653db6
5 changed files with 223 additions and 1 deletions

71
.dockerignore Normal file
View File

@@ -0,0 +1,71 @@
# Dependencies
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Next.js build output
.next
out
# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# IDE and editor files
.vscode
.idea
*.swp
*.swo
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Git
.git
.gitignore
# Docker
Dockerfile
.dockerignore
docker-compose.yml
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Dependency directories
jspm_packages/
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity

56
Dockerfile Normal file
View File

@@ -0,0 +1,56 @@
# syntax=docker/dockerfile:1
FROM node:20-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json package-lock.json* ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the application with BuildKit caching for .next directory
RUN --mount=type=cache,target=/app/.next/cache \
npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /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
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# 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
USER nextjs
EXPOSE 3000
ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]

View File

@@ -29,6 +29,15 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
## Environment Variables ## Environment Variables
### ClickHouse Database Configuration
The application connects to ClickHouse using the following environment variables:
- `CLICKHOUSE_HOST` - ClickHouse server hostname (default: `localhost`)
- `CLICKHOUSE_PORT` - ClickHouse server port (default: `8123`)
- `CLICKHOUSE_USER` - ClickHouse username (default: `default`)
- `CLICKHOUSE_PASSWORD` - ClickHouse password (default: `password`)
### `NEXT_PUBLIC_API_URL` ### `NEXT_PUBLIC_API_URL`
This environment variable allows you to override the API base URL for frontend development purposes. When set, all API calls will be made to the specified URL instead of using relative URLs. This environment variable allows you to override the API base URL for frontend development purposes. When set, all API calls will be made to the specified URL instead of using relative URLs.
@@ -64,6 +73,69 @@ The middleware applies the following CORS headers to all `/api/*` routes:
- [MeshCore](https://github.com/your-org/meshcore) - mesh network backend - [MeshCore](https://github.com/your-org/meshcore) - mesh network backend
- [Meshtastic](https://meshtastic.org/) - open source mesh communication project - [Meshtastic](https://meshtastic.org/) - open source mesh communication project
## Docker Deployment
The application includes Docker support for easy deployment. The Docker configuration is set up to connect to ClickHouse running on the Docker host.
### Prerequisites
- Docker and Docker Compose installed
- ClickHouse running on the Docker host (default port 8123)
- External Docker network `shared-network` must exist (see setup instructions below)
### External Network Setup
The application requires an external Docker network called `shared-network` to communicate with ClickHouse. You must create this network before running the application:
```bash
docker network create shared-network
```
**Note**: If the network already exists, this command will show an error but can be safely ignored.
### Running with Docker Compose
1. **Create the required external network (if not already created):**
```bash
docker network create shared-network
```
2. **Build and start the application:**
```bash
docker-compose up --build
```
3. **Access the application:**
Open [http://localhost:3001](http://localhost:3001) in your browser.
### Docker Configuration
The `docker-compose.yml` file is configured with:
- **Port mapping**: Container port 3000 → Host port 3001
- **ClickHouse connection**: Uses `clickhouse` hostname to connect to ClickHouse via the shared network
- **External network**: Requires `shared-network` to be created externally
- **Environment variables**: Pre-configured for typical ClickHouse setup
### Customizing ClickHouse Connection
You can customize the ClickHouse connection by modifying the environment variables in `docker-compose.yml`:
```yaml
environment:
- CLICKHOUSE_HOST=your-clickhouse-host
- CLICKHOUSE_PORT=8123
- CLICKHOUSE_USER=your-username
- CLICKHOUSE_PASSWORD=your-password
```
### Building with BuildKit
For faster builds with caching, enable BuildKit:
```bash
DOCKER_BUILDKIT=1 docker-compose up --build
```
## Deploy ## Deploy
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

23
docker-compose.yml Normal file
View File

@@ -0,0 +1,23 @@
version: '3.8'
services:
meshexplorer:
build:
context: .
dockerfile: Dockerfile
ports:
- "3001:3000"
environment:
- NODE_ENV=production
- CLICKHOUSE_HOST=clickhouse
- CLICKHOUSE_PORT=8123
- CLICKHOUSE_USER=default
- CLICKHOUSE_PASSWORD=password
restart: unless-stopped
init: true
networks:
- shared-network
networks:
shared-network:
external: true

View File

@@ -1,7 +1,7 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ output: 'standalone',
}; };
export default nextConfig; export default nextConfig;