Back to Field Notes
Log

Our first ERPNext instance, and an agent that reports home

The week we brought up our own ERPNext v16 site with Terraform, gave it an outbound-only agent that found 18 hand-made customizations a file hash would have missed, and merged 43 pull requests across two repositories.

Covers
Written
Repositories
infinary.io, infinary_agent
Pull requests
43
Reading time
4 min
#erpnext#terraform#google-cloud#control-plane#golden-image
Contents

The week in brief

Between Monday and Friday we merged 34 pull requests in infinary.io and 9 in a new repository, infinary_agent: a control plane, a customer portal, a provisioning pipeline, managed updates and backups. How fast that went, and what wasn’t protecting it, is its own note, and Thursday’s fight with the Backup and DR API is another. This note is about the instance and the agent.

051015pull requestsMon 22Tue 23Wed 24Thu 25Fri 26infinary.io, Mon 22: 2infinary.io, Tue 23: 8infinary.io, Wed 24: 13infinary.io, Thu 25: 10infinary.io, Fri 26: 1infinary_agent, Mon 22: 0infinary_agent, Tue 23: 0infinary_agent, Wed 24: 2infinary_agent, Thu 25: 6infinary_agent, Fri 26: 1infinary.ioinfinary_agent
051015pull requestsMon 22Tue 23Wed 24Thu 25Fri 26infinary.io, Mon 22: 2infinary.io, Tue 23: 8infinary.io, Wed 24: 13infinary.io, Thu 25: 10infinary.io, Fri 26: 1infinary_agent, Mon 22: 0infinary_agent, Tue 23: 0infinary_agent, Wed 24: 2infinary_agent, Thu 25: 6infinary_agent, Fri 26: 1infinary.ioinfinary_agent
Pull requests merged each day, June 22–26 Pull requests merged per day, Denver time. infinary.io: 2 on Monday, 8 on Tuesday, 13 on Wednesday, 10 on Thursday and 1 on Friday. infinary_agent: none on Monday or Tuesday, 2 on Wednesday, 6 on Thursday and 1 on Friday.
Show data
infinary.ioinfinary_agent
Mon 2220
Tue 2380
Wed 24132
Thu 25106
Fri 2611

Bringing up the first instance

On Tuesday, June 23, we wrote Terraform for one ERPNext instance and applied it to bring up our own site, erp.infinary.io, on ERPNext v16.23.1: a dedicated network, a static address, boot and data disks (Customer-managed encryption keys: Google Cloud encrypts the data with a key you create and control in Cloud KMS, instead of a key Google manages for you.), daily snapshots, SSH only through Google’s identity-aware proxy, and Caddy in front for TLS. We wrote down what went wrong as it happened, because the control plane would have to do the same thing unattended:

  • A null where an email should be. Terraform’s lookup for the Compute Engine service agent returned an empty email, which crashed the apply at the step that grants it use of the disk encryption key. We build the address from the project number instead.
  • Zone stockout. The machine type was out of stock in the first zone. The provisioner now retries the next zone, keeping the VM, its disks and its snapshots zonal.
  • TLS before DNS. Caddy starts at boot and asks Let’s Encrypt for a certificate immediately. If the DNS record doesn’t exist yet the challenge fails, Caddy backs off for a long time, and the browser shows ERR_SSL_PROTOCOL_ERROR. The fix is to wait until the name resolves and then reload Caddy. Our notes from that day call this “the one that bit us”.
  • Realtime refused the domain. On a custom domain, Frappe’s realtime server rejected connections with “Invalid origin” until the site’s host_name was set. The same error came back in August with a different cause, in the Aria note.

Docker’s data directory went onto the encrypted data disk, so that the database and the site files are inside the daily snapshots. We believed the container images were on that disk too. In August, when the boot disk reached 98% and an image swap failed for lack of space, we found they weren’t.

An agent that only calls out

The agent’s first commit landed at 20:00 that evening in its own repository. It has two halves. A small Frappe app exposes one read-only method that returns the instance’s versions and a drift fingerprint. A (The small Infinary agent that runs next to ERPNext on each server. It runs updates, app installs and rollbacks, and only ever connects outward.) process sends a heartbeat, long-polls the control plane for jobs and runs upgrades with a backup and a rollback. It opens no port and listens on nothing; every connection goes out from the instance.

The fingerprint is the interesting part. A hash of the app files tells you whether code was changed, but in Frappe a lot of customization is made through the browser and stored in the database: custom fields, server scripts, client scripts. So the fingerprint hashes both. Installing it on our live site turned up three bugs in its first hour, one of them a query for a doctype that doesn’t exist. Then it found 18 custom fields made through the UI and one app that isn’t part of the baseline. A file hash alone would have missed all 18 fields. Adding one more custom field moved the count to 19, and removing it moved it back to 18.

By Friday the sidecar had gone from 0.4.0 to 0.7.3: it learned to back up, restart and clear the cache on request, honour the kill switch, apply updates inside the owner’s window, update itself blue/green, and apply a per-app target image.

Smaller things worth recording

  • One image lineage. A (The server image every Infinary site runs: Frappe, ERPNext and our own apps, pinned to exact versions and tested together.) pipeline builds ERPNext images with the agent baked in, so provisioning and upgrades start from the same image.
  • Per-app updates. Frappe and ERPNext versions are coupled, and every app is baked into the image, so “update only ERPNext” can’t edit a running container. Selecting apps resolves to a pre-built image in a curated catalog, or returns a 409 when no image carries that combination.
  • The portal served old code. The portal’s Cloudflare Pages project had no Git connection, so it only changed on a manual deploy. It kept serving 0.8.0, without the new admin tab, well after 0.9.0 merged.
  • Four commits missed their merge. Four times in under two days, a commit was pushed to a branch just after its pull request had merged. One of them meant a newly provisioned instance would never install the agent; another meant the “Update now” job had no handler in the agent at all. Each needed a follow-up pull request. Merge the branch tip, not the moment you think you’re done.