- Update Gitea pipeline to build cnoc:node18, cnoc:node20, cnoc:node22 - Update local-dev.sh to use cnoc container from registry - Update documentation references from CNC to CNOC - Update default app package name to cnoc-default-app - Avoid conflict with existing nginx container (cnc) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
3.6 KiB
3.6 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Cloud Node Container (CNOC) is a Docker-based Node.js hosting environment that supports multiple Node.js versions (18, 20, 22) with Nginx reverse proxy, designed for both local development and production deployment.
Common Development Commands
Local Development Setup
# Quick start with automated setup (creates helper scripts and default app)
./local-dev.sh -n local-dev
# With specific Node.js version
./local-dev.sh -n myproject -a 22 # Node.js 22
# Helper scripts created by local-dev.sh:
./instance_start # Start container
./instance_stop # Stop container
./instance_logs # View container logs
./instance_shell # Access container shell
Building and Testing
# Build container locally
docker build -t cnoc:latest .
# Build with specific Node.js version
docker build --build-arg NODEVER=22 -t cnoc:node22 .
# Run container manually
docker run -d -p 80:80 -p 443:443 \
-e NODEVER=20 -e environment=DEV \
-e uid=$(id -u) -e user=$(whoami) -e domain=localhost \
-v"$(pwd)/user":/home/$(whoami) \
--name test-container cnoc:latest
Server Deployment
- Production git directory:
/root/whp
- After
git pull
, sync web files:rsync -av web-files/ /docker/whp/web/
Architecture and Key Components
Directory Structure
/scripts/
- Container setup scripts (entrypoint, Node.js installers, nginx config)/configs/
- Nginx, PM2, and default application configurations- User applications go in
/home/$user/app/
Container Behavior
-
Entrypoint Flow (
scripts/entrypoint.sh
):- Creates user with specified UID
- Sets up directory structure (/home/$user/app/, logs/)
- Configures Nginx reverse proxy based on environment variables
- In DEV mode: starts Memcached for session storage
- Starts Nginx and PM2-managed Node.js application
-
Environment Modes:
- DEV (
environment=DEV
): Local Memcached, automatic backups, verbose logging - PROD (default): Expects external services, optimized for production
- DEV (
-
Node.js Version Management:
- Controlled via
NODEVER
environment variable (18, 20, 22) - Each version has dedicated install script in
/scripts/
- PM2 ecosystem configuration adapts to user paths
- Controlled via
Key Environment Variables
uid
(required): User ID for file permissionsuser
(required): Username for container userdomain
(required): Primary domain for Nginx configurationserveralias
: Additional domains (comma-separated)NODEVER
: Node.js version to use (default: 20)environment
: DEV or PROD mode
Important Technical Details
- Health Check: Available at
/ping
endpoint (Node.js app must implement) - Logs Location:
/home/$user/logs/nginx/
and/home/$user/logs/nodejs/
- Application Backups (DEV mode): Every 30 minutes to
/home/$user/_backups/
- Log Rotation: Compress after 3 days, delete after 7 days
- SSL: Self-signed certificate auto-generated, Nginx handles SSL termination
- Static Files: Nginx serves from
/home/$user/app/public/
at/static/
path - Process Management: PM2 handles Node.js application lifecycle
Application Requirements
User applications in /home/$user/app/
should include:
package.json
with dependencies and scripts- Main application file (default:
index.js
) - Optional:
ecosystem.config.js
for PM2 configuration - Optional:
public/
directory for static assets
The container provides a default Express.js application with health endpoints and Memcached session support if no user application is found.