返回 首页

docker编译arm python


FROM alexcrichton/rust-slave-linux-cross:2017-02-02
#You can this Docker image 109 it contains an ARM cross toolchain that ships with glibc-2.14. The official binary releases are built using that toolchain.
#https://users.rust-lang.org/t/how-to-compile-rust-with-a-specific-glibc-version-for-gnueabihf-architecture/6680/4
ENV CC=arm-linux-gnueabihf-gcc
ENV CXX=arm-linux-gnueabihf-g++
ENV AR=arm-linux-gnueabihf-ar
ENV RANLIB=arm-linux-gnueabihf-ranlib
ENV LD=arm-linux-gnueabihf-ld

USER root
RUN  sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list  \
     && echo deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial main universe restricted multiverse >> /etc/apt/sources.list \
      && apt-key adv --keyserver keyserver.ubuntu.com/ --recv-keys BA6932366A755776 \
    && apt-get update  && apt-get install wget make  vim software-properties-common   -y \
    &&  apt-get install python3.6 sqlite3 libsqlite3-dev  python3.6-dev unixodbc-dev binutils-arm-linux-gnueabi -y
#RUN apt-get install binutils-arm-linux-gnueabi -y   ; exit 0
RUN cp /usr/bin/python3 /python3   && cp /usr/bin/python /python \
    && ln -sfn /usr/bin/python3.6 /usr/bin/python3  && ln -sfn /usr/bin/python3 /usr/bin/python

#RUN apt-get install  \
#    libbz2-dev \
#    libncurses5-dev \
#     libgdbm-dev  \
#     liblzma-dev  \
#     sqlite3 libsqlite3-dev python3-pip  \
#     libsqlite3-dev openssl libssl-dev tcl8.6-dev tk8.6-dev libreadline-dev zlib1g-dev \
#      uuid-dev liblzma-dev  -y


#zlib
RUN wget  http://www.zlib.net/zlib-1.2.11.tar.gz && tar -zxvf zlib-1.2.11.tar.gz
RUN cd zlib-1.2.11 \
    && ./configure --prefix=/root/lib \
    && make && make install

# sqllite
RUN wget --no-check-certificate https://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz && tar -zxvf sqlite-autoconf-3360000.tar.gz
RUN cd  sqlite-autoconf-3360000 \
 && ./configure --host=arm-linux-gnueabihf  --prefix=/root/lib/  --enable-shared --disable-readline --disable-dynamic-extensions \
 && make -j4 && make install


#ssl
RUN wget   --no-check-certificate http://www.openssl.org/source/openssl-1.1.0i.tar.gz && tar -zxvf openssl-1.1.0i.tar.gz
RUN cd openssl-1.1.0i \
    && ./Configure linux-aarch64 no-asm no-async --prefix=/root/lib \
   && make -j4 && make install


# python
RUN  sed -i "s/python3/python3.5/g"  /usr/bin/lsb_release  \
    && wget  --no-check-certificate https://npm.taobao.org/mirrors/python/3.6.9/Python-3.6.9.tgz && tar -zxvf  Python-3.6.9.tgz

RUN cd Python-3.6.9  \
   && sed -ie '/^#SSL/a SSL=/root/lib\n\n_ssl _ssl.c -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl -L$(SSL)/lib -lssl -lcrypto' Modules/Setup.dist \
   && sed -ie '/^#zlib/a zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz ' Modules/Setup.dist \
    && ./configure --host=arm-linux-gnueabihf  \
        --build=i386 --disable-ipv6 ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no  \
        --prefix=/root/python --enable-shared   CPPFLAGS='-I/root/lib/include' LDFLAGS='-L/root/lib/lib'  CFLAGS='-I/root/lib/lib' \
    && make -j4 && make install

RUN apt-get install --reinstall -y python3-pip  ; exit 0

# freetds
COPY ./freetds-0.95.95.tar.gz /
RUN cd  /  && tar -zxvf freetds-0.95.95.tar.gz   && cd freetds-0.95.95 \
    && ./configure --prefix=/root/lib --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared --enable-static --host=arm-linux-gnueabihf  --disable-libiconv \
        && make&& make install

RUN apt-get install --reinstall -y python3-pip  ; exit 0

RUN pip3 install Cython setuptools --upgrade -i https://pypi.douban.com/simple

ENV  LDSHARED="arm-linux-gnueabihf-gcc -shared"
ENV LDFLAGS="-L/root/python/lib -L/root/lib/lib"
ENV CFLAGS="-I/root/python/include/python3.6m -I/root/lib/include"
ENV LDSHARED="arm-linux-gnueabihf-gcc -shared"
ENV PYTHONPATH=/root/python/lib/python3.6/site-packages

# psutil
RUN wget   --no-check-certificate https://files.pythonhosted.org/packages/e1/b0/7276de53321c12981717490516b7e612364f2cb372ee8901bd4a66a000d7/psutil-5.8.0.tar.gz
RUN tar -zxvf  psutil-5.8.0.tar.gz
RUN cd psutil-5.8.0   \
    &&  export LDSHARED="arm-linux-gnueabihf-gcc -shared" \
        && python3 setup.py install --prefix=/root/python/



RUN apt-get install --reinstall -y python3-pip  ; exit 0



COPY entrypoint.sh /entrypoint.sh
COPY main.c /main.c

ENTRYPOINT []

使用alexcrichton/rust-slave-linux-cross:2017-02-02镜像, 是为了兼容较老的glibc版本。 只粘了关键步骤, 运行上面这些指令后, 将容器内的 /root/python/和/root/lib/ 复制出来即可。



评论(0)

登录