All Modules Environments Deploy Infra as Code Auto-Deploy عربي

Deploy + Infrastructure as Code

Take the image live — and define the servers it runs on as version-controlled code.

Module 10 · Reproducible deployments, no clicking around.

Advanced Deploy & IaC Includes Lab ~60 min

What You'll Learn

  • What environments (dev / staging / production) are and why they exist
  • Deploy the containerized vault to a real host
  • Define infrastructure as code with Terraform (provision) and Ansible (configure)
  • Wire deployment into CI so a push to main ships automatically
  • Hands-on lab: get the vault live at a URL, with its infra captured in code

Prerequisites: Module 9 (image built in CI). Deep dive: DevOps Lab: Infrastructure as Code and Real Cloud.

Environments

You don't test in front of your users. Real projects run the same app in separate environments, each with its own config and data:

EnvironmentPurpose
DevelopmentYour machine / containers — where you build.
StagingA production-like copy for final checks before release.
ProductionThe live environment real users touch.

The container makes this trivial

Because Module 8 froze the app into an image, "deploy to production" just means "run that same image on the production host with production config." Same box, different environment variables.

Getting It Live

The simplest real deployment: a small cloud VM with Docker installed, pulling your image and running it with Compose. In plain terms:

# on the production host docker pull ghcr.io/YOU/snippet-vault-api:latest docker compose -f docker-compose.prod.yml up -d

Doing this by hand once is fine for learning. But manual steps drift and get forgotten — which is exactly the problem Infrastructure as Code solves.

Infrastructure as Code

Clicking around a cloud console is the .env-in-the-repo of infrastructure: unrepeatable and impossible to review. Infrastructure as Code defines your servers in version-controlled files, so the whole environment is reproducible and diffable.

ToolJob
TerraformProvision — create the VM, network, and firewall from code.
AnsibleConfigure — install Docker and deploy the app onto that VM.

Reuse the DevOps Lab, don't reinvent it

The DevOps Lab IaC module and its sample-app/terraform and sample-app/ansible folders are a working template. Point your assistant at them, adapt for the vault, and review every line — infra code can cost real money if it's wrong.

Especially review AI infra code

An assistant will happily open a firewall to the world or hard-code a token. Infra is the highest-stakes place to take the wheel (Module 5). Read it like a hawk, and keep secrets in variables, never in the code.

Auto-Deploy on Green

The finish line of CD: extend your Module 9 pipeline so that when CI passes on main, it deploys automatically — pull the new image, restart the container. Now a merged pull request becomes a live release, hands-free, every time.

The full loop, automated

Idea → spec → build → test → gate → CI → deploy. From here, shipping a change is just merging a reviewed PR. That's the DevOps standard the whole course was building toward.

Practical Lab: Ship It Live

You'll deploy the vault to a real host and capture its infrastructure as code. A free-tier VM is ideal, but a managed container host works too — the goal is a public URL plus infra you can recreate from files.

What you need

Your GitHub repo from Module 9 (image building in CI) and a host to deploy to (a free-tier cloud VM, or a managed container platform).

1

Branch and add a prod compose

git checkout -b feature/deploy

Ask the assistant for a docker-compose.prod.yml that runs your published images with production env vars (from the host, not committed).

2

Capture the infra as code

Using the DevOps Lab terraform/ansible sample as a template, write IaC to: provision one small VM with a firewall (allow only 80/443/22), install Docker, and run docker-compose.prod.yml. Keep secrets in variables.

Review every line — especially firewall rules and any secrets.

3

Deploy and reach it

Run your provision + configure steps (or your managed-host deploy). Open the app's public URL in a browser and create a snippet. It's live on the internet.

4

Automate it (optional but recommended)

Add a deploy job to your CI workflow that runs on main after tests pass. Merge a tiny change and watch it deploy itself.

5

Merge and reflect

git add . git commit -m "Add prod compose + IaC; deploy the vault" git checkout main && git merge feature/deploy

In REFLECTION.md: paste your live URL, and note one thing in the AI's infra code you had to tighten for safety. Commit.

What to hand in

Your repo plus the live URL. Self-check:

  • The vault is reachable at a public URL and works
  • Infrastructure is defined in committed code (Terraform/Ansible or equivalent)
  • No secrets in the infra code; firewall is restrictive
  • REFLECTION.md has the URL and a safety fix you made

Mini Glossary

TermPlain meaning
EnvironmentA place the app runs: dev, staging, or production.
ProvisionCreate the servers/network the app needs.
TerraformTool to provision infrastructure from code.
AnsibleTool to configure servers and deploy apps from code.
IaCInfrastructure as Code — servers defined in version-controlled files.

Recap & What's Next

You now have

The snippet vault live on the internet, its infrastructure defined in reviewable code, and (optionally) a pipeline that deploys on every green merge. Your AI-built app is a real, shipped product.

Next up: Module 11 — Monitoring & Observability. Live isn't done — now we make the app tell you when it's healthy and when it's not, with logs, metrics, and alerts.

Deploy + Infrastructure as Code

Objectives Environments Deploy Infra as Code Auto-Deploy Practical Lab Glossary Recap