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

Docker image build fails when the flag '--no-binary pydantic' is added to requirements.txt #15

Open
arashmalekz opened this issue Nov 1, 2021 · 3 comments · May be fixed by #17
Open
Assignees

Comments

@arashmalekz
Copy link

arashmalekz commented Nov 1, 2021

The flag '--no-binary pydantic' is added to requirements.txt on a new line so it doesn't generate pydantic binaries and make the Lambda deployment package smaller. However, if I have this flag and try to build the Pygeoapi Docker image, I get the following error:

Obtaining file:///pygeoapi
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/pygeoapi/setup.py'"'"'; __file__='"'"'/pygeoapi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
         cwd: /pygeoapi/
    Complete output (1 lines):
    error in pygeoapi setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'--no-bin'"
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
@anthonyfok anthonyfok added this to the Sprint 45 milestone Nov 3, 2021
anthonyfok added a commit to anthonyfok/pygeoapi that referenced this issue Nov 4, 2021
This is to reduce the size of the resulting Docker image,
apparently from 974MB down to 866MB

Fixes OpenDRR#15
@anthonyfok anthonyfok linked a pull request Nov 4, 2021 that will close this issue
@anthonyfok
Copy link
Member

anthonyfok commented Nov 4, 2021

Hey @arashmalekz, thank you for your very helpful report!
I was able to reproduce the error that you were seeing, and it turns out pip3 install -e . which runs setup.py is the "culprit". So, after removing the --no-binary pydantic from requirements.txt, I borrowed a trick inside Dockerfile (where upstream pre-installed elasticsearch-dsl with pip3 for some reason):

--- a/Dockerfile
+++ b/Dockerfile
@@ -92,6 +92,8 @@ RUN \
     && if [ "$BUILD_DEV_IMAGE" = "true" ] ; then pip3 install -r requirements-dev.txt; fi \
     # Temporary fix for elasticsearch-dsl module not available as deb package in bionic
     && pip3 install elasticsearch-dsl \
+    # Reduce size of Docker image by not installing pydantic binary package
+    && pip3 install --no-binary pydantic pydantic \
     && pip3 install -e . \
     # OGC schemas local setup
     && mkdir /schemas.opengis.net \

pip3 install -e . would then see that pydantic is already installed (in whatever form) and would leave it alone, thus skipping the binary wheel file download. See also PR #17 if we want this in the master branch too.

Hope this will make the Docker image small enough (969MB → 861MB before compression) for AWS Lambda. Please test and let me know! If it is still too large, I think there could be some more tricks to reduce the size of the Docker image further.

anthonyfok added a commit to anthonyfok/pygeoapi that referenced this issue Nov 4, 2021
This is to reduce the size of the resulting Docker image,
apparently from 969MB down to 861MB

Fixes OpenDRR#15
@arashmalekz
Copy link
Author

Hey @anthonyfok , sorry, I finally had a chance to look at this!
I'm using the Docker image to generate pygeoapi and openapi config. The package I build for Lambda is not actually Docker image. I'm using the serverless framwork (aws-lambda folder in this repo). It reads requirements.txt file and installs packages locally and then creates a Lambda zip file.
I think what I can do is to create a requirements.txt file specific for serverless builds and get it to use that. This way we could leave Dockerfile as is. Let me see if I can do it that way and I'll let you know.

@anthonyfok anthonyfok modified the milestones: Sprint 45, Sprint 50 Jan 17, 2022
@anthonyfok anthonyfok modified the milestones: Sprint 50, Sprint 52 Jan 26, 2022
@anthonyfok
Copy link
Member

Hey @arashmalekz, thank you so much for looking into this! (And sorry for my late reply.)

Joost reminded me that we don't deploy pygeoapi on AWS Lambda any longer.
Instead a full pygeoapi container is now used to allow larger records (e.g. more than 10 items) to be sent to clients (something like that, if I recall correctly?).

If so, I was wondering if we could close this issue? Please let me know! Many thanks!

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

Successfully merging a pull request may close this issue.

2 participants