raspberry piでdocker buildするとcryptographyがエラーになる件
公開: 2023年03月30日
** raspberry piでdocker buildするとcryptographyがエラーになる件 **
目次
raspberrypi でDocker buildするとエラーが出た
ラズパイでDockerをビルドした際に以下のエラーがでた。
#0 1357.7 error: failed to get `asn1` as a dependency of package `cryptography-rust v0.1.0 (/tmp/pip-install-s6o7_ky6/cryptography_ead2bdf31835430bb895fb435fae6096/src/rust)`
#0 1357.7
#0 1357.7 Caused by:
#0 1357.7 failed to fetch `https://github.com/rust-lang/crates.io-index`
#0 1357.7
#0 1357.7 Caused by:
#0 1357.7 error inflating zlib stream; class=Zlib (5)
#0 1357.7
#0 1357.7 =============================DEBUG ASSISTANCE=============================
#0 1357.7 If you are seeing a compilation error please try the following steps to
#0 1357.7 successfully install cryptography:
#0 1357.7 1) Upgrade to the latest pip and try again. This will fix errors for most
#0 1357.7 users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
#0 1357.7 2) Read https://cryptography.io/en/latest/installation/ for specific
#0 1357.7 instructions for your platform.
#0 1357.7 3) Check our frequently asked questions for more information:
#0 1357.7 https://cryptography.io/en/latest/faq/
#0 1357.7 4) Ensure you have a recent Rust toolchain installed:
#0 1357.7 https://cryptography.io/en/latest/installation/#rust
#0 1357.7
#0 1357.7 Python: 3.11.2
#0 1357.7 platform: Linux-5.15.84-v7+-armv7l-with-glibc2.31
#0 1357.7 pip: n/a
#0 1357.7 setuptools: 67.6.1
#0 1357.7 setuptools_rust: 1.5.2
#0 1357.7 rustc: 1.48.0
#0 1357.7 =============================DEBUG ASSISTANCE=============================
#0 1357.7
#0 1357.7 error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path src/rust/Cargo.toml --release -v --features 'pyo3/abi3-py36 pyo3/extension-module' -- --crate-type cdylib` failed with code 101
#0 1357.7 [end of output]
#0 1357.7
#0 1357.7 note: This error originates from a subprocess, and is likely not a problem with pip.
#0 1357.7 ERROR: Failed building wheel for cryptography
#0 1357.8 Building wheel for MarkupSafe (setup.py): started
#0 1363.3 Building wheel for MarkupSafe (setup.py): finished with status 'done'
#0 1363.3 Created wheel for MarkupSafe: filename=MarkupSafe-2.1.2-cp311-cp311-linux_armv7l.whl size=26923 sha256=1d668e84564eca2e15ae2fce05c5edabbecac603fa4e97eb725cdab210a52c91
#0 1363.4 Stored in directory: /root/.cache/pip/wheels/86/02/d3/b895040dec39ff4577ce0a016eaf81a6d60ba51e58a72b5a8c
#0 1363.4 Successfully built psycopg2-binary django-allauth django-extra-views python-nmap pyyaml netifaces coreschema MarkupSafe
#0 1363.4 Failed to build cryptography
#0 1363.4 ERROR: Could not build wheels for cryptography, which is required to install pyproject.toml-based projects
#0 1363.7
#0 1363.7 [notice] A new release of pip available: 22.3.1 -> 23.0.1
#0 1363.7 [notice] To update, run: pip install --upgrade pip
------
Dockerfile:8
--------------------
6 | RUN apt-get update
7 | RUN apt-get -y install iputils-ping net-tools dnsutils nmap rustc
8 | >>> RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r /files/requirements.txt
9 |
--------------------
ERROR: failed to solve: process "/bin/sh -c pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r /files/requirements.txt" did not complete successfully: exit code: 1
エラーの発生場所はpip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r /files/requirements.txt
requirements.txtでpipの中身を記述しているので、その中のパッケージになる。
cryptography
のpip installで失敗しているようだ。
Pythonの依存を見てみると以下になる
Python > Django > django-cryptography > Cryptography
ラズパイはarm系のプロセッサのため、pipでバイナリが見つからなかったようで、 rustによるビルドが必要そう。
ただ、rustをインストールする場合もなかなかのパッケージ数だ。
Rustは以下のコマンドで一発インストールできる。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
DockerFileでは対話できないので、以下に修正して対話なしで実行できるようにする。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
再度 docker buildをしたところうまく進んだようだ。
=> => # Created wheel for coreschema: filename=coreschema-0.0.4-py3-none-any.w
=> => # hl size=15015 sha256=62224a32bf62dfa50257405fcd7820546bd15f0f348c751a7f3
=> => # 93fd0aad8aaf1
=> => # Stored in directory: /root/.cache/pip/wheels/96/66/52/ed5030efbbcf5159
=> => # 34995121a21b3345caf37f48434a170588
=> => # Building wheel for cryptography (pyproject.toml): started
しかしながらラズパイのCPUが貧弱なせいか異常に遅い。。。 あと、ラズパイ3ならビルド成功するが、ラズパイゼロだとメモリが512MBないせいか、cryptographyのビルド処理でこけてしまう。