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

Fixed docker support for the Python target #2377

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Fixed docker support for the Python target #2377

merged 3 commits into from
Jul 24, 2024

Conversation

cmnrd
Copy link
Collaborator

@cmnrd cmnrd commented Jul 22, 2024

This PR implements several fixes:

  • proper quoting of cmake arguments so that they work in the build image
  • enabling Python docker tests
  • ensuring that the docker generation runs after the Python code generation
  • moving failing federated docker tests to a failing directory

Details

I noticed that the docker generation for Python is broken, producing errors like the following:

/lingua-franca/PingPongContainerized/src-gen/lib/pythontarget.c: In function ‘py_source_directory’:
#10 3.738 <command-line>: error: expected expression before ‘/’ token
#10 3.738 /lingua-franca/PingPongContainerized/src-gen/lib/pythontarget.c:171:36: note: in expansion of macro ‘LF_SOURCE_DIRECTORY’
#10 3.738   171 |   return PyUnicode_DecodeFSDefault(LF_SOURCE_DIRECTORY);
#10 3.738       |                                    ^~~~~~~~~~~~~~~~~~~
#10 3.738 /lingua-franca/PingPongContainerized/src-gen/lib/pythontarget.c: In function ‘py_package_directory’:
#10 3.738 <command-line>: error: expected expression before ‘/’ token
#10 3.738 /lingua-franca/PingPongContainerized/src-gen/lib/pythontarget.c:181:36: note: in expansion of macro ‘LF_PACKAGE_DIRECTORY’
#10 3.738   181 |   return PyUnicode_DecodeFSDefault(LF_PACKAGE_DIRECTORY);
#10 3.738       |                                    ^~~~~~~~~~~~~~~~~~~~
#10 3.743 make[2]: *** [CMakeFiles/LinguaFrancaPingPongContainerized.dir/build.make:146: CMakeFiles/LinguaFrancaPingPongContainerized.dir/lib/pythontarget.c.o] Error 1
#10 3.743 make[1]: *** [CMakeFiles/Makefile2:106: CMakeFiles/LinguaFrancaPingPongContainerized.dir/all] Error 2

This is related to the way we quote arguments that we pass to cmake. For some reason, the quoting behaves different when building for Python than when building for C. I assume this is because a different shell is used in the different base images. The implemented fix makes the generated quoting more robust.

While debugging this, I also noticed that the Python docker tests were disabled. So we did not notice the problems before... It looks like this was done because of another issue: #1564. However, the issue is not very descriptive, and I don't understand what it is about. @lhstrh Perhaps you can comment on whether we can consider the issue fixed?

After enabling the tests again, I noticed a fundamental flaw in the Python docker generation. It was completely relying on the C generator, which gets invoked by the Python generator before the Python code is generated. Thus, the docker image was incomplete, as it was created before any Python files were generated.

Finally, I had to mark two of the federated tests as failing. I don't know why they are failing and will open another issue.

@cmnrd cmnrd added python Related to the Python target docker Issue related to the docker support bugfix labels Jul 22, 2024
@cmnrd cmnrd requested review from edwardalee and lhstrh July 22, 2024 18:43
@elgeeko1
Copy link
Collaborator

python:3.10-slim derives from Debian bookworm and the C image derives from Alpine. Debian will use bash as its shell, alpine will use POSIX Dash. However I'm surprised this would make a difference on something like quoting where the two shells should be interchangeable.

I think it would be a good idea to have the Python docker images use the same parent image as our C image, so that they have the same shell and package manager. python:3.10-alpine is an official image for Python 3.10 that is based on Alpine, so this would accomplish this.

@cmnrd
Copy link
Collaborator Author

cmnrd commented Jul 23, 2024

python:3.10-slim derives from Debian bookworm and the C image derives from Alpine. Debian will use bash as its shell, alpine will use POSIX Dash. However I'm surprised this would make a difference on something like quoting where the two shells should be interchangeable.

I was surprised by this too. So basically the C and the Python dockerfile have similar content. In parrticular, the cmake arguments that define path C macros look like this in both docker files: -DLF_SOURCE_DIRECTORY="/some/path". However, when building the image, docker seems to convert this and add quoting. So when building for C, it actually passes '-DLF_SOURCE_DIRECTORY=/some/path' to cmake. In Python, it passes -DLF_SOURCE_DIRECTORY="/some/path". For some reason, the latter defines LF_SOURCE_DIRECTORY to /some/path, which lacks the quotes and is thus not a string in C.

I don't know what is causing the difference between C and Python.

I think it would be a good idea to have the Python docker images use the same parent image as our C image, so that they have the same shell and package manager. python:3.10-alpine is an official image for Python 3.10 that is based on Alpine, so this would accomplish this.

I agree, but I think we should treat using an alpine base image as a separate issue.

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

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

No idea why the federated tests are failing but please create an issue for them if you haven't already.

@lhstrh
Copy link
Member

lhstrh commented Jul 24, 2024

Actually, let's repurpose #1564 to track the failing tests, because it's neither clear that this PR fixes #1564 nor whether the "new" failures are related to the ones observed when I created #1564.

@cmnrd cmnrd added this pull request to the merge queue Jul 24, 2024
Merged via the queue into master with commit d587b50 Jul 24, 2024
26 checks passed
@cmnrd cmnrd deleted the fix-python-docker branch July 24, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix docker Issue related to the docker support python Related to the Python target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants