summaryrefslogtreecommitdiff
path: root/ambient-run.md
blob: b3cee4a7593c70c6ebc0962b7c0a5a06f0a8cd0f (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# Introduction

`ambient-run` runs continuous integration build locally. It creates a
virtual machine for each build. The VM has no network access, for
safety, security, and control. While `ambient-run` is meant to be a
usable tool on its own, it's also acts as a base component for a full
CI system. However, the full CI system is outside the scope of this
documents, which only considers `ambient-run` as a standalone tool.

The build VM contains all the tools needed for the build, and gets all
the source code and all the dependencies via virtual hard drives. The
build writes any artifacts is produces to another virtual hard drives.
Yet another virtual hard drive acts as a cache between builds, to
allow for incremental builds.

~~~dot
digraph "ambient-run" {
    src [label="source \n code" shape=folder]
    deps [label="dependencies" shape=folder]
    cache [label="cache" shape=folder]
    artifact [label="build \n artifacts" shape=folder]
    VM [label="build \n VM" shape=box3d]
    log [label="build log" shape=note]

    src -> VM
    deps -> VM
    cache -> VM
    VM -> cache
    VM -> artifact
    VM -> log
}
~~~

## Example

FIXME: This section will have an example of how to use `ambient-run`.

# Requirements and acceptance criteria

FIXME: This chapter will enumerate all requirements for `ambient-run`,
as acceptance criteria, using Subplot scenarios to document how to
verify the software meets the requirements.

## Stakeholders

The following people are explicitly named stakeholders for
`ambient-run`:

* Lars Wirzenius

Additional stakeholders will be added as they're discovered. They may
be specific people, or descriptions of groups.

## Configuration handling

### Show default per-user configuration file path name

_Requirement:_ `ambient-run` can tell the user the path name of the
default configuration file.

_Justification:_ As a user I want to be sure where the default
configuration file should be, whether it currently exists or not.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run

when I run ambient-run config --default --filename
then stdout matches regex ^/
then stdout contains "/.config/ambient-run/config.yaml"
~~~

### List configuration file paths

_Requirement:_ `ambient-run` can list the path name of the
configuration file it read.

_Justification:_ As a user I want to know what configuration files are
actually used.

_Stakeholder:_ Lars.

Note that we want to know only the names of files that are actually
used, not files that will be used if they exist.

~~~scenario
given an installed ambient-run

when I run ambient-run config --filename
then stdout is exactly ""

given file .config/ambient-run/config.yaml from default.yaml
when I run ambient-run config --filename
then stdout matches regex ^/
then stdout contains "/.config/ambient-run/config.yaml"
then stdout doesn't contain "extra.yaml"

given file extra.yaml
when I run ambient-run --config extra.yaml config --filename
then stdout contains "/.config/ambient-run/config.yaml"
then stdout contains "/extra.yaml"
~~~

### Show per-user configuration

_Requirement:_ One can query `ambient-run` for its full per-user
configuration. This means the union of the built-in default
configuration, any configuration files, and command line arguments.

_Justification:_ As a user I want to see the actual configuration
without having to deduce it myself.

_Stakeholder:_ Lars

~~~scenario
given an installed ambient-run
given file .config/ambient-run/config.yaml from default.yaml
given file extra.yaml
when I run ambient-run --config extra.yaml config
then stdout, as YAML, matches file full-config.yaml
~~~

~~~{#default.yaml .file .yaml}
image: /my/image.qcow2
max_cpus: 4
~~~

~~~{#extra.yaml .file .yaml}
image: /other/image.qcow2
max_cpus: 8
~~~

~~~{#full-config.yaml .file .yaml}
image: /other/image.qcow2
max_cpus: 8
~~~

### Show per-project configuration

_Requirement:_ One can query `ambient-run` for its full per-project
configuration. This means the union of the built-in defaults
and the configuration in the file.

_Justification:_ As a user I want to see the actual configuration
without having to deduce it myself.

_Stakeholder:_ Lars

~~~scenario
given an installed ambient-run
given file .config/ambient-run/config.yaml from default.yaml
given file project.yaml
when I run ambient-run project project.yaml
then stdout, as YAML, matches file full-project.yaml
~~~

~~~{#project.yaml .file .yaml}
shell: |
  cargo test
~~~

~~~{#full-project.yaml .file .yaml}
source: .
shell: |
  cargo test
image: /my/image.qcow2
artifact: null
artifact_max_size: null
dependencies: null
cache: null
~~~

### Show per-build configuration

## Building with ambient-run

### Smoke test build works

_Requirement:_ I can do a simple build that just runs the shell
command `echo hello, world` using `ambient-run`.

_Justification:_ This is the simplest possible project build, and if
it works, then at least the very fundamental parts of `ambient-run`
work, and vice versa.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file smoke/project.yaml from smoke-project.yaml
given image file image.qcow2 specified for test suite
when I run ambient-run build smoke/project.yaml --log hello.log
then file hello.log contains "hello, world"
~~~
~~~{#smoke-project.yaml .file .yaml}
source: .
shell: |
  #!/bin/bash
  set -xeuo pipefail
  echo hello, world
image: image.qcow2
~~~

### Build gets source code

_Requirement:_ The build gets a copy of the specified source code.

_Justification:_ This is the simplest possible project build, and if
it works, then at least the very fundamental parts of `ambient-run`
work, and vice versa.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file foo-project.yaml
given file foo/README.md from foo-project.yaml
given image file image.qcow2 specified for test suite
when I run ambient-run build foo-project.yaml --log foo.log
then file foo.log contains "README.md"
~~~


~~~{#foo-project.yaml .file .yaml}
source: foo
shell: |
  #!/bin/bash
  ls -l
image: image.qcow2
~~~

### Build produces an artifact

_Requirement:_ The build can produce an artifact.

_Justification:_ Without this a build can't produce something that can
be used after the build has finished.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file artifact-project.yaml
given file foo/README.md from foo-project.yaml
given image file image.qcow2 specified for test suite
when I run ambient-run build artifact-project.yaml --log foo.log
then file foo.tar exists
when I run tar tf foo.tar
then stdout contains "README.md"
~~~


~~~{#artifact-project.yaml .file .yaml}
source: foo
shell: |
  #!/bin/bash
  tar -cf /dev/vdc .
image: image.qcow2
artifact: foo.tar
~~~

### Fail build that tries to produce an unwanted artifact

_Requirement:_ If an artifact output is not specified for the project,
fail a build that tries to make one.

_Justification:_ If a build tries to create an artifact, but one isn't
wanted, the build should fail.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file no-artifact-project.yaml
given file foo/README.md from foo-project.yaml
given image file image.qcow2 specified for test suite
when I try to run ambient-run build no-artifact-project.yaml --log foo.log
then file foo.log contains "EXIT CODE: 2"
then exit code is 1
~~~


~~~{#no-artifact-project.yaml .file .yaml}
source: foo
shell: |
  #!/bin/bash
  tar -cf /dev/vdc .
image: image.qcow2
~~~

### Fail build that tries to produce an oversize artifact

_Requirement:_ If a build produces an artifact that is too large, the
build should fail.

_Justification:_ Without a limit, a malicious build could fill all
available storage space, which is a denial-of-service attack.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file small-artifact-project.yaml
given file foo/README.md from foo-project.yaml
given image file image.qcow2 specified for test suite
when I try to run ambient-run build small-artifact-project.yaml --log foo.log
then file foo.log contains "EXIT CODE: 2"
then exit code is 1
~~~


~~~{#small-artifact-project.yaml .file .yaml}
source: foo
shell: |
  #!/bin/bash
  tar -cf /dev/vdc .
image: image.qcow2
artifact: foo.tar
artifact_max_size: 1
~~~

### Build is given dependencies

_Requirement:_ The build is provided with its dependencies.

_Justification:_ Without its dependencies, a project can't build.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file dep-project.yaml
given file foo/README.md from dep-project.yaml
given file foo-deps/library.file from dep-project.yaml
given image file image.qcow2 specified for test suite
when I run ambient-run build dep-project.yaml --log foo.log
then file foo.log contains "/workspace/deps/library.file"
~~~


~~~{#dep-project.yaml .file .yaml}
source: foo
shell: |
  #!/bin/bash
  find /workspace -type f
image: image.qcow2
dependencies: foo-deps
~~~

### Cache is persistent between builds

_Requirement:_ The build can persist files between builds in a cache
device.

_Justification:_ This allows incremental builds and caching of build
artifacts.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
given file cache-project.yaml
given file foo/README.md from cache-project.yaml
given a directory foo-cache
given image file image.qcow2 specified for test suite
then file foo-cache/cached.file does not exist
when I run ambient-run build cache-project.yaml --log foo.log
then file foo.log contains "creating cached file"
then file foo-cache/cached.file exists
when I run ambient-run build cache-project.yaml --log foo2.log
then file foo2.log contains "cache has file"
~~~


~~~{#cache-project.yaml .file .yaml}
source: foo
shell: |
  #!/bin/bash
  set -xeuo pipefail
  find /workspace -ls
  file="/workspace/cache/cached.file"
  if [ -e "$file" ]; then
    echo "cache has file"
  else
    echo "creating cached file"
    touch "$file"
  fi
image: image.qcow2
cache: foo-cache
~~~

### Build gets the resources is demands

## Utility functionality

The `ambient-run` command has some subcommands that are meant to be
useful for debugging and testing, but rarely used by normal users.
This section is for verifying those.

### Create a virtual drive from directory

_Requirement:_ I can create a virtual drive from the contents of a
directory.

_Justification:_ This is useful for, at least, verifying that the
functionality dealing with virtual drives works, independently of the
rest of the program.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
when I create directory src
when I write "my project!" to file src/README.md
when I run ambient-run vdrive create --root src my.drive
then file my.drive exists
when I run ambient-run vdrive list my.drive
then stdout contains "README.md"
when I run ambient-run vdrive extract my.drive --to extracted
then file extracted/README.md contains "my project!"
~~~

### Create an empty virtual drive

_Requirement:_ I can create an virtual drive with a desired size.

_Justification:_ This is useful for, at least, verifying that the
functionality dealing with virtual drives works, independently of the
rest of the program.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
when I run ambient-run vdrive create my.drive --size 1024
then file my.drive exists and is 1024 bytes long
when I run ambient-run vdrive list my.drive
then stdout is exactly ""
~~~

### Create a virtual drive of wanted size

_Requirement:_ I can create an virtual drive with a desired size with
contents of a directory.

_Justification:_ This is useful for, at least, verifying that the
functionality dealing with virtual drives works, independently of the
rest of the program.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-run
when I create directory src
when I write "my project!" to file src/README.md
when I run ambient-run vdrive create my.drive --size 10000 --root src
then file my.drive exists and is 10000 bytes long
when I run ambient-run vdrive list my.drive
then stdout contains "README.md"
when I run ambient-run vdrive extract my.drive --to extracted
then file extracted/README.md contains "my project!"
~~~

## Errors during build
### Bad per-user configuration

_Requirement:_ `ambient-run` fails if the per-user configuration is
bad.

_Justification:_ As a user I want to get an error if the configuration
is wrong.

_Stakeholder:_ Lars

~~~scenario
given an installed ambient-run
given file garbage.yaml
when I try to run ambient-run --config garbage.yaml config
then command fails
then stderr contains "garbage.yaml"
~~~

~~~{#garbage.yaml .file .yaml}
This is not a valid YAML file.
~~~

### Bad per-project configuration

_Requirement:_ `ambient-run` fails if the project configuration is
bad.

_Justification:_ As a user I want to get an error if the configuration
is wrong.

_Stakeholder:_ Lars

~~~scenario
given an installed ambient-run
given file garbage.yaml
when I try to run ambient-run project garbage.yaml
then command fails
then stderr contains "garbage.yaml"
~~~

### Build produces too large an artifact
### Build produces too large a cache
### Build demands too many CPUs
### Build demands too much RAM
### Build takes too long

# Architecture of `ambient-run`

## Overview

FIXME: This section gives the very high level view of how
`ambient-run` works: the build VM, the inputs, the cache, the artifact
output, and how the VM and the outside world interact. It also
describes that there is per-user and per-project and per-build
configuration.

## Per-user configuration

FIXME: This section describes the configuration the user sets that
applies to all use of `ambient-run`.

## Per-project configuration

FIXME: This section describes the configuration that applies to all
builds of a project.

## Per-build configuration

FIXME: This section describes the configuration for one specific
build, i.e., one run of `ambient-run`.

## Requirements for the build VM

FIXME: This section describes what `ambient-run` expects of the VM to
do, what inputs it gets, what outputs it produces, and how it gets the
per-build instructions.