Fix Dockerfile parsing on Windows

Line endings are written as "\r" by default on Windows, which makes the
Dockerfiles unreadable by Docker.

See: https://github.com/overhangio/tutor/pull/385#issuecomment-730387969
This commit is contained in:
Régis Behmo 2020-11-20 16:05:56 +01:00
parent 7b16af22b8
commit 727c204e92
3 changed files with 10 additions and 6 deletions

View File

@ -4,6 +4,8 @@ Note: Breaking changes between versions are indicated by "💥".
## Unreleased
- [Bugfix] Fix Dockerfile parsing on Windows
## v10.5.0 (2020-11-19)
- 💥[Improvement] Remove `dev/local pullimages`. Instead, run `dev/local dc pull`.

View File

@ -117,7 +117,7 @@ def install(location):
# Save file
if not os.path.exists(plugins.DictPlugin.ROOT):
os.makedirs(plugins.DictPlugin.ROOT)
with open(plugin_path, "w") as f:
with open(plugin_path, "w", newline="\n") as f:
f.write(content)
fmt.echo_info("Plugin installed at {}".format(plugin_path))

View File

@ -227,13 +227,15 @@ def write_to(content, path):
"""
Write some content to a path. Content can be either str or bytes.
"""
open_mode = "w"
encoding = "utf8"
open_kwargs = {"mode": "w"}
if isinstance(content, bytes):
open_mode += "b"
encoding = None
open_kwargs["mode"] += "b"
else:
# Make files readable by Docker on Windows
open_kwargs["encoding"] = "utf8"
open_kwargs["newline"] = "\n"
utils.ensure_file_directory_exists(path)
with open(path, open_mode, encoding=encoding) as of:
with open(path, **open_kwargs) as of:
of.write(content)