Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building the extension in Docker #3

Open
zeroware opened this issue Oct 13, 2023 · 2 comments
Open

Building the extension in Docker #3

zeroware opened this issue Oct 13, 2023 · 2 comments
Assignees

Comments

@zeroware
Copy link

Hello,

Here is a Dockerfile i'm trying to create to compile and test this extension with multiple PHP versions.
I run the testbed at the end to verify that the extension is working.

ARG PHP_VERSION_MAJOR=8
ARG PHP_VERSION_MINOR=1
ARG PHP_VERSION=$PHP_VERSION_MAJOR.$PHP_VERSION_MINOR

FROM php:$PHP_VERSION-zts-bookworm as php-git2-debian
ARG PHP_VERSION_MAJOR
ARG PHP_VERSION_MINOR
ARG PHP_VERSION
ARG PHP_GIT2_PHP_VERSION=php$PHP_VERSION_MAJOR
ARG PHP_GIT2_VERSION=v2.0.0

RUN apt-get update && \
    apt-get -y --no-install-recommends install \
    git \
    wget \
    libgit2-dev \
    unzip \
    && \
    apt-get clean

RUN cd /opt && \
    wget https://github.com/RogerGee/php-git2/archive/refs/tags/$PHP_GIT2_PHP_VERSION/$PHP_GIT2_VERSION.zip -O php-git2.zip && \
    unzip php-git2.zip && \
    cd /opt/php-git2-$PHP_GIT2_PHP_VERSION-$PHP_GIT2_VERSION && \
    phpize && \
    ./configure && \
    make &&  \
    make install && \
    rm /opt/php-git2.zip

RUN docker-php-ext-enable git2

FROM php-git2-debian as php-git2-debian-test

COPY --from=composer/composer:2-bin /composer /usr/bin/composer

RUN git --global --add user.name root && \
    git --global --add user.email root@localhost \

RUN cd /opt/php-git2-$PHP_GIT2_PHP_VERSION-$PHP_GIT2_VERSION/testbed && \
    composer update && \
    composer install && \
    php main.php

The tests are failing on PHP 8.1 and 8.2 with the following errors :

There were 6 errors:

1) PhpGit2\Test\RemoteTest::testConnect
Git2Exception: libgit2 error: (12): unsupported URL protocol

/opt/php-git2-php8-v2.0.0/testbed/src/Test/RemoteTest.php:221

2) PhpGit2\Test\RemoteTest::testDownload
Git2Exception: libgit2 error: (12): unsupported URL protocol

/opt/php-git2-php8-v2.0.0/testbed/src/Test/RemoteTest.php:284

3) PhpGit2\Test\RemoteTest::testFetch
Git2Exception: libgit2 error: (12): unsupported URL protocol

/opt/php-git2-php8-v2.0.0/testbed/src/Test/RemoteTest.php:311

4) PhpGit2\Test\RemoteTest::testFetch_Default
Git2Exception: libgit2 error: (12): unsupported URL protocol

/opt/php-git2-php8-v2.0.0/testbed/src/Test/RemoteTest.php:324

5) PhpGit2\Test\RemoteTest::testPrune
Git2Exception: libgit2 error: (12): this remote has never connected

/opt/php-git2-php8-v2.0.0/testbed/src/Test/RemoteTest.php:397

6) PhpGit2\Test\RemoteTest::testUpdateTips
Git2Exception: libgit2 error: (12): this remote has never connected

/opt/php-git2-php8-v2.0.0/testbed/src/Test/RemoteTest.php:452
@RogerGee RogerGee self-assigned this Oct 13, 2023
@RogerGee
Copy link
Owner

This is due to an issue with the configured remote in one of the testbed repositories. I will have to fix this in the next release. For now, I have a workaround that I've added to your Dockerfile:

ARG PHP_VERSION_MAJOR=8
ARG PHP_VERSION_MINOR=1
ARG PHP_VERSION=$PHP_VERSION_MAJOR.$PHP_VERSION_MINOR

FROM php:$PHP_VERSION-zts-bookworm as php-git2-debian
ARG PHP_VERSION_MAJOR
ARG PHP_VERSION_MINOR
ARG PHP_VERSION
ARG PHP_GIT2_PHP_VERSION=php$PHP_VERSION_MAJOR
ARG PHP_GIT2_VERSION=v2.0.0

RUN apt-get update && \
    apt-get -y --no-install-recommends install \
    git \
    wget \
    libgit2-dev \
    unzip \
    && \
    apt-get clean

RUN cd /opt && \
    wget https://github.com/RogerGee/php-git2/archive/refs/tags/$PHP_GIT2_PHP_VERSION/$PHP_GIT2_VERSION.zip -O php-git2.zip && \
    unzip php-git2.zip && \
    cd /opt/php-git2-$PHP_GIT2_PHP_VERSION-$PHP_GIT2_VERSION && \
    phpize && \
    ./configure && \
    make &&  \
    make install && \
    rm /opt/php-git2.zip

RUN docker-php-ext-enable git2

FROM php-git2-debian as php-git2-debian-test
ARG PHP_VERSION_MAJOR
ARG PHP_VERSION_MINOR
ARG PHP_VERSION
ARG PHP_GIT2_PHP_VERSION=php$PHP_VERSION_MAJOR
ARG PHP_GIT2_VERSION=v2.0.0

COPY --from=composer/composer:2-bin /composer /usr/bin/composer

RUN git config --global user.name root && \
    git config --global user.email root@localhost

# This fixes an issue with running the testbed concerning the remote configured
# in the bare repository. We need it to point at an actual repository on disk.
# This will be fixed in future releases of php-git2. -RogerGee
RUN cd /opt/php-git2-$PHP_GIT2_PHP_VERSION-$PHP_GIT2_VERSION/testbed/repos && \
   git init general && \
   cd general && \
     echo 'contents' > file && \
     git add file && \
     git commit -m '1' && \
   cd ../general.git && \
   git remote set-url origin /opt/php-git2-$PHP_GIT2_PHP_VERSION-$PHP_GIT2_VERSION/testbed/repos/general

RUN cd /opt/php-git2-$PHP_GIT2_PHP_VERSION-$PHP_GIT2_VERSION/testbed && \
    echo composer update && \
    composer install && \
    php main.php

I had to modify the file slightly to get it to build for me. (I may be running an older version of Docker.)

Also, I removed the composer update which takes away the deprecation warnings. I will address the deprecated usage in the next release. The PHP 8 extension properly raises exceptions in all cases, but in the PHPUnit files I still am checking those exception errors with the older methods.

I will close this issue out once those changes are in place. Sorry for any inconvenience.

@zeroware
Copy link
Author

Thanks for your fix.
I don't know much about Github CI but I wonder if we could use the Dockerfile to build and test the repository against multiple PHP versions automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants