Cloud

Deployment Generator

Generate a Dockerfile, docker-compose.yml, and Kubernetes manifests (Deployment, Service, HPA, PDB, Ingress) from one config object.

3 min readUpdated DocumentationEdit this page
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

TypeScript
TS
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.

Dockerfile
DOCKER
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 --from=builder /app/package*.json ./
18RUN npm ci --omit=dev && npm cache clean --force
19COPY --from=builder /app/dist ./dist
20
21USER appuser
22EXPOSE 8080
23
24HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
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 on healthPath
  • Service: ClusterIP, port 80 to the container port
  • HorizontalPodAutoscaler (autoscaling/v2): CPU utilization target
  • PodDisruptionBudget: minAvailable: 1
  • Ingress (only when domain is 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.

TypeScript
TS
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

OptionTypeDefaultDescription
appNamestring—Application name (sanitized to RFC 1123)
versionstring—Image tag / version label
portnumber—Container port
replicasnumber3Initial replica count
domainstring—Ingress hostname; omit for no Ingress
registrystring—Image registry, no trailing slash
envRecord<string, string>—Environment variables
resourcesobjectSee belowCPU/memory requests and limits
minReplicasnumber2HPA minimum
maxReplicasnumber10HPA maximum
targetCPUnumber70HPA target CPU utilization %
healthPathstring'/health'Probe and health check path

resources

FieldDefault
cpuRequest'100m'
cpuLimit'500m'
memoryRequest'128Mi'
memoryLimit'512Mi'

Was this page helpful?

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY