Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add newline conversion for postBuild scripts #301

Closed
wants to merge 4 commits into from

Conversation

betatim
Copy link
Member

@betatim betatim commented Apr 25, 2018

Fixes #263

Python normalises line endings to always be "platform appropriate". So by reading in a file that potentially uses \r\n (because it was checked out from git on Windows) and writing it out again on a linux platform (inside a docker container) we make sure files only use \n.

@betatim
Copy link
Member Author

betatim commented Apr 25, 2018

What do people in general think about this?

If it has support I would add some tests with explicit \r\n in them to make sure this works.

@choldgraf
Copy link
Member

I'm +1, I think it's a fair concern that it slightly change the thing that is run on the repo2docker side vs. whatever is on the computer. However, since this is limited to line endings I think it's OK. Otherwise any user that makes things on windows will have to 1. learn about the concept of line endings, and 2. remember to change this, every time the wanna use postBuild.

tl;dr, I can't really think of a situation where we'd think "damn, I wish we had not forced *nix line endings", so I'm +1

@@ -110,6 +110,8 @@
{% if post_build_scripts -%}
{% for s in post_build_scripts -%}
RUN chmod +x {{ s }}
# Fix up line endings for users who checked out postBuild scripts on Windows
RUN python -c "open('{{ s }}', 'w').write(open('{{ s }}').read())"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technically eliminates the possibility of binary postBuild, but I'm not sure that's an issue.

Should this also be specifically python3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good way to tell if it is a binary? It seems rare but we could try to detect it and refuse to do anything if we think it is a binary. I'll experiment a bit with file postbuild to see how many different things it outputs.

👍 on python3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a test checking if file postBuild thinks this is a binary but I'd vote to do that once we have someone who actually uses binaries for postBuild.

@betatim
Copy link
Member Author

betatim commented Apr 26, 2018

Does anyone have an idea why suddenly the memlimit tests fail? Doesn't seem like something that would be flaky but also not really related to changes here I'd say.

@betatim
Copy link
Member Author

betatim commented Apr 27, 2018

Can we add something that asserts that the original postBuild in the test contains CRLFs? So that we find out if that ever stops being the case which would make the test useless.

@@ -0,0 +1,4 @@
#!/bin/bash

# I contain CRLF line endings on purpose
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had hoped to see some extra characters/symbol here on GH to verify that this file contains CRLF. Could someone on a not-windows system checkout this branch to confirm my .gitattribute worked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened it on my windows machine and it said that it was in CRLF mode, which is what we want. Just FYI, you should be able to open this with Atom or something like this, and it should tell you the line endings present in the file (and if not by default, then there are plugins for this kinda thing for most text editors)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally I see the extra characters but because git can/will mangle the line endings when you checkin/-out I wanted to see if someone somewhere else can also see them after it has gone through git :)

@choldgraf
Copy link
Member

choldgraf commented Apr 27, 2018

in terms of an assertion, I think all we'd need to is use newline like so:

with open('./postBuild.txt', 'r', newline='') as ff:
    lines = ff.read()

and lines should now reflect whatever the file contains (e.g. \r\n or \n)

@betatim
Copy link
Member Author

betatim commented Apr 27, 2018

Where/how would we get that snippet executed as part of the test? verify is run inside the container where we will see the converted version :-/

@betatim betatim force-pushed the sanitise-newline branch from 2f396ee to 64f4063 Compare June 6, 2018 18:51
@betatim
Copy link
Member Author

betatim commented Jun 6, 2018

Does someone have an idea why the test_memlimit_nondockerfile_fail test fails?

@yuvipanda
Copy link
Collaborator

What shall we do with this one, @betatim? Do you think there have been enough complaints about this in the last two years for us to push this through?

@consideRatio
Copy link
Member

I'm triaging some PRs - @betatim do you have a recommendation on what to do with this?

@betatim
Copy link
Member Author

betatim commented Nov 1, 2022

I think it would be useful and doesn't add too much complexity/magic. However it seems like there isn't a lot of interest/need. If someone is interested to pick up this stalled PR that would be great.

@consideRatio
Copy link
Member

I'll go for a close at this point since we are not actively working this PR and since it would introduce a possible issue for binary postBuild executables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always convert line endings in postBuild to unix
6 participants