Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

In Pipelines, how can I cache gRPC after installing it with pecl?

Edited

Hello everyone,

I am just setting up our project's bitbucket-pipelines.yml file. We have a PHP web application that uses the gRPC extension.

My current default build steps are:

image: php:7.3-cli

definitions:
steps:
- step: &build
name: Build
caches:
- composer
script:
- apt-get update && apt-get install -y ssh unzip autoconf libz-dev git
- pecl install grpc
- docker-php-ext-enable grpc
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- step: &run_tests
name: Run Tests
script:
- vendor/bin/phpunit --testdox protected/tests

pipelines:
default:
- step: *build
- step: *run_tests

The problem is, pecl install grpc takes over 7 minutes to compile and install.

I was reading the article on Caching dependencies, but I'm not sure how to cache grpc in this case, so I don't have to wait over 7 minutes each time this builds.

Any suggestions on how this is achieved?

Thank you!

1 answer

1 accepted

1 vote
Answer accepted

Alright, so after spending a good amount of time trying to figure this out, I ended up realizing that I should simply create my own Docker image.

So I made one based on the PHP Docker image "php:7.3-cli" by creating this Dockerfile:

FROM php:7.3-cli

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

RUN apt-get update && apt-get install -qy ssh unzip autoconf libz-dev git
RUN yes | pecl install grpc-1.26.0
RUN install-php-extensions grpc
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

As you may have noticed, I ended up using a php-extension-installer to help me enable grpc; more details on that here: https://github.com/mlocati/docker-php-extension-installer

 

After that, while referring to this guide, I uploaded my Docker image to DockerHub and modified my Git repo's "bitbucket-pipelines.yml" file accordingly:

image: asimdlvct/php7.3-grpc1.26.0:ctweb

definitions:
steps:
- step: &setup_and_run_tests
name: Setup dependencies and run tests
caches:
- composer
script:
- composer install
- vendor/bin/phpunit --testdox protected/tests

pipelines:
default:
- step: *setup_and_run_tests

And now it works great, all running under a minute in Bitbucket Pipelines!

 

Also, I realized that my previous YAML file was wrong, since each "step" acts as a different build. So I couldn't install the composer dependencies in one step, and run tests that depended on those packages being installed in a different step! Had to be done in the same step, which makes sense in hindsight.

 

Thanks for sharing!

Like # people like this

Thanks for sharing, it helps a lot :) 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,755 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you