: nply/minci

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
# AGENTS.md - Minci

## What this project is

Minci is a small C/POSIX shell CI system derived from Kristaps Dzonsons' BSD.lv code.  Keep changes conservative, explicit, and easy to audit.  Prefer simple C, POSIX shell, semantic HTML, and small CSS changes over abstractions or dependencies.

## Architecture

- `minci.sh` is the runner.  It reads `~/.minci` or `/etc/minci`, fetches configured repositories, sources a Jobfile when present, runs jobs, and submits signed results.
- `main.c` is the CGI/FastCGI server.  It accepts signed result submissions, handles small control requests, and renders the web UI.
- `db.ort` is the openradtool schema.  Generated files such as `db.c`, `extern.h`, `db.sql`, and `minci.db` must not be committed.
- `minci.css` is the entire UI stylesheet.
- `README.md` is user/admin documentation.
- `design-plans/` and `evals/` on the `ai` branch hold AI-oriented plans and operational evaluations.

## Active model

- Projects are configured in the minci database and in runner config as `repo = ...` lines.
- Runner branch selection is global per config via `branch = ...`.
- A repository may provide `.config/Jobfile`.
- A runner operator may instead provide `jobfile = ...` or `/etc/minci.d/<repo>/Jobfile` to keep deployment logic outside the tested branch.
- Jobfile `triggers` name the branch/ref being tested, not necessarily the branch that stores an operator-held Jobfile.
- Result submissions go to `minci.cgi`/`minci.fcgi`; execution happens in `minci.sh`.

## Current deployment notes from cdg-1 / ci.nply.org

- Public service: `https://ci.nply.org/cgi-bin/minci.cgi` and FastCGI at `/cgi-bin/minci.fcgi`.
- Installed binaries: `/usr/lib/cgi-bin/minci.cgi`, `/usr/lib/cgi-bin/minci.fcgi`.
- Installed runner: `/usr/local/bin/minci.sh`.
- Runner state and DB: `/var/lib/minci`.
- CSS: `/usr/share/minci/minci.css`.
- The deployed FastCGI binary was built with `DATADIR=/var/lib/minci`.
- For the web start experiment it was built with `RUNNER=/usr/local/sbin/minci-submit`.
- `www-data` is in the `gitolite3` and `git` groups on cdg-1; the runner normally executes as user `git`.

## Gitolite hook model

- Gitolite uses `LOCAL_CODE => $rc{GL_ADMIN_BASE}/local`.
- Repository `post-receive` hooks are symlinks to `/home/git/.gitolite/local/hooks/common/post-receive`.
- Repo-specific hooks are not enabled in `.gitolite.rc`, so the common local hook is the active adapter path.
- The common hook should stay repository-agnostic:
  - mirror only when `gitolite.mirror.simple` is set;
  - minci only when `gitolite.minci = true` is set.
- Do not hardcode project names in the hook.

## Build/test commands

On a host with openradtool/kcgi/sqlbox available:

```sh
make
```

For cdg-1 style deployment builds:

```sh
make DATADIR=/var/lib/minci \
  CFLAGS='-g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-unused-parameter -DDATADIR="/var/lib/minci" -DRUNNER="/usr/local/sbin/minci-submit"'
```

On systems without openradtool tools, `make` will fail because `ort-c-source`, `ort-c-header`, and related tools are missing.  Do not treat that as a code failure.

Always run:

```sh
sh -n minci.sh
```

## Code rules

- Preserve the ISC license header and existing style.
- Keep shell POSIX-compatible; avoid Bashisms.
- Keep C changes small and in the style already present: explicit helper functions, simple ownership, `kasprintf`/`free`, and existing kcgi patterns.
- Avoid new tables unless the feature truly needs durable state.
- Be careful with result submission signing.  The server verifies MD5 signatures built from sorted/formatted fields and the user's API secret.
- Do not commit generated files: `db.c`, `extern.h`, `db.sql`, `minci.db`, object files, CGI binaries.

## Known caveat

A direct web start request currently creates the start marker.  The wrapper `/usr/local/sbin/minci-submit` works when invoked as `www-data`, and gitolite push-triggered offload is the reliable trigger path.  If relying on web-triggered execution, re-test FastCGI process-manager behaviour before assuming the runner actually starts from the web request.