.gitbay/wiki/CI.org

545ba0bcdea3b534903bd78c918c0c025a97eda7
gitbay/.gitbay/wiki/CI.org

216 lines · 11793 bytes

3 symbols in this file
  1#+title: CI: what a push queues
  2
  3Three mechanisms decide what a push does to CI, and they interact:
  4
  5- *Dedupe.* A job's result is a property of the commit's tree and the
  6  ref it ran for, since a job sees =GITBAY_REF=. A commit that already
  7  has a passed, queued or running build for a job on this ref is not
  8  queued again; a commit whose tree already passed a job on this ref
  9  gets that result as its status, naming the build it came from (#177).
 10  A merge onto the default branch is built there even when the branch
 11  passed. Only a
 12  trusted build counts, and for tree reuse only one on the image the
 13  job names: a fork's green build does not stand for the repository's
 14  own, so its commit is built again when it lands on a branch (#258). A
 15  job that names no =image:= is compared as naming none: its reuse does
 16  not notice the runner's default image changing, because reuse is
 17  decided when the push is queued, before any runner claims the build,
 18  and runners can differ in their default. Name the image in =ci.yml=
 19  to tie reuse to it; after an operator changes a runner's =-image=,
 20  =build trigger= builds a job afresh, since a triggered build is never
 21  reused. When a trusted and an untrusted build of the same commit both
 22  run, the one that finishes last sets =ci/<job>= on that commit. A
 23  failed, cancelled or abandoned build does not count: that commit runs
 24  again.
 25- *Path filters.* =paths= and =paths-ignore= on a job are evaluated
 26  against the files the push changed. The diff base is the old tip when
 27  it is an ancestor of the new one, and the merge base with the default
 28  branch otherwise: a new branch, or a force push after a rebase (#176).
 29  A filter that cannot be evaluated, because there is no diff base or
 30  the diff fails, runs the job rather than skipping it. A filter that
 31  excludes the push records a =skipped= status, which =require-checks=
 32  accepts (#172).
 33- *The reaper.* A build a runner claimed and never reported is failed by
 34  the scheduler's tick: two minutes after its log stream ended, or at
 35  the build deadline if no stream was ever seen (#179). Its status reads
 36  =build abandoned=.
 37
 38Which runner takes a build is the fourth: a build is claimed only by a
 39runner attached to its repository (or one polling with a full-scope
 40admin key), and an untrusted build only by one started with
 41=-untrusted=. A repository with no runner attached queues builds
 42nothing claims. See the Users page. Among what a runner may claim it
 43takes the oldest pending build, across every repository it serves;
 44a repository that must never wait on another gets a runner of its own
 45(decided in krz/gitbay#207). There is no cap on how many
 46builds an account queues or how often a schedule fires, and none is
 47planned (krz/gitbay#206): a tick queues nothing while the job's last
 48build is pending or running, so a repository with no runner holds one
 49row per scheduled job, and a schedule with a runner attached spends
 50its owner's compute, not the instance's.
 51
 52Scheduled jobs run on their cron against the default branch, never on
 53push; a default-branch push registers or updates them. Tag jobs run on
 54a matching tag push and nothing else.
 55
 56A running build is followed with =build log <owner/name> <n> --follow=:
 57the stored log, then output as the runner sends it, then the outcome
 58as =build <n> <status>= on stderr once the build ends. The exit code is
 590 whatever the outcome. A follow of a build still queued after ten
 60minutes ends on its own and says so on stderr, since nothing reaps a
 61queued build. The build page does the same without JavaScript while a
 62build is queued or running; =?follow=0= renders it once. An account
 63holds at most eight follows open, and signed-out viewers share one
 64account's eight. Over the JSON API the command answers when the build
 65ends, with the whole log. Read access is checked again every two
 66seconds: a follower who loses it is told the repository is not found.
 67A restart ends every open follow with a message saying so, rather
 68than holding the drain; follow again once the daemon is back.
 69
 70A failed build names the step it stopped at: the log's last line reads
 71=step 3/3 failed: exit 1=, and =build show= prints =failed step= (=3/3
 72go test ./... (exit 1)=) and =duration=. =build log <owner/name> <n>
 73--step failed= prints only that step's output, =--step 2= another one
 74(=0= is the clone before the first step), and =--tail 40= the last forty
 75lines of whichever was chosen; neither combines with =--follow=. The
 76build page folds the finished log into one section per step, opens the
 77failed one and links to it from the top as "Jump to failure". Builds
 78from before this reported no step; their last section is taken as the
 79failed one.
 80
 81* What a build can reach
 82
 83| Build     | Internet         | Runner's host                               | Private ranges |
 84|-----------+------------------+---------------------------------------------+----------------|
 85| trusted   | open             | forge's public 22, 80, 443; DNS on loopback | closed         |
 86| untrusted | TCP 80, 443; DNS | DNS on loopback                             | closed         |
 87
 88An untrusted build is a merge request head from a fork. It can fetch
 89modules and packages over HTTPS but cannot reach the forge, send mail,
 90or open ssh elsewhere. The forge is reached at the address in
 91=GITBAY_SSH=: on a runner that polls the daemon over loopback,
 92=169.254.1.2=, which pasta translates to the host's public address, so
 93a build's logins never arrive from =127.0.0.1=, where the runner polls.
 94Two nftables tables on the runner's host enforce this, one by the
 95runner's user and one by the cgroup each build runs in; the Threat-Model
 96page, "What a build can reach", says how and why, and the Admin page
 97how to install them (krz/gitbay#260). A runner off the daemon's host
 98gets none of this unless its operator adds it.
 99
100To check a runner, run =deploy/runner-auth-flood-test.sh= against a
101scratch repository, once as a push and once with =--untrusted=: the
102build probes what it reaches, then fails SSH logins with an expired key
103until the limiter locks its address, and the script checks that the
104runner still reported the build and kept polling, and that the build's
105log shows what the table allowed and refused.
106
107** Measured on bay1
108
1092026-09-29, runner and daemon at 8b73af2, kernel 6.12.107, nftables
1101.1.3, podman 5.4.2, the runner scoped to =cmc/runner-scratch=. pasta
111ran in the build's cgroup both times
112(=builds/trusted/build-2144=, =builds/untrusted/build-2146=). Both runs
113passed.
114
115| Probe                | trusted          | untrusted        |
116|----------------------+------------------+------------------|
117| DNS                  | ok               | ok               |
118| 169.254.1.2:22/80/443 | open            | refused          |
119| 169.254.1.2:2222     | refused          | refused          |
120| 10.0.0.1:80, 192.168.0.1:80 | refused   | refused          |
121| proxy.golang.org:443 | open             | open             |
122| github.com:22        | open             | refused          |
123| 12 logins            | 12 denied (sshd) | 12 refused (table) |
124
125The trusted build's logins arrived from the host's public address,
12646.232.248.67: ten =auth.expired= and one =auth.throttled= for it, none
127for =127.0.0.1=. The untrusted build's logins never reached sshd. The
128runner kept polling through both builds.
129
130* The table
131
132One =ci.yml= with five jobs, each isolating one rule:
133
134#+begin_src yaml
135jobs:
136  plain:
137    steps: [echo plain]
138  onapp:
139    paths: [app/**]
140    steps: [echo onapp]
141  notapp:
142    paths-ignore: [app/**]
143    steps: [echo notapp]
144  nightly:
145    schedule: "0 3 * * *"
146    steps: [echo nightly]
147  release:
148    tags: "v*"
149    steps: [echo release]
150#+end_src
151
152Every push below changes =app/x= and nothing else, so a push whose
153filters are evaluated queues =onapp= and skips =notapp=, and a push
154whose filters cannot be evaluated queues both. Each cell is what the
155push produced for that job; the commit's =ci/<job>= status follows:
156
157- =queued=: a build, and a =pending= status until the runner reports.
158  =queued, untrusted= is a build without the repository's secrets.
159- =skipped=: no build, and a =skipped= status naming the filter.
160- =reused=: no build, and a =success= status naming the earlier build
161  with the same tree.
162- =registered=: no build; the job's schedule is (re)registered.
163- =abandoned=: the build failed and the status reads =build abandoned=.
164- =—=: nothing new. A status the commit already had stands.
165
166| push | plain | onapp | notapp | nightly | release | ci/config |
167|---+---+---+---+---+---+---|
168| first push of the default branch | queued | queued | queued | registered | — | — |
169| push to the default branch | queued | queued | skipped | registered | — | — |
170| push to another branch | queued | queued | skipped | — | — | — |
171| a new branch, no old sha | queued | queued | skipped | — | — | — |
172| rebase onto a moved default branch, old not an ancestor | queued | queued | skipped | — | — | — |
173| rewritten commit, same tree as a passed build | reused | reused | skipped | — | — | — |
174| fast-forward of a commit built on another branch | queued | queued | — | registered | — | — |
175| squash merge onto the default branch, same tree as a branch build | queued | queued | skipped | registered | — | — |
176| a commit whose earlier build failed, on a new branch | queued | queued | — | — | — | — |
177| merge request head from a fork | queued, untrusted | queued, untrusted | queued, untrusted | — | — | — |
178| tag push | — | — | — | — | queued | — |
179| schedule tick on the default branch | — | — | — | queued | — | — |
180| schedule tick while the last scheduled build is still pending | — | — | — | — | — | — |
181| claimed builds whose runner vanished | abandoned | abandoned | — | — | — | — |
182| push to the default branch with an old sha that cannot be diffed | queued | queued | queued | registered | — | — |
183| push with a broken ci.yml | — | — | — | — | — | failure |
184| push with no ci.yml | — | — | — | — | — | — |
185
186Rows worth a second look:
187
188- The first push of the default branch has no diff base at all: the
189  merge base of the tip with itself is the tip. Every filtered job
190  runs. The same holds when the old sha cannot be diffed on the default
191  branch; on any other branch the merge base takes over and the filters
192  apply.
193- A rewritten commit with the same tree reuses =plain= and =onapp=
194  because the tree check comes before the filter. =notapp= never had a
195  passed build to reuse, and the push changed nothing, so the filter
196  skips it again.
197- A build stands for its commit, or its tree, only on the ref it ran
198  for: a job sees =GITBAY_REF= and may act on it, as one that publishes
199  only from the default branch does. A fast-forward or a squash merge
200  onto the default branch is built there although the branch passed.
201  =notapp= on the fast-forward keeps the skipped status the branch push
202  gave the same commit.
203- A failed build does not stand for its commit. The same commit pushed
204  to another branch runs again; =notapp= keeps its skipped status.
205- A merge request head from a fork has no diff base and, unlike a
206  branch push, no merge-base fallback: every job runs, without secrets.
207  Filtering a head down to no jobs would make it unmergeable under
208  =require-checks= (#172).
209- A context named in =repo settings require-contexts= must be one that
210  reports on merge request heads. A schedule-only or tag-only job never
211  reports there, so the gate stays pending (#258).
212
213=TestPushShapes= in =internal/hookd= runs every row against real git
214and the store, and =TestPushShapesTableOnWiki= checks that this page
215carries each row as the code has it. A row that changes fails there
216first.