path:
/README.md
5.96 KB | plain
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Introduction
This is a minimal CI ("continuous integration") system used by BSD.lv
projects.
It uses a shell script as the test runner and a
[BCHS](https://learnbchs.org) back-end server for recording and
displaying results.
The server is assumed to run on a [OpenBSD](https://www.openbsd.org)
system, although it's trivially portable.
The CI test runner performs the following:
1. clone or freshen a project's git repository
2. configure the software (all use
[oconfigure](https://github.com/kristapsdz/oconfigure))
3. build
4. run tests
5. fake install
6. distribution check (runs build, tests, install on distributed
archive)
The results of this sequence (failure is implied if the last step isn't
reached) are sent to the CI report server.
CI reports may also be viewed on the server over a web interface.
Tested projects are simply identified by name. There is currently no
way to verify that project results are actually from a project.
CI testers are identified by authentication tokens. (These are
internally associated with an e-mail.) These tokens are used to sign
submitted reports.
# Repositories
Repositories are identified only by name. The test runner uses the name
component of the repository URL as its reported repository. So with a
repository of `https://github.com/you/yourproj.git`, the name is
`yourproj`.
Add repositories to the database as follows:
```sh
name="foobar" ; \
echo "INSERT INTO project (name) VALUES (\"$name\")" | \
sqlite3 path/to/minci.db
```
The unique name must be less than 32 bytes. Adjust the database
filename as appropriate.
The repository so identified must either contain `.config/Jobfile` or
conform to the following:
1. Accessible by git, with the name being the URL filename.
2. `./configure PREFIX=install_prefix`
3. make
4. make regress
5. make install
6. make distcheck
The `make` must be BSD make.
# CI testers
To generate a CI tester, add a row to the `user` table of the database.
Set the e-mail to anything you'd like.
The API key and secret are used to authenticate messages and should be
random. Assuming your operating system has a good random number
generator, you can use:
```sh
email="foo@bar.com" ; \
apikey="$RANDOM" ; \
apisecret="`jot -r -c 32 'A' '{' | sed 's!\\$!-!g' | rs -g0`" ; \
ctime="`date +%s`" ; \
echo "INSERT INTO user (email,apikey,apisecret,ctime) \
VALUES (\"$email\",\"$apikey\",\"$apisecret\",\"$date\")" | \
sqlite3 path/to/minci.db
```
(The `sed` makes sure that the final character isn't an escape.)
Set `foo@bar.com` to be the user's email address and adjust the database
filename.
# Test Runner
The test runner is just a shell script.
If you'd like to participate in a **minci** CI community, the shell
script, server URL, and credentials are all you need.
**The test runner should be run as an ordinary user**. Do not run it
with super user privileges. Ideally it should have its own user, as a
repository might accidentally try to overwrite files it shouldn't.
First, download or otherwise acquire the test runner,
[minci.sh](minci.sh). It should probably be in your *bin* directory
with execute permission.
Next, create *~/.minci*. (If this isn't found, */etc/minci* is used.)
You can start with the [minci.example](minci.example) example.
```
apikey = 12345
apisecret = abcdefghijklmnopqrstuvwxyz123456
#bsdmake = bmake
server = https://yourdomain/cgi-bin/minci.cgi
repo = https://github.com/somename/yourrepo1.git
repo = https://github.com/somename/yourrepo2.git
```
There can be arbitrary space around the equal signs. `bsdmake` is
useful for Linux machines, since repositories are assumed to use BSD
make and not GNU make, which is the default `make` on some machines.
In this example, there are two repositories, `yourrepo1` and
`yourrepo2`, which must be represented in the database.
The runner tests `origin/master` unless `branch` is set in the
configuration. If a checked-out repository contains `.config/Jobfile`,
that file is sourced as POSIX shell. It may define lowercase variables
and job functions:
```
project=yourrepo1
triggers="refs/heads/master: build"
build() {
make
}
```
The `triggers` value is a newline-separated list of `ref: job...` lines.
For matching refs, minci executes the named functions in order and
submits each as a job. During execution, `srcdir`, `workdir`, `pkgdir`,
`destdir`, and `target` are set for the job.
Ideally, the runner should be executed daily by `cron`:
```
@daily $HOME/bin/minci >/dev/null 2>&1
```
The `PATH` variable may need to be set to include */usr/local/bin* or as
required by the operating system.
Alternatively, the script may be run manually for instant gratification.
# Security
First, the server only runs on OpenBSD and makes significant use of pledging,
unveiling, and separation using
[openradtool](https://kristaps.bsd.lv/openradtool)'s underlying
[kcgi](https://kristaps.bsd.lv/kcgi) and
[sqlbox](https://kristaps.bsd.lv/sqlbox) features.
Messages between the runner and server are authenticated by hashing the entire
message (in a well-defined order) with the user's secret API key. The server,
which also has the secret key, hashes the message contents as well and compares
the signature. If the signature matches, the report is authentic.
To further prevent tampering, **minci** uses the role-based access
control of [openradtool](https://kristaps.bsd.lv/openradtool) to wall
off producers (those generating reports) with consumers (those viewing
them).
# Report viewing
**minci** has a built-in web interface at the same address used for
posting reports.
It features a dashboard "index" view showing the most recent reports
grouped by project and generating machine. This gives a quick look at
what systems currently work and don't work. Jobfile submissions are
shown as runs containing one or more named jobs, optionally with artifact
links.
It also allows for browsing by project, date, or seeing the individaul
report log, including full failure logs.
The interface supports HTTP caching, compression, and the styling is
responsive and includes a night mode.