containers / containers/podman-py

No such file or directory error when building image

Open
#177 2 comments 1 reaction 0 assignees View on GitHub
help wanted
Dominant language
Python
Stars
381
Forks
140
Avg merge
5h 30m
Merged PRs (30d)
1

Description

Have met a problem during building an image through podman-py:

```
File "/usr/local/lib/python3.8/site-packages/podman/domain/images_build.py", line 89, in build
params["dockerfile"] = api.prepare_containerfile(kwargs["path"], params["dockerfile"])

File "/usr/local/lib/python3.8/site-packages/podman/api/tar_utils.py", line 50, in prepare_containerfile
shutil.copy2(dockerfile_path, proxy_path, follow_symlinks=False)

File "/usr/lib64/python3.8/shutil.py", line 435, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)

File "/usr/lib64/python3.8/shutil.py", line 264, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:

FileNotFoundError: [Errno 2] No such file or directory: '.containerfile.7482d90f40a649bde91353e5326d5a698053219c'
```

It appears if path parameter for images.build is set, but dockerfile isn't.

Looked a bit into podman-py code and found probable cause of this issue in podman-py/podman/api/tar_utils/prepare_containerfile:
```
proxy_path = anchor_path / f".containerfile.{random.getrandbits(160):x}"
shutil.copy2(dockerfile_path, proxy_path, follow_symlinks=False)
return proxy_path.name
```

It seems, that between creating path and copying - there should be creation of temporary file.

Contributor guide

Open the contributing guide

Research direction

Start in podman/api/tar_utils.py at prepare_containerfile, then inspect the images.build path in podman/domain/images_build.py. Reproduce an image build with path set and dockerfile omitted, and verify it no longer raises FileNotFoundError when preparing the Containerfile.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.