为 Python/Django 构建 arm64-Python 映像时出现 lib-sodium/pynacl 错误

Ole*_*sov 6 django python-3.x docker arm64 apple-m1

摘要:我正在尝试为我的项目构建一个 ARM64 映像,以便能够在我的 macbook M1 (pro) 计算机上本地更快地运行它,而不是使用运行速度极慢的普通 x64 映像(启动时间长、本地响应时间长) dev HTTP 服务器,测试运行时间长)。

我有以下泊坞窗文件:

FROM arm64v8/python

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpq-dev \
    build-essential \
    libssl-dev \
    libffi-dev

# Install Node.js for ARM64
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs

# Set the working directory in the container
WORKDIR /app

# Install Python dependencies
RUN pip install --no-cache-dir cryptography
RUN pip install --no-cache-dir pyNaCl==1.3.0

# Copy the requirements.txt file to the container
COPY requirements.txt .

# Install additional Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the Django project files to the container
COPY . .

# Expose the Django development server port
EXPOSE 8000

# Start the Django development server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Run Code Online (Sandbox Code Playgroud)

requirements.txt

autopep8==1.6.0
kombu>=5.0.0  # celery dependency
celery==5.0.0
dj-database-url==0.5
django==3.2.13
django-bootstrap4==2.2.0
django-cors-headers==3.4.0
django-debug-toolbar==3.2.1
django-phonenumber-field==4.0.0
django-safedelete==0.5.6
djangorestframework==3.13.0
djangorestframework-xml==2.0.0
django-model-utils==4.2.0
gunicorn==20.0.4
ipdb==0.13.3
jedi==0.18.1  # ipython dependency
ipython==7.32.0
ipython-genutils==0.2.0
newrelic==7.16.0.178
pep8==1.7.1
python-dateutil>=2.8.0
pytz>=2019.2
redis==3.5.3
django-redis==4.12.1
requests==2.27.1
requests-mock>=1.6.0
selenium==3.141.0
twilio==7.8.0
django-filter==2.4.0
psycopg2==2.9.3
django-session-security==2.6.6
django-axes==5.4.1
beautifulsoup4==4.9.1
git+https://github.com/onitsoft/uphold-sdk-python.git#egg=uphold
isort==5.2.0
freezegun>=0.3.1
suds-community>=1.1.0
drf-extensions>=0.5.0
requests-cache==0.5.2
xmltodict==0.12
python-bitcoinrpc==1.0
urllib3==1.26.5
pillow==9.1.0
git+https://github.com/onitsoft/django-loginurl.git#egg=django-loginurl
django-countries==7.3.2
tornado==6.0.4 # flower dependency
flower==0.9.5
django-guardian==2.4.0
dredd-hooks==0.2.0
django-fsm==2.8.0
git+https://github.com/onitsoft/python-bittrex.git#egg=python-bittrex
cached-property==1.5.1
web3==5.25.0
# pycrypto==2.6.1
pycryptodome==3.14.1
django-extensions==3.1.5
django-oauth-toolkit==1.7.1
iptools==0.7.0
django-otp==0.9.3
qrcode==6.1
git+https://github.com/onitsoft/django-audit-log.git@django3-support
rlp==1.2.0
django-newsletter==0.9.1
git+https://github.com/onitsoft/py-stellar-base.git@2.10.0
django-email-log==1.2.0
django-nested-admin==3.4.0
#bintrees==2.0.7
sortedcontainers==2.2.2
git+https://github.com/onitsoft/OrderBook.git@5dbd18b4534ac4945b7e53315c65e1d49d9e340d#egg=orderbook
django-picklefield===2.1.1
pdbpp==0.10.2
pyyaml==5.4.1
git+https://github.com/onitsoft/ripple-python
django-constance==2.9.1
django-admin-rangefilter==0.8.4
toml==0.10.1
phonenumbers==8.12.7
django-post-office==3.4.1
slackclient==2.7.3
django-intercom==0.1.3
django-ipware==3.0.7
django-enum-choices==2.1.3
git+https://github.com/onitsoft/monero-python.git@v0.9.3
simplejson==3.17.2
django-polymorphic==3.1.0
retrying==1.3.3
ccxt==3.0.51
django-admin-multiple-choice-list-filter==0.1.1
celery-once==3.0.1
bidict==0.21.2
fireblocks-sdk==1.19.0
pycountry==20.7.3
cbor==1.0.0
git+https://github.com/onitsoft/django-admin-comments.git
lxml==4.9.1
supervisor==4.2.4
django-admin-csvexport==1.11
rsa==4.9
pydantic==1.10.2
XlsxWriter==3.0.8
Run Code Online (Sandbox Code Playgroud)

回溯: https: //pastebin.com/1xtwdfXY(太长,无法粘贴到此处)

我已经尝试过您可以在网上找到的所有内容,包括:

  • 通过 apt 而不是通过 pip 安装 lib-sodium
  • 特别使用安装 pynacl 版本 1.3.0pynacl==1.3.0
  • 通过以下方式在主机(MacO)上本地安装 lib-sodiumbrew install libsodium

但遗憾的是没有任何帮助。资料来源:

djm*_*nki 2

PyNaCl v1.5.0是唯一兼容 Mac ARM64 的版本。
该版本于 2022 年 1 月 7 日发布 - PyNaCl v1.5.0 变更日志

libsodium此外,还必须使用 ARM64 docker 映像发行版提供的版本,而不是捆绑的版本PyNaCl v1.5.0.

因此,您的 Dockerfile 需要进行以下更改:

RUN SODIUM_INSTALL=system pip install --no-cache-dir pyNaCl==1.5.0
Run Code Online (Sandbox Code Playgroud)

的要求PyNaCl v1.5.0对 中声明的依赖项产生了连锁影响requirements.txt

以下是使用以下命令构建 Docker 映像时发现的一些内容PyNaCl v1.5.0

py-stellar-base.git@2.10.0 - only compatible with PyNaCl 1.3.0
    updating to v 8.2.1 which compiled with PyNaCl 1.5.0 had knock on effects
    with the following:
    urllib3==1.26.5 -> 1.26.7
    toml==0.10.1 -> 0.10.2
Run Code Online (Sandbox Code Playgroud)

注意:进行上述更改可能不允许您的项目运行 - 显然可能会对项目代码等产生影响。