BUILD CONFIG - nself-org/cli GitHub Wiki
Configure how nself builds your Docker Compose stack and generates service configurations.
The nself build command:
- Reads
.envfiles - Validates configuration
- Generates
docker-compose.yml - Creates service configurations
- Sets up Nginx routes
- Generates SSL certificates
nself buildThis uses your current .env file and generates all configs.
nself build --cleanRemoves old generated files and builds fresh.
nself build --validateChecks configuration without generating files.
nself build --dry-runShows what would be generated without actually creating files.
The base configuration, committed to git. All developers use this as their starting point.
# Project Identification
PROJECT_NAME=my-app
ENV=dev
BASE_DOMAIN=localhost
# Required Services
POSTGRES_DB=myapp_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=change-me
# Hasura
HASURA_GRAPHQL_ADMIN_SECRET=change-me
HASURA_GRAPHQL_ENABLE_CONSOLE=true
# Server
NGINX_PORT=8080
# Optional Services
REDIS_ENABLED=false
MINIO_ENABLED=falseYour local machine overrides. Gitignored, never committed.
# Override only what you need
POSTGRES_PASSWORD=my-local-password
HASURA_GRAPHQL_ADMIN_SECRET=my-local-secret
REDIS_ENABLED=trueSet *_ENABLED=true in .env:
# Cache & Sessions
REDIS_ENABLED=true
REDIS_PORT=6379
REDIS_MEMORY=256mb
# File Storage
MINIO_ENABLED=true
MINIO_PORT=9000
MINIO_ADMIN_USER=minioadmin
MINIO_ADMIN_PASSWORD=change-me
# Monitoring
MONITORING_ENABLED=trueAdd your own services using CS_N:
# Format: CS_N=service_name:template:port
# Express.js API
CS_1=api:express-js:8001
# Node.js Worker
CS_2=worker:bullmq-js:8002
# Python API
CS_3=ml-api:fastapi:8003
# Go gRPC Service
CS_4=grpc:go-grpc:8004Available templates:
- Node.js: express-js, nestjs, fastify, koa
- Python: fastapi, flask, django
- Go: gin, echo, fiber, grpc
- Java: spring-boot, quarkus
- Rust: actix, rocket, axum
- And 30+ more...
Route external applications (running outside Docker):
# Frontend App 1
FRONTEND_APP_1_NAME=web
FRONTEND_APP_1_PORT=3000
FRONTEND_APP_1_ROUTE=app
# Frontend App 2
FRONTEND_APP_2_NAME=admin
FRONTEND_APP_2_PORT=3001
FRONTEND_APP_2_ROUTE=adminResult:
-
app.localhost:8080โlocalhost:3000 -
admin.localhost:8080โlocalhost:3001
After nself build, the following files are created:
Main orchestration file defining all services:
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_DB: myapp_db
volumes:
- postgres_data:/var/lib/postgresql/data
hasura:
image: hasura/graphql-engine:latest
depends_on:
- postgres
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://...
HASURA_GRAPHQL_ADMIN_SECRET: change-me
# ... more servicesAuto-generated computed values (do NOT edit):
# Generated database URL
DATABASE_URL=postgresql://postgres:password@postgres:5432/myapp_db
# Generated docker network name
DOCKER_NETWORK=my-app_network
# Generated service names
POSTGRES_HOST=postgres
HASURA_HOST=hasuraNginx configuration files:
nginx/
โโโ nginx.conf # Main config
โโโ includes/
โ โโโ gzip.conf # Compression
โ โโโ security.conf # Security headers
โ โโโ proxy.conf # Proxy settings
โโโ sites/
โ โโโ api.conf # Hasura routing
โ โโโ auth.conf # Auth service routing
โ โโโ custom.conf # Custom service routing
โโโ ssl/
โโโ cert.pem # Self-signed certificate
โโโ key.pem # Private key
Generated custom service directories:
services/
โโโ api/ # Generated from CS_1
โ โโโ Dockerfile
โ โโโ package.json
โ โโโ src/
โ โ โโโ index.js
โ โโโ .dockerignore
โโโ worker/ # Generated from CS_2
โ โโโ Dockerfile
โ โโโ requirements.txt
โ โโโ app.py
Specify Docker Compose format version in .env:
# Default: 3.8 (recommended)
DOCKER_COMPOSE_VERSION=3.8# Network name (auto-generated from PROJECT_NAME)
# my-app_network
# Change network driver
DOCKER_NETWORK_DRIVER=bridge
# Enable external network
DOCKER_NETWORK_EXTERNAL=false# Persistent data directory
VOLUMES_PATH=/var/lib/nself/volumes
# Database backup directory
BACKUP_PATH=/var/backups/nself
# Database size limit
POSTGRES_MAX_SIZE=100gb# Default: 8080
NGINX_PORT=8080
# Custom port
NGINX_PORT=3000Each service has a default port (can be overridden):
# Redis port
REDIS_PORT=6379
# MinIO port
MINIO_PORT=9000
# Custom services
CS_1=api:express-js:8001
CS_2=worker:bullmq-js:8002nself binds services to 127.0.0.1 (localhost only) by default.
For external access, use Nginx routing:
# In .env
BASE_DOMAIN=myapp.com # Routes via HTTPS
# Nginx automatically exposes:
# - hasura.myapp.com โ Hasura
# - auth.myapp.com โ Auth service
# - api.myapp.com โ Custom servicesFor custom services, edit the generated Dockerfile:
# Generated at:
services/api/Dockerfile
# Edit it:
vim services/api/Dockerfile
# Rebuild
nself buildGenerated files are not overwritten on subsequent builds (preserves your changes).
Build uses this cascade for environment variables:
-
.env.dev(committed, shared) -
.env.local(on your machine) -
.env.staging(on staging server only) -
.env.prod(on production server only) -
.env.secrets(ultra-sensitive, server only)
Later files override earlier ones.
Specify versions in .env:
# PostgreSQL version
POSTGRES_VERSION=15
# Hasura version
HASURA_VERSION=v2.40.0
# Redis version
REDIS_VERSION=7
# MinIO version
MINIO_VERSION=latestnself config validateValidates:
- All required variables are set
- Port conflicts detected
- Service dependencies valid
- Custom service templates exist
nself build --dry-runShows exactly what would be generated without creating files.
# Show docker-compose.yml
cat docker-compose.yml
# Show Nginx configuration
cat nginx/nginx.conf
# View computed variables
cat .env.computedError: Port 8080 already in use
Solution: Change Nginx port in .env:
NGINX_PORT=8081
nself build
nself startError: Service 'postgres' not found
Solution: Make sure POSTGRES_DB is set in .env.
Error: Template 'express-js' not found
Solution: Use nself templates list to see available templates.
Error: Required variable HASURA_GRAPHQL_ADMIN_SECRET not set
Solution: Add the variable to .env:
HASURA_GRAPHQL_ADMIN_SECRET=your-secret-here
nself build# Build specific services only
nself build --only postgres,hasura
# Skip validation
nself build --skip-validate
# Parallel build (use all CPU cores)
nself build --parallelIf you have large custom services:
# Ignore large files in build
DOCKER_IGNORE_PATHS='node_modules,venv,.git'
nself build- Check disk space:
df -h - Check Docker:
docker system df - Clean unused images:
docker system prune
# Verify build completed successfully
nself build --verbose
# Rebuild from scratch
rm docker-compose.yml
nself build --clean# Check generated nginx config
cat nginx/sites/*.conf
# Verify service names
docker ps | grep my-app
# Test connection
curl -v http://localhost:8080/graphql- Cascading Configuration - Environment management
- Start Services - Launch your stack
- Deployment - Production deployment
Key Takeaway: nself build generates production-ready Docker Compose configurations from your .env files. Customize before building, then the generated files are yours to modify as needed.