Skip to content

Instantly share code, notes, and snippets.

@rodjul
Created March 24, 2023 13:41
Show Gist options
  • Select an option

  • Save rodjul/9f96f8161d4555823da078dc960e071e to your computer and use it in GitHub Desktop.

Select an option

Save rodjul/9f96f8161d4555823da078dc960e071e to your computer and use it in GitHub Desktop.
AWS Lambda python3.9 (Amazon Linux 2) - OpenSSL 1.1.1, pyOpenSSL with cryptography
#!/bin/bash
tag_image=openssl_wheel
mkdir wheels || true
docker build -t $tag_image . && docker run --rm -it -v "$(pwd)/wheels:/mnt/tmp/" $tag_image "cp /root/*.whl /mnt/tmp/"
cd wheels; ls -l
FROM ubuntu:17.10
WORKDIR /root
# RUN /usr/bin/apt update
RUN sed -i 's/archive/old-releases/g' /etc/apt/sources.list && \
/usr/bin/apt update; \
apt install -y software-properties-common make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev \
wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev \
python-openssl git \
python3-dev pkg-config
RUN cd /root && \
curl -k -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash && \
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc && \
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc && \
echo 'eval "$(pyenv init -)"' >> ~/.bashrc && \
/root/.pyenv/bin/pyenv install 3.9.0
RUN /root/.pyenv/bin/pyenv global 3.9.0
RUN /root/.pyenv/shims/python -m pip install virtualenv && \
/root/.pyenv/shims/python -m virtualenv env && \
/root/env/bin/python -m pip install -U setuptools && \
/root/env/bin/python -m pip install -U wheel pip
ARG OPENSSL_VERSION="1.1.1f"
# https://cryptography.io/en/latest/installation/#supported-platforms
RUN curl -O https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz -k
RUN tar xvf openssl-$OPENSSL_VERSION.tar.gz
RUN cd openssl-$OPENSSL_VERSION && ./config no-shared no-ssl2 no-ssl3 -fPIC --prefix=/root/openssl
RUN cd openssl-$OPENSSL_VERSION && make && make install
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# essa flag de cflags, sao antigas nessa versao https://cryptography.io/en/35.0.0/installation/
# por algum motivo funcionou desse jeito, com o OPENSSL nao vai
RUN . "$HOME/.cargo/env" && CFLAGS="-I/root/openssl/include" LDFLAGS="-L/root/openssl/lib" /root/env/bin/python -m pip wheel --no-binary :all: cryptography
# RUN . "$HOME/.cargo/env" && OPENSSL_DIR="/root/openssl" /root/env/bin/python -m pip wheel --no-cache-dir --no-binary cryptography cryptography
RUN /root/env/bin/python -m pip install cryptography-39.0.2-cp39-cp39-linux_x86_64.whl && /root/env/bin/python -m pip install pyOpenSSL
RUN /root/env/bin/python -m OpenSSL.debug
ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment