Harness containerization

From Intense-Visions/harness-engineering · View interactive version

Harness containerization is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Dockerfile review, Kubernetes manifest validation, and container optimization. Smaller images, safer containers, correct orchestration.

How to use this skill

Skill file

Harness Containerization

Dockerfile review, Kubernetes manifest validation, and container optimization. Smaller images, safer containers, correct orchestration.

When to Use

Process

Phase 1: SCAN -- Discover Container Configuration

  1. Locate container files. Search the project for container-related configuration:
  1. Identify base images. Parse each Dockerfile for FROM directives:
  1. Inventory Kubernetes resources. Parse manifest files and record:
  1. Detect Helm usage. If Helm charts exist:
  1. Present scan summary:

```

Container Scan:

Dockerfiles: 2 (app, worker)

Compose files: 1 (docker-compose.yml + docker-compose.dev.yml)

K8s manifests: 8 resources across 2 namespaces

Helm charts: 1 (app chart with 3 subcharts)

Base images: node:20-alpine, python:3.12-slim

```


Phase 2: ANALYZE -- Evaluate Best Practices

  1. Analyze Dockerfile layer efficiency. Check each Dockerfile for:
  1. Check container security posture. Evaluate:
  1. Evaluate Kubernetes resource definitions. For each Deployment/StatefulSet:
  1. Analyze docker-compose configuration. Check for:
  1. Check image tag strategy. Verify:

Phase 3: OPTIMIZE -- Recommend Improvements

  1. Recommend image size reduction. For each Dockerfile:
  1. Recommend build performance improvements.

```dockerfile

# Good: dependency layer cached separately

COPY package.json package-lock.json ./

RUN npm ci --production

COPY src/ ./src/

```

  1. Recommend Kubernetes improvements.
  1. Recommend security hardening.
  1. Generate optimization summary with estimated impact:

```

Optimization Summary:

Image size: 850MB -> ~180MB (switch to alpine + multi-stage)

Build time: ~4m -> ~2m (layer reordering + cache mounts)

Security: 3 findings (non-root, capabilities, image pinning)

K8s: 5 resources missing resource limits

```


Phase 4: VALIDATE -- Verify Configuration Correctness

  1. Validate Dockerfile syntax. Run docker build --check or parse for common errors:
  1. Validate Kubernetes manifests. Check for:
  1. Validate Helm charts. If Helm is used:
  1. Validate docker-compose. Check for:
  1. Generate validation report:

```

Container Validation: [PASS/WARN/FAIL]

Dockerfiles: PASS (2/2 valid)

K8s manifests: WARN (label mismatch in worker-service.yaml)

Helm chart: PASS (lint clean)

Compose: PASS (valid structure)

Issues:

1. k8s/worker-service.yaml: selector "app: worker" does not match

deployment label "app: worker-v2" -- requests will not route

```


Harness Integration

Success Criteria

Examples

Example: Node.js Monorepo with Docker and Kubernetes

Phase 1: SCAN
  Found: Dockerfile (app), Dockerfile.worker, docker-compose.dev.yml
  K8s: 12 manifests in k8s/ (2 Deployments, 2 Services, 2 ConfigMaps,
       2 HPA, 2 Ingress, 2 PDB)
  Base images: node:20 (not alpine), node:20 (worker)

Phase 2: ANALYZE
  Dockerfile issues:
    - node:20 full image (940MB) -- use node:20-alpine (180MB)
    - No .dockerignore -- node_modules and .git copied into image
    - No USER directive -- running as root
    - No HEALTHCHECK
  K8s issues:
    - worker deployment missing memory limits
    - No network policies defined
    - Liveness probe on /healthz but no readiness probe

Phase 3: OPTIMIZE
  1. Switch to node:20-alpine -- saves ~760MB per image
  2. Add .dockerignore with node_modules, .git, tests, docs
  3. Add multi-stage build: builder stage for npm ci, runtime for app
  4. Add USER node (UID 1000) after COPY
  5. Add readiness probe on /ready endpoint
  6. Add memory limit of 512Mi to worker deployment

Phase 4: VALIDATE
  Dockerfiles: WARN (2 security findings, 1 size finding)
  K8s manifests: WARN (missing limits, missing readiness probe)
  Compose: PASS
  Result: WARN -- 6 actionable improvements identified

Example: Python FastAPI with Helm and Distroless

Phase 1: SCAN
  Found: Dockerfile (multi-stage with distroless runtime)
  Helm chart: charts/api/ with values.yaml
  Base images: python:3.12-slim (builder), gcr.io/distroless/python3 (runtime)

Phase 2: ANALYZE
  Dockerfile: Well-structured multi-stage build
    - Builder installs dependencies, runtime copies only venv
    - Distroless base (no shell, minimal attack surface)
    - Non-root user configured
  Helm:
    - Resource limits set in values.yaml
    - Probes configured with appropriate timeouts
    - HPA configured for 2-10 replicas

Phase 3: OPTIMIZE
  Minor recommendations only:
    - Pin distroless image to digest for reproducibility
    - Add --mount=type=cache for pip downloads in builder stage
    - Add pod anti-affinity to spread replicas across nodes

Phase 4: VALIDATE
  Dockerfile: PASS
  Helm lint: PASS
  Template render: PASS (all values resolve)
  Result: PASS -- well-configured container setup

Rationalizations to Reject

| Rationalization | Reality |

| ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| "We use latest in production because we always want the most recent image" | latest is a mutable pointer. A deployment at 9am and a rollback at 9pm may pull different image contents with the same tag. Immutable tags (semver or digest) are required for reproducible deployments and reliable rollbacks. |

| "The container runs as root because it needs to bind to port 80" | Binding to a privileged port requires elevated capability, not full root access. The correct solution is to run the container as a non-root user and use --cap-add NET_BIND_SERVICE, or to expose a high port and use a load balancer or ingress for port translation. |

| "We don't set resource limits because we want the container to use whatever it needs" | Containers without memory limits can exhaust node memory, triggering OOM kills of other containers on the same node. Kubernetes uses resource requests for scheduling and limits for safety; omitting limits transfers the risk of one container onto the entire node. |

| "Our image is 2GB but it only takes a few seconds to pull in our CI" | Image size multiplies across every developer pull, every CI run, and every Kubernetes pod startup. A 2GB image that takes 3 seconds to pull in CI with a warm cache takes 90 seconds on a cold node during an autoscaling event at peak traffic. |

| "We don't need liveness and readiness probes — the container exits if it crashes" | Process exit is a coarse health signal. A process that is running but deadlocked, stuck in an infinite retry loop, or unable to connect to its database will never exit. Kubernetes will continue routing traffic to it. Readiness probes prevent traffic routing to unhealthy containers that are still running. |

Gates

Escalation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.