4

We are using CircleCI as build server for php symfony application and we require the mongodb library with composer, which is dependent on the mongodb extension, that we install with pecl. So we have the following steps in our build:

- run: sudo pecl install mongodb
- run: echo -e "extension=mongodb.so" | sudo tee /usr/local/etc/php/php.ini > /dev/null
- run: cd app && composer install --no-interaction

This works fine, but the PECL mongo db extension takes half of our build time.

Is there a way to store the installed PECL extensions into the CircleCI cache?

I have tried the following:

- save_cache: 
          key: pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
          paths:
            - /usr/local/20160303/mongodb.so

But this doesn't work - mongodb is downloaded again by PECL. What are the directories that I should try to cache in this case?

4

1 回答 1

4

回答我自己的问题。有一种方法可以缓存使用 PECL 安装的 PHP 扩展。需要知道 pecl 扩展的确切安装位置(pecl config-show)。似乎在 Circle CI 容器上,这个位置是:

/usr/local/lib/php/extensions/no-debug-non-zts-20160303/

扩展可以从这个文件夹复制到一个可以缓存和恢复的临时目录。可以使用 sudo 将恢复的文件复制回来。

  - run: pecl config-show 
  - run: mkdir pecl-cache
  - restore_cache:
     keys:
     - pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
     - pecl-v1-

  - run:
      name: Copying restored pecl extensions cache into extensions directory 
      command: sudo cp -R pecl-cache/. /usr/local/lib/php/extensions/no-debug-non-zts-20160303/

  - run: 
      name: Install mongodb pecl extensions if mongodb.so is not there
      command: >
        if [ ! -f /usr/local/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so ]; then 
            sudo pecl install mongodb ;
        fi

  - run:
      name: Copying pecl extensions to temp directory which will be cached
      command: sudo cp -R /usr/local/lib/php/extensions/no-debug-non-zts-20160303/* pecl-cache/

  - save_cache: 
      key: pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
      paths:
        - pecl-cachedocker-php-ext-install
于 2018-05-29T11:42:03.093 回答