Deployment Generator
Generate a Dockerfile, docker-compose.yml, and Kubernetes manifests (Deployment, Service, HPA, PDB, Ingress) from one config object.
On this page9
Overview
The deployment generator creates Docker and Kubernetes artifacts from a single configuration object. The manifests follow security best practices including non-root containers, read-only filesystems, and resource limits.
Generate Manifests
1import { generateDeployment } from '@axiljs/cloud'
2
3generateDeployment({
4 appName: 'payment-service',
5 version: '1.4.2',
6 port: 8080,
7 replicas: 3,
8 domain: 'payments.myapp.io',
9 env: {
10 DATABASE_URL: 'postgres://...',
11 LOG_LEVEL: 'info',
12 },
13 resources: {
14 cpuRequest: '100m',
15 cpuLimit: '500m',
16 memoryRequest: '128Mi',
17 memoryLimit: '512Mi',
18 },
19})This writes three files to ./deploy/ (relative to the current working
directory), logs a one-line summary, and returns them as
{ filename, content }[].
Generated Files
Dockerfile
Multi-stage build with Node 22 Alpine, a non-root user, and a health check.
1# ── Build stage ──────────────────────────────────────────────────
2FROM node:22-alpine AS builder
3WORKDIR /app
4COPY package*.json ./
5RUN npm ci
6COPY . .
7RUN npm run build
8
9# ── Production stage ─────────────────────────────────────────────
10FROM node:22-alpine AS runner
11
12# Non-root user
13RUN addgroup -g 1001 -S appgroup && \
14 adduser -S appuser -u 1001 -G appgroup
15
16WORKDIR /app
17COPY /app/package*.json ./
18RUN npm ci --omit=dev && npm cache clean --force
19COPY /app/dist ./dist
20
21USER appuser
22EXPOSE 8080
23
24HEALTHCHECK \
25 CMD wget -qO- http://localhost:8080/health || exit 1
26
27CMD ["node", "dist/main.js"]The image expects npm run build to produce dist/main.js.
docker-compose.yml
A single app service built from the local Dockerfile, with NODE_ENV=production,
PORT, your env entries, restart: unless-stopped, and a wget health check
against healthPath.
kubernetes.yaml
- Deployment: rolling update (
maxSurge: 1,maxUnavailable: 0), non-root security context (UID/GID 1001), read-only root filesystem, all capabilities dropped, resource requests and limits, readiness and liveness probes onhealthPath - Service: ClusterIP, port 80 to the container port
- HorizontalPodAutoscaler (
autoscaling/v2): CPU utilization target - PodDisruptionBudget:
minAvailable: 1 - Ingress (only when
domainis set): nginx SSL redirect, TLS secret named<name>-tls
Resource names are sanitized to RFC 1123 (lowercase, alphanumerics and hyphens,
at most 63 characters). The image is <registry>/<name>:<version>, or
<name>:<version> without registry. The version label is quoted so values
like 1.0 stay strings.
Dry Run Mode
Pass true as the second argument to get the manifests without writing to disk
or logging. Useful for CI/CD pipelines, tests, and API endpoints.
1const manifests = generateDeployment({
2 appName: 'my-service',
3 version: '1.0.0',
4 port: 3000,
5}, true) // dryRun = true
6
7manifests.forEach(m => console.log(m.filename, m.content))Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
appName | string | — | Application name (sanitized to RFC 1123) |
version | string | — | Image tag / version label |
port | number | — | Container port |
replicas | number | 3 | Initial replica count |
domain | string | — | Ingress hostname; omit for no Ingress |
registry | string | — | Image registry, no trailing slash |
env | Record<string, string> | — | Environment variables |
resources | object | See below | CPU/memory requests and limits |
minReplicas | number | 2 | HPA minimum |
maxReplicas | number | 10 | HPA maximum |
targetCPU | number | 70 | HPA target CPU utilization % |
healthPath | string | '/health' | Probe and health check path |
resources
| Field | Default |
|---|---|
cpuRequest | '100m' |
cpuLimit | '500m' |
memoryRequest | '128Mi' |
memoryLimit | '512Mi' |
Was this page helpful?