cmd / deploy

deploy is a Go CLI that deploys services to Render from the latest origin/main.

Run it:

go run ./cmd/deploy

It reads these environment variables from .env:

Flow

  1. Fetch origin/main merged by sockeye.
  2. Stop unless I am on main and my main matches origin/main.
  3. Read the Render status page. If it lists an open incident, or does not answer, print a red warning and ask "deploy anyway?".
  4. Compare each service's live commit SHA to origin/main. Skip a service that already runs it.
  5. Show the commits that would ship, and ask one time.
  6. Deploy app-jobs, then wait for it to reach live so its migration finishes before app-web.
  7. Deploy app-web with no second prompt.
  8. Record each service in sockeye as it reaches live.

Example session:

$ go run ./cmd/deploy
From https://sockeye.example.com/git/app
 * branch            main       -> FETCH_HEAD
```
a1b2c3d4e fix session expiry on token refresh
f5e6d7c8b add retry logic to webhook delivery
```
deploy app-jobs? (y/n) y
deploying app-jobs...
waiting for app-jobs deploy dep-abc123 to go live...
app-jobs live
deploying app-web...
waiting for app-web deploy dep-def456 to go live...
app-web live

deployed app-jobs, app-web

When both services run the same commit, the script prints the commit list one time.

Render status

The Render REST API has no status endpoint. status.render.com is an Atlassian Statuspage, and its public JSON summary at /api/v2/summary.json lists each incident that is not resolved. The render.OpenIncidents function reads that list with no API key.

With no open incident, the deploy continues with no prompt. With an open incident, the script prints each incident's name, status, impact, and link:

WARNING: Render has an open incident:
  Degraded deploys (investigating, minor impact) https://stspg.io/abc
deploy anyway? (y/n)

A status page that does not answer also gets a warning, because no answer does not mean no incident.

Render API client

The render package (render/client.go) wraps these endpoints:

WaitForDeploy polls every 10s with a 30 minute timeout. Any terminal state other than live is an error. A failed migration appears as pre_deploy_failed.

Recording the deploy

The script POSTs a record to sockeye as each service reaches live. A failure partway through still records what shipped. A failed POST prints a warning and does not stop the run, because the deploy happened and sockeye only mirrors it.

The script holds no sockeye token. It asks git for the token that soc login stored for the host:

in := "protocol=https\nhost=sockeye.example.com\n\n"
c := exec.Command("git", "credential", "fill")
c.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")

The script retrieves the token first, so a missing token halts the deploy before any service deploys without a record. Recording deploys connects errors to the release SHA that introduced them.

Design

The script deploys from main only, and my main must match origin/main. It prints the commit range from what is live to HEAD, so a git worktree or a stale main would show a range that is not what ships.

The SHA decides whether a service deploys, not an empty commit range. A range is also empty when live is ahead of origin/main, which is a rollback, and when my repo does not hold the live commit. In those cases the script prints why the list is missing.

The first "y" covers the services after it. A deploy that does not reach live ends the run, so app-web starts only after app-jobs succeeds. If I answer "n" for app-jobs, the script warns that a later service may run against an older schema, and asks about app-web.

A prompt reads an end of stdin as "n". An unattended run does not deploy, and it does not wait for an answer that never comes.

← All articles