Skip to content

Commit

Permalink
🐛 fix FileNotFoundError in running_in_docker (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkut committed Dec 1, 2022
1 parent ea55be9 commit ad71767
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Zappa Changelog

## 0.56.1

* FileNotFoundError in running_in_docker (#1201)

## 0.56.0
* Not recognizing virtaulenv created with pyenv (#1132)
* Remove six from zappa dependencies (#1164)
Expand Down
13 changes: 13 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,19 @@ def test_no_runtimeerror_when_in_docker(self, *_):
except RuntimeError:
self.fail()

@mock.patch("pathlib.Path.exists", return_value=False)
@mock.patch("pathlib.Path.read_text", side_effect=FileNotFoundError("not found"))
@mock.patch("sys.version_info", new_callable=partial(get_sys_versioninfo, 7))
def test_running_in_docker_filenotfound(self, *_):
from importlib import reload

try:
import zappa

reload(zappa)
except FileNotFoundError:
self.fail()

def test_wsgi_query_string_unquoted(self):
event = {
"body": {},
Expand Down
9 changes: 6 additions & 3 deletions zappa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ def running_in_docker() -> bool:
- When docker is used allow usage of any python version
"""
# https://stackoverflow.com/a/20012536/24718
cgroup_content = Path("/proc/1/cgroup").read_text()
in_docker = "/docker/" in cgroup_content or "/lxc/" in cgroup_content
in_docker = False
cgroup_filepath = Path("/proc/1/cgroup")
if cgroup_filepath.exists():
cgroup_content = cgroup_filepath.read_text(encoding="utf8")
in_docker = "/docker/" in cgroup_content or "/lxc/" in cgroup_content
return in_docker


Expand All @@ -33,4 +36,4 @@ def running_in_docker() -> bool:
raise RuntimeError(err_msg)


__version__ = "0.56.0"
__version__ = "0.56.1"

0 comments on commit ad71767

Please sign in to comment.