Skip to content

Commit cdd9407

Browse files
authored
docs(readme): fix docker run example to use project name (#39)
1 parent a08b26e commit cdd9407

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

cookiecutter.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"project_name": "TODO",
2+
"project_name": "replace-me",
33
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
4-
"project_short_description": "TODO",
4+
"project_short_description": "A brief description of the project",
55
"company_name": "Zenable Inc",
66
"company_domain": "zenable.io",
77
"github_org": "zenable-io",

tests/test_cookiecutter.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
def get_config() -> dict:
2525
"""Generate all the config keys"""
2626
config_file = Path("./cookiecutter.json")
27-
with open(config_file) as file_object:
28-
config = json.load(file_object)
27+
with config_file.open(encoding="utf-8") as f:
28+
config = json.load(f)
2929
return config
3030

3131

@@ -227,6 +227,19 @@ def test_default_project(cookies):
227227
if repo.is_dirty(untracked_files=True):
228228
pytest.fail("Something went wrong with the project's post-generation hook")
229229

230+
# Extract project_name and project_slug from cookiecutter.json
231+
config_file = Path("./cookiecutter.json")
232+
with config_file.open(encoding="utf-8") as f:
233+
generated_config = json.load(f)
234+
github_org = generated_config.get("github_org")
235+
project_name = generated_config.get("project_name")
236+
project_name_lower = project_name.lower()
237+
238+
# Keep this logic aligned with the template's README.md
239+
# It's important that this has -s in the name to test the docker hub image name sanitization
240+
default_image_name = f"{github_org}/{project_name_lower}"
241+
default_image_name_and_tag = f"{default_image_name}:latest"
242+
230243
try:
231244
env = os.environ.copy()
232245
env.pop("VIRTUAL_ENV", None) # Clean VIRTUAL_ENV to avoid conflicts
@@ -273,11 +286,9 @@ def test_default_project(cookies):
273286
env=env,
274287
)
275288

276-
default_image = "zenable-io/todo:latest"
277-
278289
# Ensure that --help exits 0
279290
subprocess.run(
280-
["docker", "run", "--rm", default_image, "--help"],
291+
["docker", "run", "--rm", default_image_name_and_tag, "--help"],
281292
capture_output=True,
282293
check=True,
283294
cwd=project,
@@ -288,7 +299,7 @@ def test_default_project(cookies):
288299
"docker",
289300
"run",
290301
"--rm",
291-
default_image,
302+
default_image_name_and_tag,
292303
"--debug",
293304
"--verbose",
294305
]

{{cookiecutter.project_name|replace(" ", "")}}/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ task init
1818
task build
1919

2020
# Run the image
21-
docker run {{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}:0.0.0 --help
21+
docker run {{ cookiecutter.github_org }}/{{ cookiecutter.project_name | lower }}:0.0.0 --help
2222
```
2323

2424
If you'd like to build all of the supported docker images, you can set the `PLATFORM` env var to `all` like this:

{{cookiecutter.project_name|replace(" ", "")}}/tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_docker_image():
102102
Test that the Docker image builds and runs correctly.
103103
"""
104104
project_root = Path(__file__).parent.parent
105-
image_name = "{{ cookiecutter.github_org }}/{{ cookiecutter.project_slug }}"
105+
image_name = "{{ cookiecutter.github_org }}/{{ cookiecutter.project_name | lower }}"
106106

107107
pyproject_file = project_root / "pyproject.toml"
108108

0 commit comments

Comments
 (0)