| ← Back to README | Configuration | Quadlet → |
Related: Network Security User Isolation
This guide covers deploying pactown ecosystems to production using Docker, Podman, and Kubernetes.
| Backend | Use Case | Security |
|---|---|---|
| Local | Development | Basic |
| Docker | Single server | Good |
| Podman | Rootless containers | Excellent |
| Quadlet | VPS production (systemd-native) | Excellent |
| Kubernetes | Orchestrated cluster | Enterprise |
| Compose | Multi-container | Good |
# Docker Compose (development)
pactown deploy saas.pactown.yaml -o ./deploy
# Docker Compose (production)
pactown deploy saas.pactown.yaml -o ./deploy --production
# Kubernetes manifests
pactown deploy saas.pactown.yaml -o ./deploy --kubernetes --production
cd deploy
docker compose up -d
# Or with Podman
podman-compose up -d
kubectl apply -f deploy/kubernetes/
| File | Purpose |
|---|---|
docker-compose.yaml |
Main service definitions |
docker-compose.override.yaml |
Development overrides |
docker-compose.prod.yaml |
Production settings |
docker compose up -d
docker compose logs -f
docker compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d
Podman provides rootless containers - no root daemon required.
from pactown.deploy import PodmanBackend, DeploymentConfig
config = DeploymentConfig.for_production()
podman = PodmanBackend(config)
# Build and deploy
podman.build_image("api", dockerfile_path, context_path)
podman.deploy("api", "pactown/api:latest", port=8001, env={...})
Generate systemd unit files for production:
unit = podman.generate_systemd_unit("api")
# Write to /etc/systemd/system/pactown-api.service
systemctl enable pactown-api
systemctl start pactown-api
Group related containers in a pod (like Kubernetes):
podman.create_pod("my-app", services=["api", "worker"], ports=[8001, 8002])
For each service, pactown generates:
securityContext:
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
Generate HorizontalPodAutoscaler:
from pactown.deploy import KubernetesBackend
k8s = KubernetesBackend(config)
hpa = k8s.generate_hpa("api", min_replicas=2, max_replicas=10, target_cpu=70)
Services can only communicate within the pactown namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
spec:
ingress:
- from:
- namespaceSelector:
matchLabels:
managed-by: pactown
from pactown.deploy import DeploymentConfig, DeploymentMode
config = DeploymentConfig(
mode=DeploymentMode.PRODUCTION,
# Container security
rootless=True, # Podman rootless mode
read_only_fs=True, # Read-only filesystem
no_new_privileges=True, # Prevent privilege escalation
drop_capabilities=["ALL"], # Drop all Linux capabilities
# Resource limits
memory_limit="512m",
cpu_limit="0.5",
# Health checks
health_check_interval="10s",
health_check_retries=5,
)
config = DeploymentConfig.for_production()
This enables:
Pactown auto-generates secure Dockerfiles:
FROM python:3.12-slim
WORKDIR /app
# Security: run as non-root user
RUN useradd -m -u 1000 appuser
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application
COPY . .
# Switch to non-root user
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD curl -f http://localhost:${PORT:-8000}/health || exit 1
CMD ["python", "main.py"]
from pactown.deploy import DockerBackend
docker = DockerBackend(config)
# Build
result = docker.build_image("api", dockerfile_path, context_path, tag="v1.0.0")
# Push to registry
docker.push_image("pactown/api:v1.0.0", registry="ghcr.io/myorg")
Services communicate via container names:
environment:
DATABASE_URL: http://database:8003
API_URL: http://api:8001
Services use internal DNS:
http://api.pactown.svc.cluster.local:8001
All backends support health checks:
result = backend.deploy(
service_name="api",
image_name="pactown/api:latest",
port=8001,
env={},
health_check="/health", # Health endpoint
)
logs = backend.logs("api", tail=100)
status = backend.status("api")
# {
# "running": True,
# "health": "healthy",
# "container_id": "abc123",
# }
# Generate Docker Compose
pactown deploy CONFIG [-o OUTPUT] [--production]
# Generate Kubernetes
pactown deploy CONFIG [-o OUTPUT] --kubernetes [--production]
# Options
-o, --output Output directory (default: .)
-p, --production Production configuration
-k, --kubernetes Generate Kubernetes manifests
| Module | Description |
|---|---|
deploy/base.py |
Base classes and config |
deploy/docker.py |
Docker backend |
deploy/podman.py |
Podman backend |
deploy/kubernetes.py |
Kubernetes backend |
deploy/compose.py |
Compose generator |