Mo J. Mughrabi
Mo J. Mughrabi

Reputation: 6997

Installing libgit2 and pygit2 on Debian Docker

I have been trying to install pygit2 and libgit2 using a Debian:Jessie docker file. I was able to compile the package with almost the same packages with ubuntu, but not with debian.

Below is the Dockerfile I used and output error sample

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

But when compiling the libgit2 library, am getting the following error

[ 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

Can someone please advise if I missed a dependency?

Thanks

Update

I tried updating the libgit2 to version 0.24.1 but still getting the following error

[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

Upvotes: 2

Views: 3441

Answers (2)

Webucator
Webucator

Reputation: 2693

Mike Chernev's solution from here worked for me:

FROM python
MAINTAINER Mike Chernev <[email protected]>

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

In addition, you will have to remove pygit2 from your requirements.txt file.

You can find the latest version of libgit2 here.

Upvotes: 0

lvthillo
lvthillo

Reputation: 30771

I added the following after your '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

For me this seems to work. You have to run ldconfig to create the necessary link to libgit2

A part of the output:

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

EDIT: Here is the full dockerfile. Now I had to update the libgit2 version to let it work. Here is the full 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

Upvotes: 3

Related Questions