Skip to content
/ dcyfr-ai-docker Public template

Docker and containerization templates for deploying DCYFR AI applications.

License

Notifications You must be signed in to change notification settings

dcyfr/dcyfr-ai-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@dcyfr/ai-docker

Ask DeepWiki

Docker License: MIT

Production-ready Docker containerization templates for DCYFR AI applications.

Multi-stage Dockerfiles, Docker Compose configurations, Nginx reverse proxy, health checks, security hardening, and Kubernetes manifests β€” all designed to work with any DCYFR AI template.

πŸ“¦ Starter Template β€” This is a starter template for cloning, not an npm package. Use git clone or download the source to add Docker support to your application. This package is marked private: true and is not published to npm.

✨ Features

  • 🐳 Multi-Stage Builds β€” Optimized layer caching, minimal production images
  • πŸ”’ Security Hardened β€” Non-root user, read-only filesystem, no-new-privileges
  • πŸ₯ Health Checks β€” Container-level, HTTP, database, and Redis health probes
  • πŸ”„ Hot Reload β€” Development Dockerfile with bind mounts and debug port
  • 🌐 Nginx Reverse Proxy β€” Rate limiting, gzip, security headers, WebSocket support
  • πŸ“¦ Docker Compose β€” Development and production configurations
  • ☸️ Kubernetes Ready β€” Deployment, Service, HPA, and Ingress manifests
  • πŸ›‘οΈ Dockerfile Validator β€” Lint Dockerfiles against DCYFR best practices
  • βš™οΈ Generator β€” Programmatically generate Docker configs for any app type
  • πŸ“Š Resource Management β€” CPU/memory limits, restart policies

πŸš€ Quick Start

Development

# Start development stack (app + Postgres + Redis)
docker compose up

# Start in background
docker compose up -d

# View logs
docker compose logs -f

# Stop
docker compose down

Production

# Create .env from template
cp .env.example .env
# Edit .env with production values

# Build and start production stack
docker compose -f docker-compose.prod.yml up -d

# View logs
docker compose -f docker-compose.prod.yml logs -f

Build Only

# Build production image
./scripts/build.sh

# Build with custom tag
./scripts/build.sh --tag v1.0.0

# Build development image
./scripts/build.sh --dev

πŸ“ Project Structure

dcyfr-ai-docker/
β”œβ”€β”€ Dockerfile                 # Production multi-stage build
β”œβ”€β”€ Dockerfile.dev             # Development with hot reload
β”œβ”€β”€ docker-compose.yml         # Development stack
β”œβ”€β”€ docker-compose.prod.yml    # Production stack (Nginx + security)
β”œβ”€β”€ .dockerignore              # Build context exclusions
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts               # Public API exports
β”‚   β”œβ”€β”€ types.ts               # Zod schemas & TypeScript types
β”‚   β”œβ”€β”€ validator.ts           # Dockerfile linter (10 rules)
β”‚   β”œβ”€β”€ generator.ts           # Dockerfile & Compose generator
β”‚   β”œβ”€β”€ validate.ts            # CLI: validate a Dockerfile
β”‚   └── generate.ts            # CLI: generate Docker configs
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ nginx.conf             # Production Nginx configuration
β”‚   └── health-check.sh        # Container health check script
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ build.sh               # Build Docker images
β”‚   β”œβ”€β”€ run.sh                 # Run Docker stack
β”‚   └── deploy.sh              # Build, tag, push to registry
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ full-stack.yml         # Full-stack (app + DB + Redis + Nginx)
β”‚   β”œβ”€β”€ microservices.yml      # Multi-service architecture
β”‚   └── kubernetes/
β”‚       β”œβ”€β”€ deployment.yaml    # K8s Deployment + Service + HPA
β”‚       └── ingress.yaml       # K8s Ingress with TLS
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ validator.test.ts      # Validator tests
β”‚   └── generator.test.ts      # Generator tests
└── docs/
    β”œβ”€β”€ DEVELOPMENT.md         # Development workflow guide
    β”œβ”€β”€ PRODUCTION.md          # Production deployment guide
    └── TROUBLESHOOTING.md     # Common issues & solutions

πŸ” Dockerfile Validator

Validate any Dockerfile against 10 best-practice rules:

# Validate the included Dockerfile
npm run validate

# Validate a custom Dockerfile
npm run validate -- path/to/Dockerfile

Rules checked:

Rule Severity Description
no-root-user Error Container must not run as root
no-secrets-in-env Error No secrets in ENV instructions
workdir-set Error WORKDIR must be explicitly set
no-latest-tag Warning Pin base image versions
healthcheck-present Warning Include HEALTHCHECK instruction
use-multi-stage Warning Use multi-stage builds
no-add-instruction Warning Prefer COPY over ADD
copy-package-first Warning Copy package.json before source
npm-ci-over-install Warning Use npm ci for reproducibility
cache-clean Warning Clean npm cache after install

βš™οΈ Configuration Generator

Programmatically generate Docker configurations:

# Generate for API with Postgres and Redis
npm run generate -- --type api --db postgres --redis

# Generate production only
npm run generate -- --target production

# Generate to custom directory
npm run generate -- --output ./my-project

Programmatic API

import { generateDockerfile, generateProject, validateDockerfile } from '@dcyfr/ai-docker';

// Generate a Dockerfile
const dockerfile = generateDockerfile({
  nodeVersion: '22-alpine',
  port: 3000,
  multiStage: true,
  nonRoot: true,
  healthCheck: true,
});

// Generate full project
const files = generateProject({
  appType: 'api',
  database: 'postgres',
  redis: true,
  target: 'both',
});

// Validate
const result = validateDockerfile(dockerfile);
console.log(result.score); // 100

πŸ—οΈ Architecture

Multi-Stage Build (Production)

Stage 1: deps        β†’ npm ci --omit=dev (production deps only)
Stage 2: build       β†’ npm ci + tsc (compile TypeScript)
Stage 3: production  β†’ Copy deps + dist (minimal final image)

Security Hardening

  • Non-root user: dcyfr:nodejs (UID/GID 1001)
  • Read-only filesystem: read_only: true in production compose
  • No new privileges: security_opt: no-new-privileges:true
  • Resource limits: CPU and memory constraints per service
  • Health checks: HTTP endpoint monitoring at /health
  • Secrets management: Required env vars with ${VAR:?error} syntax

Nginx Reverse Proxy

  • Rate limiting: 30 req/s API, 5 req/s auth endpoints
  • Gzip compression for text/JSON/XML/SVG
  • Security headers (CSP, X-Frame-Options, HSTS-ready)
  • WebSocket upgrade support
  • Keepalive connections to upstream

πŸ§ͺ Testing

npm test              # Run all tests
npm run test:watch    # Watch mode
npm run test:coverage # Coverage report

πŸ“¦ Compatibility

Works with all DCYFR AI templates:

Template Supported Notes
dcyfr-ai-agents βœ… Agent server containerization
dcyfr-ai-rag βœ… RAG pipeline + vector DB
dcyfr-ai-graphql βœ… GraphQL API server
dcyfr-ai-api βœ… REST API server
dcyfr-ai-web βœ… Next.js full-stack
dcyfr-ai-react βœ… Static SPA (Nginx serve)
dcyfr-ai-nodejs βœ… Express server
dcyfr-ai-code-gen βœ… Code generation service

🀝 Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

πŸ“„ License

MIT β€” see LICENSE for details.


Built with ❀️ by DCYFR | GitHub

About

Docker and containerization templates for deploying DCYFR AI applications.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •