Skip to content

About

CI action that checks a DeployEx rollout actually reached every host, and fails the pipeline when a version is ghosted.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

rollout-guard

CI action that checks a DeployEx rollout actually reached every host, and fails the pipeline when a version is ghosted.

Why

Writing a new version to current.json does not mean it is running yet. DeployEx picks it up on its own schedule, and with several hosts connected, a pod ghosts a bad version on its own: each one answers for itself only. A pipeline that moves on right after the write, or checks a single host and calls it done, can report success on a rollout that is still in progress elsewhere, or has already failed on one pod out of several. DeployEx's own Agent API guide had exactly that bug in its own example snippet: prose that said "ask each host", backed by a script that only queried one.

rollout-guard polls every host until the version is running everywhere, one of them ghosts it, or a timeout is reached - never on a single check, and never on just one host.

A ghosted version was never serving anything: DeployEx never stops the previous one until the new one passes its readiness check, so there is no user-facing outage to react to here. Failing the job matters so current.json does not stay pointed at code that will never run - not to avert an outage, since there isn't one.

Prerequisites

  • The Agent API turned on (agent_api.enabled: true in deployex.yaml) on every host being checked.
  • A token with the read scope, from a secret, never a literal in the workflow file.
  • The base URL of every host's Agent API (e.g. http://10.0.1.11:5002). rollout-guard does not discover hosts on its own - no DNS lookup, no cluster API - the calling pipeline already knows where it just deployed, so it supplies the list.

rollout-guard only checks a rollout. It does not publish the release, write current.json, or decide what a ghosted version means for your storage - see What this does not do (yet).

Usage

name: Deploy

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v7

      # However the pipeline already publishes a release today: write the
      # tarball to S3/GCS, update current.json, etc. rollout-guard starts
      # after this, it does not replace it.
      - name: Publish release
        run: ./scripts/publish.sh

      - uses: deployex/rollout-guard@v1
        with:
          hosts: |
            http://10.0.1.11:5002
            http://10.0.1.12:5002
          token: ${{ secrets.DEPLOYEX_AGENT_API_TOKEN }}
          app: myphoenixapp
          version: ${{ steps.publish.outputs.version }}

Pinned to a major version, not a commit SHA: a tag can move to point at different code later, which a SHA cannot. This repository's own .github/workflows/ci.yml makes the same choice, paired with a .github/dependabot.yml for the github-actions ecosystem that opens a PR whenever a pinned major version has a newer release. If you would rather not depend on that, pin to a full commit SHA instead and keep the tag as a trailing comment, e.g. uses: deployex/rollout-guard@abc1234 # v1.0.0.

Inputs

Input Required Default Description
hosts yes - Base URL of every DeployEx Agent API to check, one per line.
token yes - An Agent API token with the read scope.
app yes - The monitored app's name, as it appears in GET /v1/apps.
version yes - The version that was just published.
timeout-seconds no 900 How long to keep polling a rollout that is neither running everywhere nor ghosted anywhere, before giving up. See How long to wait.
poll-interval-seconds no 5 How long to wait between polls of every host.
max-unreachable-polls no 0 How many polls in a row a host may give no HTTP response before the rollout fails with unreachable. 0 never fails on it: the host is waited for until timeout-seconds.

Outputs

Output Description
result "running", "ghosted", "timed-out", "unauthorized", "not-found", or "unreachable".
host-statuses The last known status of every host, as comma-separated host=status pairs.

How it works

On every poll, rollout-guard asks each host in turn for GET /v1/apps/:name, and classifies the answer:

  • Ghosted - version is in that host's ghosted_versions. Fails immediately: a pipeline does not need to keep polling a version that already failed, on any host.
  • Running - every instance of the app on that host is on version with status "running".
  • Pending - reachable, neither of the above yet. The rollout is still in progress on that host.
  • Unreachable - no HTTP response at all. Treated the same as pending, since a host can be briefly unreachable for reasons that have nothing to do with the rollout (a load balancer not yet routing to it, a transient network blip). A host that never answers is something else, a wrong address or a host that is gone: with max-unreachable-polls set, that many polls in a row with no answer fail the job with result: unreachable, without waiting for the timeout.
  • Unauthorized / not-found - the token was refused, or the host does not monitor an app by this name. Fails immediately, the same as ghosted: retrying either one for the full timeout would never help.

Once every host reports running, or any host reports ghosted/unauthorized/not-found, rollout-guard stops and reports that result. Otherwise it waits poll-interval-seconds and checks again, until timeout-seconds runs out.

How long to wait

timeout-seconds has to be longer than the time DeployEx itself gives a version before it ghosts it, or a bad version shows up here as timed-out a moment before the host would have answered ghosted:

  • A version that does not hold is ghosted after deploy_rollback_timeout_ms of the application, 10 minutes by default. The default of timeout-seconds, 15 minutes, leaves a margin over that default. An application with a longer rollback timeout needs a longer timeout-seconds.
  • Hosts that are connected to each other deploy one at a time. The last host starts when the others are done, so a rollout that succeeds takes the time of one host times the number of hosts.

The token is given to the scripts through the environment and to curl on its standard input, never as an argument, so it does not show in the process list of a runner that other jobs share.

What this does not do (yet)

  • Publish the release. Writing the tarball to release storage and updating current.json is already handled outside DeployEx today (per-cloud publish scripts, devops/docker/publish-app.sh for the container trial), and is specific to where your releases live. rollout-guard starts after that step, it does not replace it.
  • Write current.json back on a ghosted version. rollout-guard reports that a version was ghosted and fails the job; it does not write the previous version back to current.json itself. What "the previous version" means is a property of your release storage, not of the Agent API this action calls. Nothing about this is a "rollback" in the usual sense - the application was never affected, see Why.
  • Discover hosts. No DNS lookup, no Kubernetes API, no peers_dns_query resolution - hosts is given explicitly by the calling pipeline.
  • Verify a hot upgrade actually applies. That is a different, pre-merge question, answered by relup-guard-elixir and relup-guard-erlang: building old and new releases and running a real upgrade against a throwaway node, before the PR merges. rollout-guard runs after a merge has already been deployed, against the real fleet, and only ever reads its state - it has no opinion on whether the upgrade mechanism itself was sound.

Tested against

fixtures/fake-agent-api.py is a minimal stand-in for the Agent API: it serves GET /v1/apps/:name from a JSON state file read fresh on every request, so a test step can change what the next poll sees - including a version becoming running partway through, not just the two terminal states - by overwriting that file, with no server restart needed.

.github/workflows/ci.yml runs rollout-guard against that fixture on every push:

  • The main case, two hosts both already running the target version.
  • A version ghosted on one host out of two, asserting the job fails fast rather than waiting out the timeout.
  • A wrong token, and a typo'd app name, each asserted to fail fast with their own distinct result, rather than being treated as "still rolling out".
  • A host that starts on the old version and only becomes running a couple of polls later - the one scenario that actually exercises the polling loop, not just a result available on the very first check.
  • A version that never arrives and is never ghosted either, with a short timeout-seconds, asserting the job fails with result: timed-out.
  • A host that never answers, next to one that runs the version, with max-unreachable-polls, asserting the job fails with result: unreachable long before the timeout.
  • shellcheck against every script, on every push.

Releasing

make release VERSION=1.0.0

Tags the current commit v1.0.0, moves the floating v1 tag to point at it too, and pushes both - the same convention actions/checkout and most of the GitHub Actions ecosystem use, so a consumer pinned to @v1 picks up new v1.x.y releases automatically.

The same thing is also available as a manual GitHub Actions workflow (.github/workflows/release.yml), for releasing without a local checkout: open the Actions tab, select Release, click Run workflow, pick main as the branch, and enter the version. It runs the same make release target, so the two stay in sync by construction rather than needing to be kept consistent by hand.

References

License

MIT, see LICENSE.md.

About

CI action that checks a DeployEx rollout actually reached every host, and fails the pipeline when a version is ghosted.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages