Commit 2b36034ba0

2b36034ba0d1a30802724e65b4aad3a2e776dfb9

parent: 8ddd998102

Verified · cmc ci/build: success ci/quality: success ci/test: success ci/vuln: success

cmc <hello@cleberg.net> · 2026-10-31 08:16 UTC

Runner attachments can name the jobs they claim

repo runner add <repo> --jobs <job,...> narrows an attachment; --jobs
all restores every job and a re-add without --jobs keeps the list.
runner next claims through ClaimBuildFor, which limits each narrowed
repository to its jobs. repo runner list gains a JOBS column and the
settings page takes the list when attaching. Migration 0082 adds
runner_repos.jobs.

This lets krz/omaha-metro-blotter keep daily-pull on the laptop runner,
which can reach its geo-blocked source, while the bay1 runner takes its
code scan.

Changelog for v1.47.0.

Layout: unified · split

.gitbay/wiki/Parity.org +1
@@ -220,6 +220,7 @@ there shows the app's rendering rather than the one the web page shows.
220220| mirrors | yes | no | yes |
221221| custom pages domains | yes | no | yes |
222222| runners attach, list, detach | yes | yes | n/a |
223| runner attached for some jobs | yes | yes | n/a |
223224| import from a remote | yes | yes | yes |
224225| topics, website | yes | yes | yes |
225226| visibility | yes | yes | yes |
.gitbay/wiki/Users.org +7
@@ -890,6 +890,13 @@ detaches one (the key stays on your account; =keys remove= drops it).
890890A runner key reaches only the runner protocol and read-only git, so a
891891build step that reads it off disk cannot administer your account.
892892
893=repo runner add owner/name --jobs a,b < key.pub= narrows an
894attachment to the named jobs, so two runners can share a repository by
895job: one that reaches a geo-blocked data source for the repository's
896own job (=--jobs daily-pull=), another with the code scanning image
897(=--jobs gitbay-security=). A re-add without =--jobs= keeps the list;
898=--jobs all= restores every job. =repo runner list= shows it.
899
893900* Large files (LFS)
894901
895902Standard Git LFS works over both transports with no setup beyond the
CHANGELOG.org +12
@@ -4,6 +4,18 @@ Versioning follows semver from v0.1.0. Database migrations run
44automatically on daemon start; upgrade notes appear per release when
55anything beyond "replace the binary and restart" is needed.
66
7* v1.47.0 — 2026-10-31
8
9Migration 0082.
10
11- =repo runner add <repo> --jobs <job,...> < key.pub= narrows an
12 attachment to the named jobs; =--jobs all= restores every job, and a
13 re-add without =--jobs= keeps the list. =repo runner list= has a
14 JOBS column, and the settings page takes the list when attaching.
15 Two runners can split a repository by job, for instance the
16 repository's own job on a runner that can reach its data and the
17 code scan on one with the scanning image.
18
719* v1.46.1 — 2026-10-31
820
921No migrations.
e2e/codescan_test.go +52
@@ -63,3 +63,55 @@ steps = ['mkdir -p "$GITBAY_RESULTS"', 'cp scan.sarif "$GITBAY_RESULTS/scan.sari
6363 t.Fatalf("scan set a status:\n%s", out)
6464 }
6565}
66
67// A runner attached for the code scan only leaves the repository's own
68// jobs to its other runner: the shape of a repository whose job must run
69// somewhere the scan image is not.
70func TestRunnerAttachedForJobs(t *testing.T) {
71 t.Parallel()
72 inst := startInstanceWith(t, `[security]
73image = "localhost/scan:1"
74steps = ['mkdir -p "$GITBAY_RESULTS"', 'cp empty.sarif "$GITBAY_RESULTS/x.sarif"']
75`)
76 inst.runner = buildRunner(t)
77 aliceKey := inst.newKey(t, "alice")
78 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
79 scanKey := inst.newKey(t, "scanner")
80 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
81 t.Fatalf("repo create: %s", errOut)
82 }
83 pub, err := os.ReadFile(scanKey + ".pub")
84 if err != nil {
85 t.Fatal(err)
86 }
87 if _, errOut, code := inst.ssh(t, aliceKey, string(pub), "repo", "runner", "add", "alice/app", "--jobs", "gitbay-security"); code != 0 {
88 t.Fatalf("runner add --jobs: %s", errOut)
89 }
90 work := t.TempDir()
91 env := inst.gitEnv(aliceKey)
92 mustGit(t, work, env, "clone", "-q", inst.sshURL("alice/app"), "w")
93 dir := filepath.Join(work, "w")
94 os.MkdirAll(filepath.Join(dir, ".gitbay"), 0o755)
95 os.WriteFile(filepath.Join(dir, ".gitbay", "ci.yml"), []byte("jobs:\n pull:\n steps:\n - echo pulled\n"), 0o644)
96 os.WriteFile(filepath.Join(dir, "empty.sarif"), []byte(`{"version":"2.1.0","runs":[]}`), 0o644)
97 mustGit(t, dir, env, "checkout", "-q", "-b", "main")
98 mustGit(t, dir, env, "add", ".")
99 mustGit(t, dir, env, "commit", "-q", "-m", "ci")
100 mustGit(t, dir, env, "push", "-q", "origin", "main")
101 inst.ssh(t, aliceKey, "", "repo", "security", "enable", "alice/app")
102 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "security", "run", "alice/app"); code != 0 {
103 t.Fatalf("security run: %s", errOut)
104 }
105
106 // The pull build is older, but this runner may only take the scan.
107 if out := inst.runnerOnce(t, scanKey); !strings.Contains(out, "gitbay-security") || strings.Contains(out, " pull ") {
108 t.Fatalf("runner:\n%s", out)
109 }
110 if out := inst.runnerOnce(t, scanKey); strings.Contains(out, "pull") {
111 t.Fatalf("the scan runner claimed the pull job:\n%s", out)
112 }
113 out, _, _ := inst.ssh(t, aliceKey, "", "build", "list", "alice/app")
114 if !strings.Contains(out, "pull\tpending") {
115 t.Fatalf("pull was not left pending:\n%s", out)
116 }
117}
internal/ci/ci.go +4
@@ -35,6 +35,10 @@ const (
3535
3636var jobName = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,39}$`)
3737
38// ValidJobName reports whether name could name a job: one of ci.yml's, or
39// SecurityJob.
40func ValidJobName(name string) bool { return jobName.MatchString(name) }
41
3842// imageRef matches an OCI image reference conservatively: registry path
3943// segments, an optional :tag and an optional @sha256: digest. This string
4044// becomes an argument to `podman run`, and a repository's config file must
internal/control/build.go +6 −1
@@ -701,11 +701,16 @@ func runRunnerNext(c *Ctx, args []string) int {
701701 }
702702 }
703703 untrusted := f.Has("--untrusted")
704 // An attachment may name the jobs this key claims in its repository.
705 jobs, err := c.Store.RunnerJobFilters(key.ID)
706 if err != nil {
707 return c.fail(protocol.ExitFailure, "%v", err)
708 }
704709 var b store.Build
705710 var repo store.Repo
706711 var ok bool
707712 for attempt := 0; attempt < maxOrphanSkip; attempt++ {
708 b, ok, err = c.Store.ClaimBuild(repoIDs, untrusted)
713 b, ok, err = c.Store.ClaimBuildFor(repoIDs, untrusted, jobs)
709714 if err != nil {
710715 return c.fail(protocol.ExitFailure, "%v", err)
711716 }
internal/control/runnerrepo.go +51 −9
@@ -4,9 +4,12 @@ import (
44 "errors"
55 "fmt"
66 "io"
7 "slices"
8 "strings"
79
810 "golang.org/x/crypto/ssh"
911
12 "gitbay.org/gitbay/internal/ci"
1013 "gitbay.org/gitbay/internal/policy"
1114 "gitbay.org/gitbay/internal/protocol"
1215 "gitbay.org/gitbay/internal/store"
@@ -19,9 +22,12 @@ import (
1922// read-only git.
2023func init() {
2124 register(Command{Path: []string{"repo", "runner", "add"},
22 Summary: "attach a runner's public key to a repository",
23 Usage: "repo runner add <owner/name> < key.pub",
24 Examples: []string{"repo runner add krz/gitbay < key.pub"},
25 Summary: "attach a runner's public key to a repository",
26 Usage: "repo runner add <owner/name> [--jobs <job,...>|all] < key.pub",
27 Flags: []Flag{
28 {"--jobs", "<job,...>", "claim only these jobs here; all restores every job", "every job, or as before on a re-add"},
29 },
30 Examples: []string{"repo runner add krz/gitbay < key.pub", "repo runner add krz/app --jobs gitbay-security < key.pub"},
2531 ReadsStdin: true,
2632 MintsCredential: true, NeedsRecentSignIn: true, Run: runRepoRunnerAdd})
2733 register(Command{Path: []string{"repo", "runner", "list"},
@@ -37,10 +43,21 @@ func init() {
3743}
3844
3945func runRepoRunnerAdd(c *Ctx, args []string) int {
40 f, err := c.parseArgs(args, flagSpec{MaxPos: 1, Usage: "repo runner add <owner/name> < key.pub"})
46 f, err := c.parseArgs(args, flagSpec{Values: []string{"--jobs"}, MaxPos: 1, Usage: c.Cmd.Usage})
4147 if err != nil || len(f.Pos) != 1 {
4248 return c.usage()
4349 }
50 var jobs []string
51 if v := f.Value("--jobs"); v != "" && v != "all" {
52 for _, j := range strings.Split(v, ",") {
53 if !ci.ValidJobName(j) {
54 return c.fail(protocol.ExitUsage, "bad job name %q", j)
55 }
56 if !slices.Contains(jobs, j) {
57 jobs = append(jobs, j)
58 }
59 }
60 }
4461 repo, code := resolveRepo(c, f.Pos[0], policy.CanAdmin)
4562 if code >= 0 {
4663 return code
@@ -92,9 +109,26 @@ func runRepoRunnerAdd(c *Ctx, args []string) int {
92109 if err := c.Store.AttachRunner(key.ID, repo.ID); err != nil {
93110 return c.fail(protocol.ExitFailure, "%v", err)
94111 }
95 c.Store.Audit(c.User.ID, "repo.runner.add", map[string]any{"repo": repo.Path(), "fingerprint": fp})
96 d := map[string]string{"fingerprint": fp, "repo": repo.Path()}
112 // Without --jobs a re-add leaves the attachment's jobs as they were.
113 if f.Has("--jobs") {
114 if err := c.Store.SetRunnerJobs(key.ID, repo.ID, jobs); err != nil {
115 return c.fail(protocol.ExitFailure, "%v", err)
116 }
117 }
118 audit := map[string]any{"repo": repo.Path(), "fingerprint": fp}
119 if f.Has("--jobs") {
120 audit["jobs"] = strings.Join(jobs, ",")
121 }
122 c.Store.Audit(c.User.ID, "repo.runner.add", audit)
123 d := map[string]any{"fingerprint": fp, "repo": repo.Path()}
124 if len(jobs) > 0 {
125 d["jobs"] = jobs
126 }
97127 return c.emit(d, func(w io.Writer) {
128 if len(jobs) > 0 {
129 fmt.Fprintf(w, "runner %s attached to %s for %s\n", fp, repo.Path(), strings.Join(jobs, ", "))
130 return
131 }
98132 fmt.Fprintf(w, "runner %s attached to %s\n", fp, repo.Path())
99133 })
100134}
@@ -115,7 +149,7 @@ func runRepoRunnerList(c *Ctx, args []string) int {
115149 runners = []store.RepoRunner{}
116150 }
117151 return c.emitView(runners, func(w io.Writer) {
118 tb := c.table(w, "FINGERPRINT", "ALGO", "USER", "SEEN", "HELD")
152 tb := c.table(w, "FINGERPRINT", "ALGO", "USER", "SEEN", "HELD", "JOBS")
119153 for _, r := range runners {
120154 seen := r.LastSeen
121155 if seen == "" {
@@ -125,7 +159,11 @@ func runRepoRunnerList(c *Ctx, args []string) int {
125159 if r.BuildNumber != 0 {
126160 held = fmt.Sprintf("%s #%d %s since %s", r.BuildRepo, r.BuildNumber, r.BuildJob, r.StartedAt)
127161 }
128 tb.row(cRef(r.Fingerprint), cText(r.Algo), cText(r.Username), cAge(seen), cText(held))
162 jobs := "all"
163 if len(r.Jobs) > 0 {
164 jobs = strings.Join(r.Jobs, ",")
165 }
166 tb.row(cRef(r.Fingerprint), cText(r.Algo), cText(r.Username), cAge(seen), cText(held), cText(jobs))
129167 }
130168 tb.flush()
131169 }, func() screen {
@@ -139,7 +177,11 @@ func runRepoRunnerList(c *Ctx, args []string) int {
139177 if r.LastSeen != "" {
140178 seen = "seen " + relAge(r.LastSeen, termNow())
141179 }
142 rows[i] = rowOf(cFlexRef(r.Fingerprint), lead, cText(r.Username), cMeta(r.Algo, seen, held))
180 only := ""
181 if len(r.Jobs) > 0 {
182 only = "only " + strings.Join(r.Jobs, ",")
183 }
184 rows[i] = rowOf(cFlexRef(r.Fingerprint), lead, cText(r.Username), cMeta(r.Algo, seen, held, only))
143185 }
144186 return listScreen("Runners", rows,
145187 action{"Runners", []string{"repo", "runner", "remove", repo.Path(), "<fingerprint>"}},
internal/control/runnerrepo_test.go +35
@@ -122,3 +122,38 @@ func TestRepoRunnerAddRefusesWrongKeys(t *testing.T) {
122122 t.Fatalf("attached anyway: %+v", runners)
123123 }
124124}
125
126// --jobs narrows an attachment, a re-add without it keeps the list, and
127// all restores every job; runner next claims accordingly.
128func TestRepoRunnerAddJobs(t *testing.T) {
129 st, repo, uid := newQueueTestRepo(t)
130 add := func(args ...string) string {
131 t.Helper()
132 c, out := repoRunnerCtx(t, st, uid, false, testRunnerPub)
133 if code := runRepoRunnerAdd(c, append([]string{repo.Path()}, args...)); code != protocol.ExitOK {
134 t.Fatalf("add %v: exit %d %s", args, code, out.String())
135 }
136 c, out = repoRunnerCtx(t, st, uid, false, "")
137 runRepoRunnerList(c, []string{repo.Path()})
138 return out.String()
139 }
140 if out := add("--jobs", "gitbay-security,gitbay-security"); !strings.Contains(out, `"jobs":["gitbay-security"]`) {
141 t.Fatalf("list after --jobs: %s", out)
142 }
143 if out := add(); !strings.Contains(out, `"jobs":["gitbay-security"]`) {
144 t.Fatalf("a re-add without --jobs dropped the list: %s", out)
145 }
146 c, out := repoRunnerCtx(t, st, uid, false, testRunnerPub)
147 if code := runRepoRunnerAdd(c, []string{repo.Path(), "--jobs", "Bad Name"}); code != protocol.ExitUsage {
148 t.Fatalf("bad job name: exit %d %s", code, out.String())
149 }
150
151 keys, _ := st.ListSSHKeys(uid)
152 filters, err := st.RunnerJobFilters(keys[0].ID)
153 if err != nil || len(filters[repo.ID]) != 1 {
154 t.Fatalf("filters = %v %v", filters, err)
155 }
156 if out := add("--jobs", "all"); strings.Contains(out, `"jobs"`) {
157 t.Fatalf("all did not restore every job: %s", out)
158 }
159}
internal/control/testdata/plain/repo-runner-list.txt +1 −1
@@ -1 +1 @@
1SHA256:z/fSv0Z0RZS+Lccbc6ZoOWwt/fbj1VFJGSBKQbo4icE ssh-ed25519 alice never idle
1SHA256:z/fSv0Z0RZS+Lccbc6ZoOWwt/fbj1VFJGSBKQbo4icE ssh-ed25519 alice never idle all
internal/httpd/settings.go +6 −1
@@ -106,6 +106,7 @@ func (s *Server) settingsFormWith(w http.ResponseWriter, r *http.Request, u stor
106106 "events": submitted.Get("events"),
107107 "name": submitted.Get("name"),
108108 "new-owner": submitted.Get("new-owner"),
109 "jobs": submitted.Get("jobs"),
109110 }
110111 }
111112 s.render(w, "settings.html", settingsPage{
@@ -247,7 +248,11 @@ func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store.
247248 s.settingsRedirect(w, r, "paste the runner's public key")
248249 return
249250 }
250 msg, ok := s.runControlStdin(u, []string{"repo", "runner", "add", repo}, body+"\n")
251 argv := []string{"repo", "runner", "add", repo}
252 if jobs := strings.Join(strings.Fields(strings.ReplaceAll(v("jobs"), ",", " ")), ","); jobs != "" {
253 argv = append(argv, "--jobs", jobs)
254 }
255 msg, ok := s.runControlStdin(u, argv, body+"\n")
251256 if !ok {
252257 s.settingsFormWith(w, r, u, msg, r.Form)
253258 return
internal/store/builds.go +32 −2
@@ -106,6 +106,12 @@ func scanBuild(row interface{ Scan(...any) error }) (Build, error) {
106106// repository — are skipped unless untrusted is set: they run a stranger's
107107// code, which only a runner that isolates should take.
108108func (s *Store) ClaimBuild(repoIDs []int64, untrusted bool) (Build, bool, error) {
109 return s.ClaimBuildFor(repoIDs, untrusted, nil)
110}
111
112// ClaimBuildFor is ClaimBuild where jobs narrows some repositories to the
113// jobs named for them (RunnerJobFilters).
114func (s *Store) ClaimBuildFor(repoIDs []int64, untrusted bool, jobs map[int64][]string) (Build, bool, error) {
109115 tx, err := s.DB.Begin()
110116 if err != nil {
111117 return Build{}, false, err
@@ -117,11 +123,33 @@ func (s *Store) ClaimBuild(repoIDs []int64, untrusted bool) (Build, bool, error)
117123 query += " AND trusted = 1"
118124 }
119125 if len(repoIDs) > 0 {
120 marks := strings.TrimSuffix(strings.Repeat("?,", len(repoIDs)), ",")
121 query += " AND repo_id IN (" + marks + ")"
126 var whole []int64
127 var narrowed []string
122128 for _, id := range repoIDs {
129 names, ok := jobs[id]
130 if !ok {
131 whole = append(whole, id)
132 continue
133 }
134 narrowed = append(narrowed, "(repo_id = ? AND job IN ("+marks(len(names))+"))")
123135 args = append(args, id)
136 for _, n := range names {
137 args = append(args, n)
138 }
124139 }
140 var alts []string
141 if len(whole) > 0 {
142 alts = append(alts, "repo_id IN ("+marks(len(whole))+")")
143 // The narrowed repos' args were appended first; put these in
144 // front to match the clause order.
145 front := make([]any, len(whole))
146 for i, id := range whole {
147 front[i] = id
148 }
149 args = append(front, args...)
150 }
151 alts = append(alts, narrowed...)
152 query += " AND (" + strings.Join(alts, " OR ") + ")"
125153 }
126154 query += " ORDER BY id LIMIT 1"
127155 var id int64
@@ -518,3 +546,5 @@ func (s *Store) SuccessBuildFor(repoID int64, sha, job string) (Build, bool, err
518546 }
519547 return b, err == nil, err
520548}
549
550func marks(n int) string { return strings.TrimSuffix(strings.Repeat("?,", n), ",") }
internal/store/builds_test.go +37
@@ -653,3 +653,40 @@ func TestBuildIDsNotReusedAfterRepoDelete(t *testing.T) {
653653 t.Fatalf("next build took id %d; a runner may still hold %d", got, claimed)
654654 }
655655}
656
657// A repository narrowed to some jobs yields only those; the others in the
658// claim are unaffected.
659func TestClaimBuildForNarrowsByJob(t *testing.T) {
660 s := open(t)
661 if err := s.MigrateUp(); err != nil {
662 t.Fatal(err)
663 }
664 uid, _ := s.CreateUser("cmc", true)
665 blotter, _ := s.CreateRepo("user", uid, "blotter", "public")
666 site, _ := s.CreateRepo("user", uid, "site", "public")
667 s.CreateBuild(blotter, "daily-pull", "a1", "main", `["true"]`, "", "", true)
668 scan, _ := s.CreateBuild(blotter, "gitbay-security", "a1", "main", `["true"]`, "", "", true)
669 site1, _ := s.CreateBuild(site, "deploy", "b1", "main", `["true"]`, "", "", true)
670
671 jobs := map[int64][]string{blotter: {"gitbay-security"}}
672 var got []string
673 for {
674 b, ok, err := s.ClaimBuildFor([]int64{blotter, site}, false, jobs)
675 if err != nil {
676 t.Fatal(err)
677 }
678 if !ok {
679 break
680 }
681 got = append(got, b.Job)
682 if (b.RepoID == blotter && b.Number != scan) || (b.RepoID == site && b.Number != site1) {
683 t.Errorf("claimed %+v", b)
684 }
685 }
686 if strings.Join(got, ",") != "gitbay-security,deploy" {
687 t.Fatalf("claimed %v; daily-pull must stay for another runner", got)
688 }
689 if b, ok, _ := s.ClaimBuild([]int64{blotter}, false); !ok || b.Job != "daily-pull" {
690 t.Fatalf("unnarrowed claim = %+v %v", b, ok)
691 }
692}
internal/store/migrations/0082_runner_jobs.down.sql added +1
@@ -0,0 +1 @@
1ALTER TABLE runner_repos DROP COLUMN jobs;
internal/store/migrations/0082_runner_jobs.up.sql added +5
@@ -0,0 +1,5 @@
1-- An attachment may name the jobs its runner claims in that repository,
2-- comma-separated; '' is every job. It lets two runners share a
3-- repository by job: one that can reach a geo-blocked source for the
4-- repository's own job, another with the code scanning image.
5ALTER TABLE runner_repos ADD COLUMN jobs TEXT NOT NULL DEFAULT '';
internal/store/runners.go +45 −8
@@ -1,6 +1,9 @@
11package store
22
3import "sort"
3import (
4 "sort"
5 "strings"
6)
47
58// Runner is one runner key as the instance admin sees it.
69type Runner struct {
@@ -26,11 +29,13 @@ type RepoRunner struct {
2629 Algo string `json:"algo"`
2730 Username string `json:"username"`
2831 AddedAt string `json:"added_at"`
29 LastSeen string `json:"last_seen,omitempty"`
30 BuildRepo string `json:"build_repo,omitempty"`
31 BuildNumber int64 `json:"build_number,omitempty"`
32 BuildJob string `json:"build_job,omitempty"`
33 StartedAt string `json:"started_at,omitempty"`
32 // Jobs are the only jobs this runner claims here; none is every job.
33 Jobs []string `json:"jobs,omitempty"`
34 LastSeen string `json:"last_seen,omitempty"`
35 BuildRepo string `json:"build_repo,omitempty"`
36 BuildNumber int64 `json:"build_number,omitempty"`
37 BuildJob string `json:"build_job,omitempty"`
38 StartedAt string `json:"started_at,omitempty"`
3439}
3540
3641// AttachRunner lets a key claim a repository's builds. Attaching twice is
@@ -40,6 +45,34 @@ func (s *Store) AttachRunner(keyID, repoID int64) error {
4045 return err
4146}
4247
48// SetRunnerJobs narrows an attachment to the named jobs; none restores
49// every job.
50func (s *Store) SetRunnerJobs(keyID, repoID int64, jobs []string) error {
51 _, err := s.DB.Exec("UPDATE runner_repos SET jobs = ? WHERE key_id = ? AND repo_id = ?",
52 strings.Join(jobs, ","), keyID, repoID)
53 return err
54}
55
56// RunnerJobFilters maps each repository a key is attached to with a job
57// list to that list. Repositories it may claim every job in are absent.
58func (s *Store) RunnerJobFilters(keyID int64) (map[int64][]string, error) {
59 rows, err := s.DB.Query("SELECT repo_id, jobs FROM runner_repos WHERE key_id = ? AND jobs != ''", keyID)
60 if err != nil {
61 return nil, err
62 }
63 defer rows.Close()
64 out := map[int64][]string{}
65 for rows.Next() {
66 var id int64
67 var jobs string
68 if err := rows.Scan(&id, &jobs); err != nil {
69 return nil, err
70 }
71 out[id] = strings.Split(jobs, ",")
72 }
73 return out, rows.Err()
74}
75
4376// DetachRunner removes one attachment by fingerprint. The key itself stays.
4477func (s *Store) DetachRunner(repoID int64, fingerprint string) error {
4578 res, err := s.DB.Exec(`DELETE FROM runner_repos WHERE repo_id = ?
@@ -104,7 +137,7 @@ func (s *Store) RunnerAttached(keyID, repoID int64) (bool, error) {
104137// ListRepoRunners is every key attached to a repository with its last
105138// poll and the build it holds, oldest attachment first.
106139func (s *Store) ListRepoRunners(repoID int64) ([]RepoRunner, error) {
107 rows, err := s.DB.Query(`SELECT k.fingerprint, k.algo, u.username, rr.added_at,
140 rows, err := s.DB.Query(`SELECT k.fingerprint, k.algo, u.username, rr.added_at, rr.jobs,
108141 COALESCE(rs.last_seen, ''),
109142 COALESCE(COALESCE(bu.username, bo.name) || '/' || br.name, ''),
110143 COALESCE(b.number, 0), COALESCE(b.job, ''), COALESCE(b.started_at, '')
@@ -124,10 +157,14 @@ func (s *Store) ListRepoRunners(repoID int64) ([]RepoRunner, error) {
124157 var out []RepoRunner
125158 for rows.Next() {
126159 var r RepoRunner
127 if err := rows.Scan(&r.Fingerprint, &r.Algo, &r.Username, &r.AddedAt, &r.LastSeen,
160 var jobs string
161 if err := rows.Scan(&r.Fingerprint, &r.Algo, &r.Username, &r.AddedAt, &jobs, &r.LastSeen,
128162 &r.BuildRepo, &r.BuildNumber, &r.BuildJob, &r.StartedAt); err != nil {
129163 return nil, err
130164 }
165 if jobs != "" {
166 r.Jobs = strings.Split(jobs, ",")
167 }
131168 out = append(out, r)
132169 }
133170 return out, rows.Err()
internal/web/templates/settings.html +4 −1
@@ -291,7 +291,7 @@
291291<section id="runners"><h2>Runners</h2>
292292{{if .Runners}}
293293<ul class="protlist">
294{{range .Runners}}<li><code>{{.Fingerprint}}</code> <span class="meta">{{.Username}}{{if .LastSeen}}, last poll {{when .LastSeen}}{{else}}, never polled{{end}}{{if .BuildNumber}}, running {{.BuildRepo}} #{{.BuildNumber}} {{.BuildJob}}{{end}}</span>
294{{range .Runners}}<li><code>{{.Fingerprint}}</code> <span class="meta">{{.Username}}{{if .LastSeen}}, last poll {{when .LastSeen}}{{else}}, never polled{{end}}{{if .BuildNumber}}, running {{.BuildRepo}} #{{.BuildNumber}} {{.BuildJob}}{{end}}{{if .Jobs}}, only {{join .Jobs ", "}}{{end}}</span>
295295 <form method="post" action="{{$base}}" class="inline">
296296 <input type="hidden" name="field" value="runner-remove">
297297 <input type="hidden" name="fingerprint" value="{{.Fingerprint}}">
@@ -305,6 +305,9 @@
305305 <label for="runner-key">Attach a runner</label>
306306 <p class="hint">Install <code>gitbay-runner</code>, run <code>gitbay-runner init</code>, and paste the key it prints. The runner builds your commits with the repository's secrets; merge requests from forks wait unless it runs with <code>-untrusted</code>.</p>
307307 <textarea id="runner-key" name="key" rows="3" spellcheck="false" placeholder="ssh-ed25519 AAAA… (from gitbay-runner init)">{{index .Submitted "key"}}</textarea>
308 <label for="runner-jobs">Jobs</label>
309 <p class="hint">Leave empty for every job. Name jobs, comma-separated, to have this runner claim only those here, for instance <code>gitbay-security</code> on a runner with the code scanning image.</p>
310 <input type="text" id="runner-jobs" name="jobs" value="{{index .Submitted "jobs"}}">
308311 <button type="submit" class="btn">Attach</button>
309312</form>
310313</section>