openfaas / templates

OpenFaaS Classic templates
https://www.openfaas.com
MIT License
276 stars 228 forks source link

Unable to install cryptograpy package in python, since it requires rust #260

Closed CC007 closed 3 years ago

CC007 commented 3 years ago

The python package cryptography requires rust nowadays. The Alpine image that is used by faas-cli doesn't contain rust. This causes the building of the docker image to fail.

More info: https://github.com/pyca/cryptography/issues/5771

Note that an older version of the cryptography package also doesn't work, due to the dependency on libssl-dev.

It would be nice if both of these were available, at the very least if the dev build-option is enabled.

Expected Behaviour

The docker image builds successfully

Current Behaviour

I'm getting the error:

running build_rust

      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation.html#rust
      5) If you are experiencing issues with Rust for *this release only* you may
         set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
      =============================DEBUG ASSISTANCE=============================

  error: can't find Rust compiler

  If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.

  To update pip, run:

      pip install --upgrade pip

  and then retry package installation.

  If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.

  This package requires Rust >=1.41.0.
  ----------------------------------------
  ERROR: Failed building wheel for cryptography

Are you a GitHub Sponsor (Yes/No?)

List All Possible Solutions and Workarounds

The github issue suggests either this:

sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo

Or this:

pip install --upgrade pip

Steps to Reproduce (for bugs)

  1. Make a python3 function
  2. Add the cryptography package to the requirements.txt (I used version 3.4.7)
  3. build the function with faas-cli

Context

This issue prevents me from building my function, so I can't deploy it.

Your Environment

alexellis commented 3 years ago

Hi, you can add these packages in at build time or by editing your template.

Please see the docs to learn how with build config / args.

You are also probably better off using python3-debian since it comes with a build toolchain already and is better suited for native C packages, so it may also be better for your Rust toolchain.

Thanks for using OpenFaaS and do consider becoming a GitHub Sponsor so we can continue to give community support like this.

I'll close this for now, since I've pointed you at the solution. If we get noticeable demand for this, we may look into other options.

https://docs.openfaas.com/cli/templates/#python-3-templates https://docs.openfaas.com/cli/build/#10-apply-build-options

Alex