如何在同一个pip存储库中维护glibc和libmusl Python轮子?

2024-05-14 20:52:13 发布

您现在位置:Python中文网/ 问答频道 /正文

以前我们只将内部pip存储库用于源代码分发。向前看,我们还希望托管wheels来完成两件事:

  1. 为(本地)开发人员机器和Alpine Docker环境提供我们自己的代码
  2. 为没有Alpine轮子的包创建轮子

不幸的是,使用不同库构建的轮子共享相同的工件名称,第二个被pip存储库拒绝:

码头工人-合成.yml

version: '3'

services:
  build-alpine:
    build: alpine
    image: build-alpine-wheels
    volumes:
      - $PWD/cython:/build
    working_dir: /build
    command: sh -c 'python setup.py bdist_wheel && twine upload --repository-url http://pypi:8080 -u admin -p admin dist/*'

  build-debian:
    build: debian
    image: build-debian-wheels
    volumes:
      - $PWD/cython-debian:/build
    working_dir: /build
    command: bash -c 'sleep 10s && python setup.py bdist_wheel && twine upload --repository-url http://pypi:8080 -u admin -p admin dist/*'

  pypi:
    image: stevearc/pypicloud:1.0.2
    volumes:
      - $PWD/pypi:/etc/pypicloud/

  alpine-test:
    image: build-alpine-wheels
    depends_on:
      - build-alpine
    command: sh -c 'while ping -c1 build-alpine &>/dev/null;  do sleep 1; done; echo "build container finished" && pip install -i http://pypi:8080/pypi --trusted-host pypi cython && cython --version'

  debian-test:
    image: python:3.6
    depends_on:
      - build-debian
    command: bash -c 'while ping -c1 build-debian &>/dev/null;  do sleep 1; done; echo "build container finished" && pip install -i http://pypi:8080/pypi --trusted-host pypi cython && cython --version'

阿尔卑斯山/Dockerfile

^{pr2}$

debian/Dockerfile

FROM python:3.6-slim

RUN apt-get update && apt-get install -y \
    build-essential \
 && rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip
RUN pip install twine

pypi公司/配置.ini

[app:main]
use = egg:pypicloud

pyramid.reload_templates = False
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en

pypi.default_read =
    everyone
pypi.default_write =
    everyone

pypi.storage = file
storage.dir = %(here)s/packages

db.url = sqlite:///%(here)s/db.sqlite

auth.admins =
  admin

user.admin = $6$rounds=535000$sFuRqMc5PbRccW1J$OBCsn8szlBwr4yPP243JPqomapgInRCUavv/p/UErt7I5FG4O6IGSHkH6H7ZPlrMXO1I8p5LYCQQxthgWZtxe1

# For beaker
session.encrypt_key = s0ETvuGG9Z8c6lK23Asxse4QyuVCsI2/NvGiNvvYl8E=
session.validate_key = fJvHQieaa0g3XsdgMF5ypE4pUf2tPpkbjueLQAAHN/k=
session.secure = False
session.invalidate_corrupt = true

###
# wsgi server configuration
###

[uwsgi]
paste = config:%p
paste-logger = %p
master = true
processes = 20
reload-mercy = 15
worker-reload-mercy = 15
max-requests = 1000
enable-threads = true
http = 0.0.0.0:8080
virtualenv = /env

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, botocore, pypicloud

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_pypicloud]
level = DEBUG
qualname = pypicloud
handlers =

[logger_botocore]
level = WARN
qualname = botocore
handlers =

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)s %(asctime)s [%(name)s] %(message)s

设置和执行

git clone https://github.com/cython/cython
git clone https://github.com/cython/cython cython-debian
docker-compose build
docker-compose up

最后,我希望两个测试容器都能够执行cython --version。适用于阿尔卑斯集装箱:

alpine-test_1   | Collecting cython
alpine-test_1   | Downloading http://pypi:8080/api/package/cython/Cython-0.29.12-cp36-cp36m-linux_x86_64.whl (5.0MB)
alpine-test_1   | Installing collected packages: cython
alpine-test_1   | Successfully installed cython-0.29.12
alpine-test_1   | Cython version 0.29.12

但不适用于Debian容器:

debian-test_1   | Downloading http://pypi:8080/api/package/cython/Cython-0.29.12-cp36-cp36m-linux_x86_64.whl (5.0MB)
debian-test_1   | Installing collected packages: cython
debian-test_1   | Successfully installed cython-0.29.12
debian-test_1   | Traceback (most recent call last):
debian-test_1   |   File "/usr/local/bin/cython", line 6, in <module>
debian-test_1   |     from Cython.Compiler.Main import setuptools_main
debian-test_1   |   File "/usr/local/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 28, in <module>
debian-test_1   |     from .Scanning import PyrexScanner, FileSourceDescriptor
debian-test_1   | ImportError: libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory

我觉得特别奇怪的是,这两个环境都试图拉这个轮子,因为有各种各样的包不适合阿尔卑斯山(例如熊猫),在这种情况下,pip直接用于源代码分发。我想我在这方面肯定也做错了什么。在

所以现在我想知道如何创建这些轮子,这样对于软件包的每个版本,两个不同的轮子可以存在于pip存储库中,并让pip自动下载并安装正确的轮子。在


Tags: installpiptestimagebuildpypipyramidhttp
2条回答

目前在manylinux标准中没有对musl的支持:您可以选择始终从源代码构建,或者以不同的、基于glibc的平台为目标。在

我建议不要使用Alpine,你可以在多阶段构建时得到几乎一样小的图像(https://pythonspeed.com/articles/smaller-python-docker-images/),musl不仅仅意味着缺少二进制轮子。由于musl(Python崩溃、时间戳格式化问题,请参阅https://pythonspeed.com/articles/base-image-python-docker-images/以获取参考)导致的大量产品缺陷。在

大多数已知的musl链接都已修复,但它已经足够不同了,它似乎不值得冒生产风险(更不用说您非常昂贵的开发时间!)只是为了得到一个100MB的图像。在

相关问题 更多 >

    热门问题