summaryrefslogtreecommitdiff
path: root/ambient-driver.md
blob: 073ab9ca487dc1c6962bc4e9e787d7ab2d378b5b (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
# Introduction

`ambient-driver` is a prototype for running CI on a project, using
`ambient-run`.

# Smoke test

_Requirement:_ The `ambient-driver` tool can show it's runtime
configuration.

_Justification:_ If this doesn't work, there's no hope of anything
else working, either.

_Stakeholder:_ Lars


~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
when I run ambient-driver config
then stdout contains "ambient.log"
~~~

~~~{#config.yaml .file .yaml}
log: ambient.log
run_ci: run-ci
~~~

# Allows specifying a configuration file

_Requirement:_ The `ambient-driver` tool allows the user to specify
which configuration file to use.

_Justification:_ This is very convenient when one wants to try things
and temporarily not use the default configuration file. This happens
both for experimentation and for testing.

_Stakeholder:_ Lars


~~~scenario
given an installed ambient-driver
given file special.yaml
when I run ambient-driver --config special.yaml config
then stdout contains "special.log"
~~~

~~~{#special.yaml .file .yaml}
log: special.log
run_ci: run-ci
~~~

# Capture build log when running

_Requirement:_ The stdout/stderr output of the commands executed by
the CI run must be captured.

_Justification:_ This is the primary way for the user to know what
happened during a run.

_Stakeholder:_ Lars.

Note that we can't use `.` for the current directory as the `source`
field in the project file due to how Subplot sets up a temporary data
directory for each scenario, and sets `TMPDIR` to that directory.
This would mean that `.` as `source` would create a tar archive in the
temporary directory that tries to add itself, which creates an
infinitely large tar archive.

~~~scenario
given an installed ambient-driver
given an Ambient VM image ambient.qcow2
given file .config/ambient-driver/config.yaml from config.yaml
given file hello.yaml
given a directory srcdir
when I run env AMBIENT_LOG=trace ambient-driver run hello.yaml
then file ambient.log contains "well hello there, friend"
~~~

~~~{#hello.yaml .file .yaml}
projects:
  hello:
    image: ambient.qcow2
    source: srcdir
    plan:
    - action: shell
      shell: |
        echo well hello there, friend
~~~

# Relative filenames in project files

_Requirement:_ When a project file has a relative filename, it's
relative to the directory containing the project file.

_Justification:_ The user can then run `ambient-driver run` from
anywhere, not just the source directory.

_Stakeholder:_ Lars.

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given a directory path/to/project/srcdir
given an Ambient VM image ambient.qcow2
when I run mv ambient.qcow2 path/to/project/
given file path/to/project/hello.yaml from hello.yaml
when I run env AMBIENT_LOG=trace ambient-driver run path/to/project/hello.yaml
then file ambient.log contains "well hello there, friend"
~~~

# Working directory in pre- and post-plan actions

_Requirement:_ When a pre- or post-plan action is executed, the
current working directory should be the source directory.

_Justification:_ Many actions can only usefully be executed in the
source directory.

_Stakeholder:_ Lars.

Note that we can't use `.` for the current directory as the `source`
field in the project file due to how Subplot sets up a temporary data
directory for each scenario, and sets `TMPDIR` to that directory.
This would mean that `.` as `source` would create a tar archive in the
temporary directory that tries to add itself, which creates an
infinitely large tar archive.

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given an Ambient VM image ambient.qcow2
given file cwd.yaml
given a directory path/to/project/srcdir
when I run env AMBIENT_LOG=ambient_driver::action=trace ambient-driver run cwd.yaml
then stderr matches regex INFO.*cwd:.*/path/to/project/srcdir
~~~

~~~{#cwd.yaml .file .yaml}
projects:
  pwd:
    image: ambient.qcow2
    source: path/to/project/srcdir
    pre_plan:
    - action: pwd
    post_plan:
    - action: pwd
    plan:
    - action: shell
      shell: |
        pwd
~~~

# Run CI only for some projects

_Requirement:_ When the projects file has more than one project, user
can choose only specific ones to run CI for.

_Justification:_ User may be only interested in one project right now.

_Stakeholders:_ Lars

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given an Ambient VM image ambient.qcow2
given file multi.yaml
given a directory foo
given a directory bar
when I run env AMBIENT_LOG=debug ambient-driver run --dry-run multi.yaml foo
then stderr contains "project foo: NOT running CI"
then stderr doesn't contain "project bar:"
~~~

~~~{#multi.yaml .file .yaml}
projects:
  foo:
    image: ambient.qcow2
    source: foo
    plan:
    - action: shell
      shell: |
        echo foo project
  bar:
    image: ambient.qcow2
    source: bar
    plan:
    - action: shell
      shell: |
        echo bar project
~~~
# List names of projects

_Requirement:_ The user can list names of projects in a projects file.

_Justification:_ This is handy for checking and scripting.

_Stakeholders:_ Lars

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given an Ambient VM image ambient.qcow2
given file multi.yaml
given a directory foo
given a directory bar
when I run ambient-driver projects multi.yaml
then stdout is exactly "bar\nfoo\n"
~~~

# List names of actions

_Requirement:_ The user can list names of projects in a projects file.

_Justification:_ This is handy for checking and scripting.

_Stakeholders:_ Lars

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given an Ambient VM image ambient.qcow2
when I run ambient-driver actions
then stdout contains "pre_actions:\n"
then stdout contains "\nactions:\n"
then stdout contains "\npost_actions:\n"
~~~
# Cache persists between CI runs

_Requirement:_ Cache data is persisted between CI runs.

_Justification:_ This allows incrementally building a project after
changes.

_Stakeholders:_ Lars

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given an Ambient VM image ambient.qcow2
given file cache.yaml
given a directory srcdir

when I run ambient-driver run cache.yaml
then file ambient.log contains "counter is now 1."

when I run ambient-driver run cache.yaml
then file ambient.log contains "counter is now 2."

when I run ambient-driver run cache.yaml
then file ambient.log contains "counter is now 3."
~~~

~~~{#cache.yaml .file .yaml}
projects:
  hello:
    image: ambient.qcow2
    source: srcdir
    plan:
    - action: shell
      shell: |
        cache=/workspace/cache
        counter="$cache/counter"
        if [ -e "$counter" ]; then
            n="$(expr "$(cat "$counter")" + 1)"
            echo "$n" > "$counter"
        else
            echo 1 > "$counter"
        fi
        echo "counter is now $(cat "$counter")."
        find "$cache" -ls
~~~
# Publish files via rsync

_Requirement:_ Artifacts can be published via rsync to a server.

_Justification:_ This allows publishing many kinds of things.

_Stakeholders:_ Lars

~~~scenario
given an installed ambient-driver
given file .config/ambient-driver/config.yaml from config.yaml
given an Ambient VM image ambient.qcow2
given file rsync.yaml
given a directory srcdir
given file srcdir/data.dat from rsync.yaml

given a directory serverdir
when I run ambient-driver run rsync.yaml --target serverdir
then file serverdir/hello.txt contains "hello, world"
~~~

~~~{#rsync.yaml .file .yaml}
projects:
  hello:
    image: ambient.qcow2
    source: srcdir
    plan:
    - action: shell
      shell: |
        echo hello, world > /workspace/artifacts/hello.txt
    post_plan:
    - action: rsync
~~~