Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't pyenv finding openssl shared libraries under Alpine Linux?

I'm trying to build a docker image from gliderlabs/alpine:latest containing only pyenv and it's dependencies. I would like for this container to be able to install and execute an arbitrary interpreter through pyenv.

Initial Attempt

I began with the following Dockerfile:

FROM gliderlabs/alpine:latest

RUN apk-install curl \
  ca-certificates \
  bash \
  git \
  openssl-dev \
  readline-dev \
  bzip2-dev \
  sqlite-dev \
  build-base

RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer -o /pyenv-installer
RUN touch /root/.bashrc && \
      /bin/ln -s /root/.bashrc /root/.bash_profile && \
      /bin/bash /pyenv-installer && \
      rm /pyenv-installer && \
      echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile && \
      echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile && \
      echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

ENV HOME  /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

The Error

Once built, I can start a container and run bash, and the pyenv command is available, as expected.

However, when I try to run pyenv install 3.4.3 I get the following error:

bash-4.3# pyenv install 3.4.3
Downloading Python-3.4.3.tgz...
-> https://yyuu.github.io/pythons/4281ff86778db65892c05151d5de738d
Installing Python-3.4.3...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/yyuu/pyenv/wiki/Common-build-problems


BUILD FAILED (Alpine Linux 3.2.3 using python-build 20151006)

Inspect or clean up the working tree at /tmp/python-build.20151006155321.99
Results logged to /tmp/python-build.20151006155321.99.log

Last 10 log lines:
(cd /root/.pyenv/versions/3.4.3/share/man/man1; ln -s python3.4.1 python3.1)
if test "xupgrade" != "xno"  ; then \
    case upgrade in \
        upgrade) ensurepip="--upgrade" ;; \
        install|*) ensurepip="" ;; \
    esac; \
     ./python -E -m ensurepip \
        $ensurepip --root=/ ; \
fi
Ignoring ensurepip failure: pip 6.0.8 requires SSL/TLS

Attempted Fix

After a bit of googling I found this page, which, for OSX/homebrew, suggests the following fix:

CFLAGS="-I$(brew --prefix openssl)/include"
LDFLAGS="-L$(brew --prefix openssl)/lib"

Since I'm not using OSX or Homebrew, I attempted to adapt these commands to an Alpine environment by adding the following lines to the Dockerfile:

ENV CFLAGS '-I/usr/include'
ENV LDFLAGS '-L/usr/lib'

Please note that /usr/lib contains:

  • libssl.a
  • libssl.so
  • libssl.so.1.0.0

and /usr/include contains openssl. This having been said, the modification seems to have no impact on my error when installing Python 3.4.3.

The Question

How can I get pyenv to install a python environment under a dockerized Alpine Linux?

Edit:

  1. The pyenv build log is apparently chocking because the sockaddr_can type is undefined. I'm officially lost. Is this a musl bug ?
like image 317
Louis Thibault Avatar asked Jan 07 '23 10:01

Louis Thibault


1 Answers

The problem had to do with musl not finding generic linux headers. The solution is to install linux-headers.

Below is a minimal working Dockerfile:

FROM gliderlabs/alpine:latest

RUN apk-install curl \
      ca-certificates \
      bash \
      git \
      openssl-dev \
      readline-dev \
      bzip2-dev \
      sqlite-dev \
      ncurses-dev \
      linux-headers \
      build-base

RUN curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer -o /pyenv-installer && \
      touch /root/.bashrc && \
      /bin/ln -s /root/.bashrc /root/.bash_profile && \
      /bin/bash /pyenv-installer && \
      rm /pyenv-installer && \
      echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile && \
      echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile && \
      echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

ENV HOME  /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
like image 56
Louis Thibault Avatar answered Jan 16 '23 20:01

Louis Thibault