Skip to main content
CRUCIBLE
Legacy Reference Archive: This 44-chapter book reference has been distilled into Academy A01 (8 Executable Modules) with Tier-Adaptive Productive Failure, Kore/Puck voice, and live Firecracker labs.
Open Academy A01 →
COURSE 0 · SERVER BUILDING & LIFECYCLE MASTERY

Zero-to-Production Linux, Containers, Networking & Recovery

PROGRESS: 0 / 72 (0%)0/44L · 0Q · 0VM
CH 07 · PART II · CONTAINERS, LIVE DEPLOY & OPS (CH 06–08) · 1,282 WORDS (7 MIN)

7 Deploy a service to a live HTTPS domain

Write down the service owner, region, data classification, expected traffic, acceptable outage, recovery targets, monthly budget, and maintenance window. For a first private demo, a single VM is understandable. It is also a single point of failure.

FULL WAR-ROOM →
INTERACTIVE REQUEST FLOW · CLICK ANY HOP TO INSPECT LIVE

Production Request Path: HTTPS Edge -> App -> PgBouncer -> Postgres

Trace every hop from a browser TLS 1.3 connection to an indexed PostgreSQL row lookup.

HTTPSQLPooledNGINX EdgeTLS 1.3 · :8443 / :443FastAPI Worker127.0.0.1 :8000PgBouncer PoolTX Mux · :6432PostgreSQL 15B-Tree · :5432
SELECTED LAYER · NGINX EDGE
Terminates HTTPS, enforces timeouts and rate limits, and reverse-proxies clean HTTP to loopback.
Common failure: HTTP 502 Bad Gateway when upstream keepalive_timeout is shorter than proxy idle timeout.
$ nginx -t

Outcome: deploy the reference service on a Linux VM and verify it from an external client. Prerequisites: local and container checks pass, you control a domain, and you can recover console access. Environment: a new Ubuntu VM; separate laptop terminal. Status: a live deployment recipe, not a claim that Course 0 provisioned or tested your account. Public traffic, DNS changes, and hosting may incur costs.

Decide the deployment contract

Write down the service owner, region, data classification, expected traffic, acceptable outage, recovery targets, monthly budget, and maintenance window. For a first private demo, a single VM is understandable. It is also a single point of failure. A customer-facing service may require a managed database, redundant application instances, stronger gateway controls, and an operational owner.

The initial topology is internet → host Caddy on 443 → loopback API on 18768 → private PostgreSQL. Only SSH for trusted administrators and HTTP/HTTPS for intended clients should be externally reachable. Do not publish PostgreSQL merely to make a local client convenient.

Provision and prepare

In your provider console, create the chosen Ubuntu VM with a known SSH public key, appropriate architecture, enough image/database storage, and a recoverable console. Record its address and instance ID. Configure a provider firewall allowing SSH only from your administrative source and 80/443 as needed. Check IPv6 separately.

On the remote Ubuntu VM, install Docker Engine and the Compose plugin using Docker's official Ubuntu installation instructions, and Caddy using its official installation instructions. Verify their package sources and supported OS versions. Course 0 does not pipe a remote installer into a privileged shell. See [Docker on Ubuntu](https://docs.docker.com/engine/install/ubuntu/) and [Caddy installation](https://caddyserver.com/docs/install).

Verify docker version, docker compose version, and caddy version. Docker administration is highly privileged; adding a user to its group grants broad control. Keep administrator access separate from the application identity. Apply OS updates and plan any required reboot before putting data on the machine.

Transfer the application

Transfer the reviewed source bundle over SSH or clone your reviewed repository. Exclude .env, .venv, caches, local databases, and backups. Do not copy your laptop's generated lab credentials to the server. Create a new deployment directory with restricted ownership and generate fresh server-side credentials with setup_lab.py.

Use an explicit reviewed release. Keep a record of the source revision, lock file, image ID/digest, configuration revision, and schema version. Do not deploy by pulling an unreviewed moving branch and hoping it matches your tested environment.

On the remote server, inside the example directory:

bash
python3 setup_lab.py
docker compose config --quiet
docker compose up -d --build
curl --fail-with-body --retry 20 --retry-connrefused \
  --retry-delay 1 --retry-max-time 60 --max-time 3 \
  http://127.0.0.1:18768/health/ready

If .env already exists, the generator refuses to overwrite it. Investigate whether this is an existing deployment; do not delete it to silence the error. If local readiness fails, fix application/database initialization before changing DNS or the proxy.

Configure the domain

Create an A record for your chosen hostname pointing to the VM's IPv4 address. Add an AAAA record only if the IPv6 path is correctly configured. Use a low TTL during planned migration, recognizing that caches and previous TTLs affect convergence. Verify from an independent resolver and from an external client.

Use a subdomain such as jobs.your-domain.example as a placeholder in your notes; substitute a domain you actually control. A placeholder does not receive a public certificate. If a CDN or proxy fronts the host, document where TLS terminates and how the origin is protected.

Configure Caddy

The included Caddyfile uses {$DOMAIN} for portability. A system service does not inherit your interactive shell's environment. For a first deployment, write your actual hostname directly in the server's Caddyfile instead of relying on an unconfigured service variable.

Remote `/etc/caddy/Caddyfile`, replace the hostname:

caddy
jobs.your-actual-domain.com {
    request_body {
        max_size 64KB
    }
    reverse_proxy 127.0.0.1:18768
    log
}

Before replacing an existing configuration, preserve it and confirm the server does not host unrelated sites. Validate with sudo caddy validate --config /etc/caddy/Caddyfile, then reload the service. Inspect journalctl -u caddy if certificate issuance fails. Public certificate issuance requires the domain and challenge path to reach the intended server. Persist and protect Caddy's certificate state. [Automatic HTTPS](https://caddyserver.com/docs/automatic-https) explains the requirements.

The app limits body size and body-read duration. Before opening an adversarial public service, also configure gateway-level connection limits, unauthenticated request throttling, header/read deadlines, and suitable request concurrency limits. The minimal Caddyfile is an HTTPS recipe, not a comprehensive abuse gateway. Keep an initial demo behind a controlled access layer until those controls are established.

Verify from outside

From your laptop or another external machine, verify hostname resolution, valid HTTPS, unauthenticated liveness, invalid-token rejection, authorized submission, and job completion. Confirm unauthorized tenants remain isolated. Check that database and API-internal ports are not reachable externally using only the host you own or are authorized to test.

Record evidence for every layer. A successful curl to loopback does not prove DNS. A valid certificate does not prove authorization. A successful job does not prove backups. Use a fresh synthetic request ID for the public smoke test, and do not put credentials in screenshots or shared logs.

Release and rollback

For a first release, build and tag the tested image with a unique revision. For subsequent releases, retain the previous image and configuration. Deploy the candidate, run readiness and contract smoke checks, and observe error rate and job completion. If behavior regresses, restore the previous compatible image/configuration and verify the original contract.

The teaching Compose file builds a convenient 5.0 tag. For releases, replace that moving identity with an immutable tag or digest and remove ambiguity about which image runs. Record rollback commands for the actual deployment. An image rollback does not reverse database migrations, lost files, or already-sent external effects.

For zero- or low-downtime requirements, deploy a second instance, verify readiness, drain the old one, and shift traffic gradually. Keep schema changes compatible with both versions during overlap. A single-VM Compose restart may interrupt requests; do not promise zero downtime for it.

Managed hosting alternative

A managed platform can remove OS and certificate administration from your first project. Create an API service from the same image, a separate worker with python worker.py, and a private managed PostgreSQL database. Run the reviewed Alembic migration as a one-off release step, then seed initial credentials separately. Set the API's listening port to the platform's contract, inject secrets, configure a readiness path, attach a custom domain, and verify the same external tests.

Do not use local ephemeral disk as a durable database. Check platform shutdown grace periods, idle behavior, request timeouts, worker support, egress costs, and backup restoration. These details vary; consult the selected platform's current documentation before committing to it. The managed route is an adaptation procedure, not a vendor-specific production manifest.

Acceptance and retirement

Before using real customer data, require: least-privilege runtime credentials, tested access controls, durable backups and restoration, monitoring, secret rotation, dependency review, resource limits, an incident owner, and a rollback plan. Document any remaining single points of failure and obtain the appropriate owner acceptance.

To retire the service, stop new submissions, drain or export accepted work, retain data according to policy, remove traffic/DNS deliberately, revoke service credentials, and delete only the confirmed resources after retention and backup decisions. Check for orphaned disks, addresses, snapshots, databases, and subscriptions. Do not assume deleting an application removes every billable resource.

Exit exercise: complete a live deployment in your chosen account, record the public checks without secrets, deploy a deliberately failing candidate to staging, recover, and document the actual monthly resource estimate. This external proof remains pending a selected account, domain and approved deployment scope.

ACTIVE-RECALL MASTERY CHECKPOINT · CH 07

Lock in what you just learned (3 quick questions)

PASS 2/3 FOR +30 XP
Q1.Before pointing public DNS to a new HTTPS server, what must be verified first?
Q2.Why automate TLS certificate renewal (e.g. ACME/Let's Encrypt) and monitor certificate expiry days?
Q3.Why configure X-Forwarded-For and X-Forwarded-Proto carefully on your reverse proxy?
Answered 0 / 3