Skip to content

Commit b672201

Browse files
Jswigivotron
andauthored
cli: add options step attribute (#881)
Add ability of specifying options for a step, initially supported for the docker runner. The YAML spec is extended to support arbitrary options. This also contains tests and additions to to documentation. Co-authored-by: Ivo Jimenez <[email protected]>
1 parent bed6500 commit b672201

File tree

6 files changed

+15
-3
lines changed

6 files changed

+15
-3
lines changed

docs/sections/cli_features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CLI feautures
1+
# CLI features
22

33
## New workflow initialization
44

docs/sections/cn_workflows.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ attribute.
4545
| `secrets` | **optional** A list of strings representing the names of secret variables to define<br>in the environment of the container for the step. For example,<br>`secrets: ["SECRET1", "SECRET2"]`. |
4646
| `skip_pull` | **optional** A boolean value that determines whether to pull the image before<br>executing the step. By default this is `false`. If the given container<br>image already exist (e.g. because it was built by a previous step in<br>the same workflow), assigning `true` skips downloading the image from<br>the registry. |
4747
| `dir` | **optional** A string representing an absolute path inside the container to use as the<br>working directory. By default, this is `/workspace`. |
48+
| `options` | **optional** Container configuration options. For instance:<br>`options: {ports: {8888:8888}, interactive: True, tty: True}`. Currently only<br> supported for the docker runtime. See the parameters of `client.containers.runs()`<br> in the [Docker Python SDK](https://docker-py.readthedocs.io/en/stable/containers.html?highlight=inspect) for the full list of options |
4849

4950
### Referencing images in a step
5051

@@ -400,6 +401,11 @@ question (see [here][engconf] for more).
400401

401402
[engconf]: ./cli_features#customizing-container-engine-behavior
402403

404+
405+
Alternatively, to restrict a configuration to a specific step in a workflow, set the desired parameters in the step's `options`
406+
**Note**: this is currently only supported for the Docker runtime
407+
408+
403409
## Resource Managers
404410

405411
Popper can execute steps in a workflow through other resource managers

src/popper/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class WorkflowParser(object):
3535
"matching-rule": "any",
3636
"mapping": {"regex;(.+)": {"type": "str"}},
3737
},
38+
"options": {"type": "map", "allowempty": True},
3839
},
3940
}
4041
],

src/popper/runner_host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _get_container_kwargs(self, step, img, name):
257257
}
258258

259259
self._update_with_engine_config(args)
260-
260+
args.update(step.options)
261261
log.debug(f"container args: {pu.prettystr(args)}\n")
262262

263263
return args

src/test/test_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def test_new_workflow(self):
3737
"env": {"EN": "EE"},
3838
"secrets": ["S"],
3939
"dir": "/path/to/",
40+
"options": {"name": "spam"},
4041
},
4142
{"uses": "bar", "runs": ["a", "b"], "args": ["c"], "skip_pull": True},
4243
],
43-
"options": {"env": {"FOO": "bar"}, "secrets": ["Z"]},
44+
"options": {"env": {"FOO": "bar"}, "secrets": ["Z"],},
4445
}
4546
wf = WorkflowParser.parse(wf_data=wf_data)
4647

@@ -50,6 +51,7 @@ def test_new_workflow(self):
5051
self.assertEqual(("Z", "S"), step.secrets)
5152
self.assertEqual({"EN": "EE", "FOO": "bar"}, step.env)
5253
self.assertEqual("/path/to/", step.dir)
54+
self.assertEqual("spam", step.options.name)
5355
self.assertTrue(not step.runs)
5456
self.assertTrue(not step.args)
5557
self.assertFalse(step.skip_pull)

src/test/test_runner_host.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_get_container_kwargs(self):
159159
"args": ["ls"],
160160
"id": "one",
161161
"dir": "/tmp/",
162+
"options": {"ports": {"8888/tcp": 8888}},
162163
},
163164
default_box=True,
164165
)
@@ -203,6 +204,7 @@ def test_get_container_kwargs(self):
203204
"privileged": True,
204205
"hostname": "popper.local",
205206
"domainname": "www.example.org",
207+
"ports": {"8888/tcp": 8888},
206208
},
207209
)
208210

@@ -234,6 +236,7 @@ def test_get_container_kwargs(self):
234236
"privileged": True,
235237
"hostname": "popper.local",
236238
"domainname": "www.example.org",
239+
"ports": {"8888/tcp": 8888},
237240
},
238241
)
239242

0 commit comments

Comments
 (0)