在 Debian 上安装 libgit2 和 pygit2 Docker

Installing libgit2 and pygit2 on Debian Docker

我一直在尝试使用 Debian:Jessie docker 文件安装 pygit2 和 libgit2。我能够使用 ubuntu 几乎相同的包编译包,但不能使用 debian。

下面是我使用的Dockerfile和输出的错误示例

FROM debian:jessie

# Install packages
RUN DEBIAN_FRONTEND=noninteractive apt-get update -qq && \
    DEBIAN_FRONTEND=noninteractive apt-get install -yqq \
    libssl-dev \
    libssh2-1-dev \
    libffi-dev \
    zlib1g-dev \
    python-cffi \
    python-dev \
    python-pip \
    build-essential \
    cmake \
    gcc \
    pkg-config \
    git \
    libhttp-parser-dev \
    python-setuptools

RUN cd /tmp && \
    wget https://github.com/openssl/openssl/archive/OpenSSL_1_0_1r.tar.gz && \
    tar xzf OpenSSL_1_0_1r.tar.gz && \
    cd openssl-OpenSSL_1_0_1r && \
    ./config -fPIC --prefix=/usr/local/ -ldl && \
    make && \
    make install

RUN cd /tmp && \
    wget https://github.com/libgit2/libgit2/archive/v0.20.0.tar.gz && \
    tar xzf v0.20.0.tar.gz && \
    cd libgit2-0.20.0/

RUN cd /tmp/libgit2-0.20.0 && \
    cmake . && \
    cmake --build . && \
    ldconfig && \
    pip install -I pygit2==0.20.3 && \
    pip install -I pyOpenSSL==0.15.1

RUN pip install pip==8.1.2 && \
    pip install cherrypy==3.2.2 \
                tornado==4.3 \
                docker-py==1.8.1 \
                halite==0.1.17 \
                GitPython==0.3.2.RC1 \
                # pygit2==0.20.3 \
                pyOpenSSL==0.15.1

但是在编译 libgit2 库时,出现以下错误

[ 99%] Building C object CMakeFiles/libgit2_clar.dir/tests/blame/harder.c.o
/tmp/libgit2-0.20.0/tests/blame/harder.c: In function 'test_blame_harder__m':
/tmp/libgit2-0.20.0/tests/blame/harder.c:37:20: warning: variable 'opts' set but not used [-Wunused-but-set-variable]
  git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
                    ^
/tmp/libgit2-0.20.0/tests/blame/harder.c: In function 'test_blame_harder__c':
/tmp/libgit2-0.20.0/tests/blame/harder.c:45:20: warning: variable 'opts' set but not used [-Wunused-but-set-variable]
  git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
                    ^
/tmp/libgit2-0.20.0/tests/blame/harder.c: In function 'test_blame_harder__cc':
/tmp/libgit2-0.20.0/tests/blame/harder.c:55:20: warning: variable 'opts' set but not used [-Wunused-but-set-variable]
  git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
                    ^
/tmp/libgit2-0.20.0/tests/blame/harder.c: In function 'test_blame_harder__ccc':
/tmp/libgit2-0.20.0/tests/blame/harder.c:65:20: warning: variable 'opts' set but not used [-Wunused-but-set-variable]
  git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
                    ^
[ 99%] Building C object CMakeFiles/libgit2_clar.dir/tests/blame/blame_helpers.c.o
[100%] Building C object CMakeFiles/libgit2_clar.dir/tests/blame/getters.c.o
Linking C executable libgit2_clar
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x354): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x412): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x484): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x542): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x5a9): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x60d): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x645): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x6d1): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x731): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x792): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
CMakeFiles/libgit2_clar.dir/build.make:9030: recipe for target 'libgit2_clar' failed
make[2]: *** [libgit2_clar] Error 1
make[1]: *** [CMakeFiles/libgit2_clar.dir/all] Error 2
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/libgit2_clar.dir/all' failed
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

如果我遗漏了依赖项,有人可以告诉我吗?

谢谢

更新

我尝试将 libgit2 更新到版本 0.24.1 但仍然收到以下错误

[100%] Building C object CMakeFiles/libgit2_clar.dir/tests/blame/getters.c.o
Linking C executable libgit2_clar
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x354): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x412): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x484): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x542): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x5a9): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x60d): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x645): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x6d1): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x731): undefined reference to `dlerror'
/usr/local/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x792): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
CMakeFiles/libgit2_clar.dir/build.make:11874: recipe for target 'libgit2_clar' failed
make[2]: *** [libgit2_clar] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/libgit2_clar.dir/all' failed
Makefile:127: recipe for target 'all' failed
make[1]: *** [CMakeFiles/libgit2_clar.dir/all] Error 2
make: *** [all] Error 2

我在你的'install packages'

之后添加了以下内容
RUN apt-get update
RUN apt-get install -y wget

RUN wget https://github.com/libgit2/libgit2/archive/v0.24.0.tar.gz && \
tar xzf v0.24.0.tar.gz && \
cd libgit2-0.24.0/ && \
cmake . && \
make && \
make install

RUN ldconfig
RUN pip install pygit2

对我来说这似乎有效。你必须 运行 ldconfig 创建必要的 link 到 libgit2

部分输出:

l/include -I/usr/include/python2.7 -c src/commit.c -o build/temp.linux-x86_64-2.7/src/commit.o
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include -I/usr/include/python2.7 -c src/error.c -o build/temp.linux-x86_64-2.7/src/error.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/diff.o build/temp.linux-x86_64-2.7/src/options.o build/temp.linux-x86_64-2.7/src/utils.o build/temp.linux-x86_64-2.7/src/tag.o build/temp.linux-x86_64-2.7/src/object.o build/temp.linux-x86_64-2.7/src/signature.o build/temp.linux-x86_64-2.7/src/reference.o build/temp.linux-x86_64-2.7/src/blob.o build/temp.linux-x86_64-2.7/src/pygit2.o build/temp.linux-x86_64-2.7/src/note.o build/temp.linux-x86_64-2.7/src/repository.o build/temp.linux-x86_64-2.7/src/oid.o build/temp.linux-x86_64-2.7/src/walker.o build/temp.linux-x86_64-2.7/src/patch.o build/temp.linux-x86_64-2.7/src/treebuilder.o build/temp.linux-x86_64-2.7/src/branch.o build/temp.linux-x86_64-2.7/src/tree.o build/temp.linux-x86_64-2.7/src/commit.o build/temp.linux-x86_64-2.7/src/error.o -L/usr/local/lib -lgit2 -o build/lib.linux-x86_64-2.7/_pygit2.so
    building '_cffi__x50f7320ax7286955d' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include -I/usr/include/python2.7 -c __pycache__/_cffi__x50f7320ax7286955d.c -o build/temp.linux-x86_64-2.7/__pycache__/_cffi__x50f7320ax7286955d.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/__pycache__/_cffi__x50f7320ax7286955d.o -L/usr/local/lib -lgit2 -o build/lib.linux-x86_64-2.7/_cffi__x50f7320ax7286955d.so

Successfully installed pygit2

编辑: 这是完整的 dockerfile。现在我必须更新 libgit2 版本才能让它工作。这是完整的 dockerfile:

FROM debian:jessie

# Install packages
RUN DEBIAN_FRONTEND=noninteractive apt-get update -qq && \
    DEBIAN_FRONTEND=noninteractive apt-get install -yqq \
    libssl-dev \
    libssh2-1-dev \
    libffi-dev \
    zlib1g-dev \
    python-cffi \
    python-dev \
    python-pip \
    build-essential \
    cmake \
    gcc \
    pkg-config \
    git \
    libhttp-parser-dev \
    python-setuptools \
    wget

RUN wget https://github.com/libgit2/libgit2/archive/v0.25.0.tar.gz && \
tar xzf v0.25.0.tar.gz && \
cd libgit2-0.25.0/ && \
cmake . && \
make && \
make install

RUN ldconfig
RUN pip install pygit2

Mike Chernev's solution from here 为我工作:

FROM python
MAINTAINER Mike Chernev <mike@mikechernev.com>

ENV LIBGIT_VERSION 1.1.0

# Cmake is a dependency for building libgit2
RUN apt-get update && apt-get install -y cmake \

# Downloading and building libgit2
    && wget https://github.com/libgit2/libgit2/archive/v${LIBGIT_VERSION}.tar.gz \
    && tar xzf v${LIBGIT_VERSION}.tar.gz \
    && cd libgit2-${LIBGIT_VERSION} \
    && cmake . \ 
    && make \
    && make install \
# The python wrapper for libgit2
    && pip install pygit2 \
# Required for updating the libs
    && ldconfig

此外,您必须从 requirements.txt 文件中删除 pygit2。

您可以找到 latest version of libgit2 here.