iron-io / functions

IronFunctions - the serverless microservices platform by
https://iron.io
Apache License 2.0
3.18k stars 227 forks source link

gcc is missing from the python-dev container #654

Closed wrsuarez closed 6 years ago

wrsuarez commented 6 years ago

Trying to write a function which needs to SSH into another system to get some data and leveraging the paramiko library to do so. When including paramiko in the requirements file the python-dev container complains about gcc when trying to compile the required libraries for paramiko:

MYLAPTOP:projectdir me$ fn build Running prebuild command: docker run --rm -v /Users/me/project:/worker -w /worker iron/python:2-dev pip install -t packages -r requirements.txt Collecting PyNaCl (from -r requirements.txt (line 1)) Downloading PyNaCl-1.1.2.tar.gz (3.1MB) Complete output from command python setup.py egg_info: unable to execute 'gcc': No such file or directory unable to execute 'gcc': No such file or directory

    No working compiler found, or bogus compiler options passed to
    the compiler from Python's standard "distutils" module.  See
    the error messages above.  Likely, the problem is not related
    to CFFI but generic to the setup.py of any Python package that
    tries to compile C code.  (Hints: on OS/X 10.8, for errors about
    -mno-fused-madd see http://stackoverflow.com/questions/22313407/
    Otherwise, see https://wiki.python.org/moin/CompLangPython or
    the IRC channel #python on irc.freenode.net.)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-8DHlH1/PyNaCl/setup.py", line 232, in <module>
    "Programming Language :: Python :: 3.6",
  File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 269, in __init__
    self.fetch_build_eggs(attrs['setup_requires'])
  File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 313, in fetch_build_eggs
    replace_conflicting=True,
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 825, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1070, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1082, in obtain
    return installer(requirement)
  File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 380, in fetch_build_egg
    return cmd.easy_install(req)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 640, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 670, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 853, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1081, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1069, in run_setup
    raise DistutilsError("Setup script exited with %s" % (v.args[0],))
distutils.errors.DistutilsError: Setup script exited with 1

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-8DHlH1/PyNaCl You are using pip version 8.0.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. error running docker build: exit status 1

c0ze commented 6 years ago

hello @wrsuarez !

Thank you for the report ! Iron base containers are configured to be minimal, to make them take as little space as possible.

However, you don't have to keep to using Iron provided base containers. By default, fn tool tries to be smart, and provide you with a default container & Dockerfile based on your application. However, you can also use any configuration you like if you provide a custom Dockerfile.

In this case, the base Dockerfile fn tool presumes is :

python:2-dev

Adding some necessary dependencies for paramiko, a Dockerfile like below should solve your problem :

FROM iron/python:2

RUN apk update && apk upgrade

RUN apk add --no-cache curl python pkgconfig python-dev openssl-dev libffi-dev musl-dev make gcc

RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python

WORKDIR /app
ADD . /app
RUN pip install -U setuptools
RUN python -m pip install --upgrade pip
RUN pip install -t packages -r requirements.txt

ENTRYPOINT ["python", "func.py"]

Or, checking dockerhub for paramiko, you can use another base container which includes all these deps and end up with a cleaner Dockerfile:

FROM eduardoshanahan/paramiko

WORKDIR /app
ADD . /app

RUN pip install -t packages -r requirements.txt

ENTRYPOINT ["python", "func.py"]

In this case, the base container doesn't seem to contain pip, so this doesn't work. But the point is there might be other containers out there serving your needs built by other people, so you can base your app on these containers as well. You are not confined to Iron provided containers.

I hope this solves your issue, let us know how it works !

c0ze commented 6 years ago

closing this for now, please feel free to open if something is not clear. 👍