Skip to content

Commit 514e72c

Browse files
authored
Merge pull request #179 from shanejbrown/examples
Add Examples
2 parents 0f891ac + 0dcc360 commit 514e72c

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
vendor*
2-
build
2+
build/*
33
dist
44
*.egg-info
55
*.egg
@@ -13,6 +13,7 @@ dist
1313

1414
.eggs
1515
venv*
16+
.venv
1617
.act*
1718

1819
buildrunner/version.py

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,11 @@ Common Issues
11281128

11291129
See `docs/common-issues <docs/common-issues.rst>`_.
11301130

1131+
Example Configurations
1132+
======================
1133+
1134+
See `examples <examples/README.rst>`_.
1135+
11311136
Contributing
11321137
============
11331138

examples/README.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
==================================
2+
Buildrunner Example Configurations
3+
==================================
4+
5+
This directory contains example configuration files for Buildrunner, demonstrating various use cases and best practices. These examples serve as references for users looking to configure and execute Buildrunner effectively.
6+
7+
Running Buildrunner with Example Configuration Files
8+
====================================================
9+
10+
To run Buildrunner using an example configuration file, follow these steps from the root directory of the Buildrunner repository:
11+
12+
1. **Navigate to the Buildrunner repository directory.**
13+
14+
2. **Execute Buildrunner with a specified configuration file:**
15+
.. code-block:: sh
16+
17+
PYTHONPATH=. ./bin/buildrunner -f examples/<path-to-config-file>
18+
19+
*Example:*
20+
21+
.. code-block:: sh
22+
23+
PYTHONPATH=. ./bin/buildrunner -f examples/build/basic/buildrunner.yaml
24+
25+
Adding a New Example Configuration File
26+
=======================================
27+
28+
To contribute a new example configuration file, adhere to the following guidelines:
29+
30+
1. **File Location & Naming**
31+
- Place the new file in the ``examples/`` directory.
32+
- Ensure the filename ends with ``.buildrunner.yaml`` to allow automatic detection and execution by unit tests.
33+
34+
2. **Configuration Validity**
35+
- The configuration file must contain a valid Buildrunner configuration.
36+
- It should execute successfully using the standard instructions provided in this repository without requiring any manual intervention.
37+
38+
3. **Documentation & Additional Files**
39+
- If necessary, include a ``README.rst`` file in the same directory as the configuration file to provide additional details or instructions.
40+
- Any supporting files required for the configuration should be placed alongside the configuration file.
41+
42+
Following these best practices ensures consistency, maintainability, and ease of use for all contributors and users.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Basic buildrunner configuration to build a simple Docker image.
2+
steps:
3+
simple-build-step:
4+
build:
5+
dockerfile: |
6+
FROM busybox:latest
7+
RUN echo Hello World
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Basic buildrunner configuration to run a simple Docker image.
2+
steps:
3+
simple-run-step:
4+
run:
5+
image: busybox:latest
6+
cmd: echo Hello World

tests/test_buildrunner_files.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ def _get_test_runs(
117117
]
118118

119119

120+
def _get_example_runs(test_dir: str) -> List[Tuple[str, str, Optional[List[str]], int]]:
121+
file_names = []
122+
# Walk through the examples directory and find all files ending with buildrunner.yaml
123+
for root, _, files in os.walk(test_dir):
124+
for file in files:
125+
file_name = os.path.join(root, file)
126+
if file_name.endswith("buildrunner.yaml"):
127+
file_names.append(file_name)
128+
129+
return [
130+
(test_dir, file_name, _get_test_args(file_name), _get_exit_code(file_name))
131+
for file_name in file_names
132+
]
133+
134+
120135
def _test_buildrunner_file(test_dir, file_name, args, exit_code):
121136
print(f"\n>>>> Testing Buildrunner file: {file_name}")
122137
with tempfile.TemporaryDirectory(prefix="buildrunner.results-") as temp_dir:
@@ -194,3 +209,11 @@ def test_buildrunner_arm_dir(test_dir: str, file_name, args, exit_code):
194209
def test_buildrunner_scan_dir(test_dir: str, file_name, args, exit_code):
195210
# The scan tests can be flaky, with errors like "TOOMANYREQUESTS: retry-after: 804.543µs, allowed: 44000/minute"
196211
_test_buildrunner_file(test_dir, file_name, args, exit_code)
212+
213+
214+
@pytest.mark.parametrize(
215+
"test_dir, file_name, args, exit_code",
216+
_get_example_runs(test_dir=f"{TEST_DIR}/../examples"),
217+
)
218+
def test_example_configs(test_dir: str, file_name, args, exit_code):
219+
_test_buildrunner_file(test_dir, file_name, args, exit_code)

0 commit comments

Comments
 (0)