<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: CHIMA_NIGERIAN_SUPERMAN</title>
    <description>The latest articles on DEV Community by CHIMA_NIGERIAN_SUPERMAN (@stino_emmanuel_53fdaf1217).</description>
    <link>https://dev.to/stino_emmanuel_53fdaf1217</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3916525%2F38877306-1028-443c-915f-259dfe017a0c.png</url>
      <title>DEV Community: CHIMA_NIGERIAN_SUPERMAN</title>
      <link>https://dev.to/stino_emmanuel_53fdaf1217</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stino_emmanuel_53fdaf1217"/>
    <language>en</language>
    <item>
      <title>Building a Self-Deploying Infrastructure Tool with OPA Policy Guards</title>
      <dc:creator>CHIMA_NIGERIAN_SUPERMAN</dc:creator>
      <pubDate>Wed, 06 May 2026 18:41:54 +0000</pubDate>
      <link>https://dev.to/stino_emmanuel_53fdaf1217/building-a-self-deploying-infrastructure-tool-with-opa-policy-guards-3o58</link>
      <guid>https://dev.to/stino_emmanuel_53fdaf1217/building-a-self-deploying-infrastructure-tool-with-opa-policy-guards-3o58</guid>
      <description>&lt;p&gt;Building a Self-Deploying Infrastructure Tool with OPA Policy Guards&lt;br&gt;
What I Built and Why....&lt;/p&gt;

&lt;p&gt;Author CHIMA_THE_NIGERIAN_SUPERMAN&lt;/p&gt;

&lt;p&gt;For HNG Stage 4, I built SwiftDeploy — a CLI tool that turns a single YAML manifest into a fully running web application with Nginx, Docker containers, and Open Policy Agent security gates.&lt;/p&gt;

&lt;p&gt;The problem at hand: Traditional DevOps requires writing multiple config files by hand, manually checking if the environment is safe, and hoping nothing breaks during deployment.&lt;/p&gt;

&lt;p&gt;The solution i worked on: One manifest file describes everything. The tool generates all configs, checks policies automatically, and refuses to deploy if conditions aren't met.&lt;/p&gt;

&lt;p&gt;How the Manifest Works&lt;br&gt;
The manifest.yaml is the only file I edit. It declares:&lt;/p&gt;

&lt;p&gt;yaml&lt;br&gt;
services:&lt;br&gt;
  image: swift-deploy-1-node:latest&lt;br&gt;
  port: 3000&lt;br&gt;
  mode: stable&lt;/p&gt;

&lt;p&gt;nginx:&lt;br&gt;
  image: nginx:latest&lt;br&gt;
  port: 8080&lt;/p&gt;

&lt;p&gt;From this single file, swiftdeploy init generates:&lt;/p&gt;

&lt;p&gt;nginx.conf with reverse proxy, JSON logging, and error pages&lt;/p&gt;

&lt;p&gt;docker-compose.yml with health checks, networks, and volumes&lt;/p&gt;

&lt;p&gt;If you delete the generated files, they regenerate exactly the same way. The manifest is the single source of truth, i call the omni truth lol&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Policy Brain: Open Policy Agent&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The coolest part is the OPA sidecar. Instead of hardcoding "if disk &amp;lt; 10GB, don't deploy" in the CLI, I wrote it as a Rego policy:&lt;/p&gt;

&lt;p&gt;rego&lt;br&gt;
allow if {&lt;br&gt;
    disk_free_gb &amp;gt; 10&lt;br&gt;
    cpu_load &amp;lt; 2.0&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The CLI asks OPA: "Should I deploy?" OPA answers with reasoning — not just yes/no, but exactly why. If OPA is unreachable, the CLI fails safely instead of crashing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Observability Eyes: Prometheus Metrics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every request is tracked with counters by method, path, and status code. Latency is recorded in histogram buckets. &lt;br&gt;
The /metrics endpoint serves everything in Prometheus format.&lt;/p&gt;

&lt;p&gt;The live dashboard (swiftdeploy status) scrapes these metrics every 3 seconds and shows real-time policy compliance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chaos Testing: Breaking Things on Purpose&lt;/strong&gt;&lt;br&gt;
The canary mode has a /chaos endpoint that lets you inject failures:&lt;/p&gt;

&lt;p&gt;slow mode: Responses take N seconds&lt;/p&gt;

&lt;p&gt;error mode: 50% of requests return 500 errors&lt;/p&gt;

&lt;p&gt;recover: Cancels all chaos&lt;/p&gt;

&lt;p&gt;When I activated error mode, the pre-promote gate blocked promotion because the error rate exceeded the 1% threshold. The audit report recorded every violation.&lt;/p&gt;

&lt;p&gt;What I Learned?&lt;/p&gt;

&lt;p&gt;Declarative configuration is powerful — One file generates an entire stack&lt;/p&gt;

&lt;p&gt;Policy-as-code prevents mistakes — OPA catches problems before they reach users&lt;/p&gt;

&lt;p&gt;Observability matters — Without metrics, you're deploying blind&lt;/p&gt;

&lt;p&gt;Always whitelist your own IP — I learned this the hard way in Stage 3!&lt;/p&gt;

&lt;p&gt;Try It Yourself&lt;br&gt;
The project is open source at github.com/icode-py/swiftdeploy.&lt;/p&gt;

&lt;p&gt;git clone &lt;a href="https://github.com/icode-py/swiftdeploy.git" rel="noopener noreferrer"&gt;https://github.com/icode-py/swiftdeploy.git&lt;/a&gt;&lt;br&gt;
cd swiftdeploy&lt;br&gt;
pip install pyyaml jinja2 psutil&lt;br&gt;
cd app &amp;amp;&amp;amp; docker build -t swift-deploy-1-node:latest . &amp;amp;&amp;amp; cd ..&lt;br&gt;
python swiftdeploy deploy&lt;br&gt;
curl &lt;a href="http://localhost:8080/" rel="noopener noreferrer"&gt;http://localhost:8080/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;

</description>
      <category>devops</category>
      <category>ai</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
