UAT and production¶
How-to guideThe steps for one task.
An Apinx instance is one environment: everything deployed on it serves its callers. To keep UAT and production apart, run one instance per environment and promote the configuration from one to the other as a file. With that separation, a bad deployment, a runaway test or a leaked UAT key can never touch production traffic. A single console managing several environments is on the roadmap.
The layout¶
| UAT | Production | |
|---|---|---|
| Console | https://uat-console.example.com |
https://console.example.com |
| APIs | https://uat-api.example.com |
https://api.example.com |
| Database | apinx_uat |
apinx |
| Master key | its own | its own |
| Upstreams | point at the UAT backends | point at the production backends |
| Consumers, keys, subscriptions | UAT applications | production applications |
| Users | testers and developers | the operations team |
Both can run on one server or on two. On two servers, follow Deploying on Linux once on each. On one server, the UAT instance is a second service beside the first:
A second instance on the same server¶
Every path, port and name differs from production; nothing is shared but the binary.
sudo mkdir -p /etc/apinx-uat
sudo cp /etc/apinx/apinx.yaml /etc/apinx-uat/apinx.yaml
sudo cp /etc/apinx/gateway.yaml /etc/apinx-uat/gateway.yaml
Edit /etc/apinx-uat/apinx.yaml: the console on 127.0.0.1:9200, the gateway file under
/etc/apinx-uat/, the access log under /var/lib/apinx-uat/logs/, and the UAT console
address:
console:
listen: "127.0.0.1:9200"
public_url: "https://uat-console.example.com"
proxy:
config_file: /etc/apinx-uat/gateway.yaml
access_log:
enabled: true
sink: file
path: /var/lib/apinx-uat/logs/access.log
and the listener in /etc/apinx-uat/gateway.yaml on 127.0.0.1:8082.
A database of its own, a master key of its own:
sudo -u postgres psql -c "CREATE DATABASE apinx_uat OWNER apinx;"
sudo tee /etc/apinx-uat/apinx.env >/dev/null <<EOF
APINX_SECURITY_MASTER_KEY=$(openssl rand -base64 32)
APINX_STORAGE_DRIVER=postgres
APINX_STORAGE_DSN=postgres://apinx:$PGPASS@127.0.0.1:5432/apinx_uat?sslmode=disable
EOF
sudo chmod 0600 /etc/apinx-uat/apinx.env
The unit, with its own state directory:
sed -e 's#/etc/apinx/#/etc/apinx-uat/#g' \
-e 's#StateDirectory=apinx apinx-keys#StateDirectory=apinx-uat apinx-uat-keys#' \
-e 's#/var/lib/apinx #/var/lib/apinx-uat #; s#/var/lib/apinx-keys#/var/lib/apinx-uat-keys#' \
-e 's#WorkingDirectory=/var/lib/apinx#WorkingDirectory=/var/lib/apinx-uat#' \
-e 's#Description=Apinx API gateway#Description=Apinx API gateway (UAT)#' \
/etc/systemd/system/apinx.service | sudo tee /etc/systemd/system/apinx-uat.service >/dev/null
sudo systemctl daemon-reload && sudo systemctl enable --now apinx-uat
sudo journalctl -u apinx-uat --no-pager | grep -A 3 "enter this claim token" | tail -4
Check the result with systemctl cat apinx-uat: every path must name apinx-uat.
In nginx, two more server blocks, the same as production's with uat-console.example.com →
127.0.0.1:9200 and uat-api.example.com → 127.0.0.1:8082, and two more DNS records. Open
https://uat-console.example.com and claim it with its own token.
Restrict UAT
UAT carries test data and looser limits. An allow list on its nginx blocks (your office,
your VPN) keeps it away from the internet.
What differs between the two, and how to keep it that way¶
The configuration (APIs, operations, policies, shared flows, products, plans) is the same in both: that is what you test in UAT and release to production. A few values are not:
| Value | How to handle it |
|---|---|
| Upstream targets (UAT vs production backend URLs) | Kept per environment: the promotion below leaves production's upstreams as they are |
| Secrets (backend client secrets, JWT shared secrets) | Write them as references, env:YY_CLIENT_SECRET, and set the variable in each instance's apinx.env; the same file then works in both. A sealed value from UAT cannot be read by production, which has a different master key, so promote references, never sealed values |
| Identity provider (issuer, JWKS URL) | The same in both when the provider serves both; otherwise kept per environment like upstreams |
| Listeners and hostnames | Per instance, never promoted |
| Consumers, keys, subscriptions, users | Data, not configuration: never part of an export, created in each environment |
Promoting from UAT to production¶
From a machine that reaches both consoles (or on the server), with a token for each:
UAT=https://uat-console.example.com
PROD=https://console.example.com
UAT_TOKEN=$(APINX_PASSWORD='…' apinxctl --server $UAT login --email you@example.com)
PROD_TOKEN=$(APINX_PASSWORD='…' apinxctl --server $PROD login --email you@example.com)
# 1. What UAT serves, as a file you keep in git
apinxctl --server $UAT --token $UAT_TOKEN export > release.yaml
# 2. Keep production's own upstreams and listeners: take them from production
apinxctl --server $PROD --token $PROD_TOKEN export > prod-now.yaml
yq eval-all 'select(fi == 0) * {"upstreams": (select(fi == 1) | .upstreams), "listeners": (select(fi == 1) | .listeners)}' \
release.yaml prod-now.yaml > release-prod.yaml
# 3. Review, import, see what changes, deploy
apinx gateway validate release-prod.yaml
apinxctl --server $PROD --token $PROD_TOKEN import release-prod.yaml
apinxctl --server $PROD --token $PROD_TOKEN diff
apinxctl --server $PROD --token $PROD_TOKEN publish -m "release 1.4 from UAT"
This works because operations refer to upstreams by name: give each upstream the same
name in both environments (test-api), with the UAT address in UAT and the production address in
production. A release that introduces a new upstream needs it created in production first, with
production's address, or validate names the operation that refers to it.
import replaces production's draft; nothing serves until publish. The production console's
Deployments page shows the same changes under Waiting to go live if you would rather
review and deploy there. If something is wrong after the deployment, Roll back to this on
the previous deployment in production's history restores it at once.
Import replaces the whole draft
Anything changed directly in production's console and not in UAT is overwritten by the
import. Make changes in UAT first, then promote; or export production before importing and
keep the file, so the previous state is one import away.
In CI¶
The same four steps run in a pipeline on a release tag, with the tokens as pipeline secrets:
validate on every pull request, import and diff into production on the tag, and publish
after an approval step. Configuration as code has the general loop.
Just testing, not isolating¶
If all you need is to try a new version of an API next to the current one on the same
instance, use versions: v2 on its own base path or
selected by a header, with its own upstream if it calls a different backend. Versions share the
instance's keys, limits and administrators, so they are a release tool, not a UAT environment.