Build from your CI
You do not need CI to build on Zaroz: a push starts a build. CI is for when you want your own tests to decide whether a commit goes live, or when something other than a push should start a build. There are three ways to combine them.
| You want | Use |
|---|---|
| Zaroz builds on every push, but only deploys when your CI is green | Wait for checks |
| Your CI runs the tests, then asks Zaroz to build that commit and waits for the result | The API |
| A tool or a schedule starts a build and needs no token | A deploy hook |
If your CI builds the image itself and only tells Zaroz to run it, that is the other way: see Deploy from CI with an API token.
Let your CI be the gate: wait for checks
In the service's Source tab, under When it builds and deploys, turn on Wait for checks.
- A push builds right away, so the image is ready.
- The build deploys only after the other checks on that commit pass: your tests in GitHub Actions, GitLab CI or Forgejo Actions.
- If a check fails, the build stays built and does not deploy. You can still choose Deploy this build by hand.
The build page shows Built. Waiting for this commit's other checks before deploying. while it waits. Zaroz waits for a limited time, and then the build stays built, not deployed.
This works for GitHub, GitLab, Forgejo and Gitea connections. A plain git address has no checks to read, so builds there deploy without waiting.
Start a build from CI with the API
Run your tests first and ask Zaroz to build the commit that passed. The job fails if the build fails.
Create a token
Make a project token as described in Create a token that can only deploy, with these permissions:
| Permission | Why |
|---|---|
services.deploy | Start, cancel and retry builds, and deploy one |
services.read | Wait for the build and read its result |
Add the token as a secret of your CI. The service instance id is the UUID in the service's URL in the console.
The two calls
Start the build for a commit. deploy: true deploys it when it succeeds, whatever the service's auto-deploy setting says:
Code
All fields are optional. A bare POST builds the head of the branch the service follows.
| Field | Meaning |
|---|---|
ref | A branch name or full ref. Default: the branch the service follows. |
sha | A commit on that ref. Default: its head. |
deploy | true deploys on success. false leaves the build for Deploy this build. Unset: the service's auto-deploy setting decides, and a ref outside its rule does not deploy. |
no_cache | Build without the cache. |
size | A builder size, small, medium or large. It changes the minutes used. |
Then wait for it. The call returns when the build ends or after up to 10 minutes, and says which:
Code
If timed_out is true, the build is still running. Call again. When terminal is true, build.status is succeeded, failed, canceled, superseded, expired or skipped. A failed build has failure_code and failure_detail: the codes are the ones in Troubleshooting.
A script that fails the job
Code
The job's exit code is the build's result. A build that succeeds and has deploy: true is deployed by Zaroz itself, on the server, so closing the job loses nothing. build.deployment_id is the deployment it started, once it has.
In your CI
GitHub Actions
Code
GitLab CI
Code
Set ZAROZ_TOKEN and ZAROZ_SERVICE as masked CI/CD variables.
Forgejo and Gitea Actions use the same syntax as GitHub Actions, with ${{ github.sha }} for the commit.
Anything else: run the script with the three variables set.
If CI should be the only thing that starts builds, set When it builds in Source so that it builds only when you start it. Otherwise a push builds once on its own and once from CI. A build of a commit that is already building returns that build, so the duplicate costs nothing.
If the build can cost money
A build that may go past your included minutes needs the cost to be confirmed when a person starts it. GET /service-instances/{id}/builds/estimate returns the most it can cost, and confirmed_max_cost_cents in the start request confirms it. Without it, such a start is refused. If your organization has not turned on extra minutes, a build that does not fit is refused with included_minutes_exhausted and the job fails. See Build minutes.
Start a build with a deploy hook
A deploy hook is a private URL. Calling it starts a build of the service. It needs no token, so it suits a tool that cannot hold one.
- In Source, open Deploy hooks, give the hook a name and choose Create hook.
- Copy the URL. It is shown only once, and anyone who has it can start a build, so treat it like a password.
- Call it:
Code
An empty POST builds the head of the branch the service follows. Add ?ref=<branch> or ?sha=<commit> to build another one. A build for a commit or ref that is outside the service's rule is built but waits for you to choose Deploy this build.
- A service can have 3 hooks, each with a name, its last use, and a Revoke button that stops the URL at once.
- A hook can start builds for this one service and nothing else.
- Each hook accepts up to 30 calls a minute.
On a plain git address, Zaroz finds new commits by checking every few minutes. A deploy hook starts the build at once.
What Zaroz reports on your commits
Every build reports its progress on the commit in your git provider, so your pull requests show it:
| Provider | What you see |
|---|---|
| GitHub | A check named Zaroz: your service |
| GitLab and Forgejo | A status named zaroz/your-service |
It goes from pending to success or failure with the build, and links to the build page. Use it as a required check if you want a pull request to prove it builds before merging.
Related
- Deploy from CI with an API token: when your CI builds the image.
- Build settings: the rules for what builds and deploys.
- Limits: concurrent builds and the queue.
