Run Laravel and PHPUnit in a pipeline

We want to use a pipeline to run phpunit for our Laravel project every time something is committed. I've tried to set this up, but had no luck. I guess it doesn't really help that I am not that familiar with Docker.

Some questions:

  • Is it necessary to run `composer install` every time? We have a moderately large project and I noticed this can take up to 7 minutes. I vaguely know what Docker images are, but can't quite figure out if they would be of any help here.

  • Even though `composer install` finishes successfully, running `artisan` results in an `artisan: command not found` error. Not really sure why this would be... I had hoped that `composer install` would take care of it all.

Is there perhaps anyone who has managed to successfully set up a Bitbucket pipeline for a Laravel project?

Thanks in advance,

Michael

 

 

2 answers

1 accepted

0 vote

Hi Michael,

A docker image is effectively a snapshot of a system at a specific point. Once you run it it works a little like a virtual machine and can be modified and edited as you wish. Because of this using a specific docker image could cut down on the time to install composer or php but it will not also have your dependencies downloaded. You will have to continue to run 'composer install'. I would definitely recommend checking out the docker docs located here: https://docs.docker.com/engine/understanding-docker/

As for the problem of not being able to run artisan after the command finishes I have a few suggestions. If you're not installing artisan globally that might explain not being able to run the command. The first step is to get the docke rimage running locally and then executing the commands on the docker image and seeing whether the problem persists and whether there is a way to diagnose the problem. If this does not work you can raise a support ticket at https://support.atlassian.com/

Cheers,
Tom

Thanks for your answer Tom. I guess delving into Docker a bit more is unavoidable. Will do when I get the time.

Hey Michael, we have successfully set up a working laravel development pipeline, where artisan works without problems. A few suggestions:

  • make sure your docker image has a working php version installed. We are using `image: phpunit/phpunit:5.0.3`as the docker image, it comes with everything preconfigured to run laravel deployments. Since composer already works, it could be the wrong php version or something else related to your php version.

  • be sure to run `php artisan ...` instead of just `artisan ...`
  • cd into the right directory before triggering the command, otherwise artisan will not run

If you want, I can paste a working laravel deployment queue for a target linux machine for you somewhere. Just let me know.

Yes, `php artisan` instead of just `artisan` made the difference. There are still some issues to be resolved though. Like for instance disabling xdebug for composer. I suppose this has to be done from the command line somehow. Furthermore, although both the command `composer install` and `php artisan` finish successfully now, we get the following error when expanding the log for each of these two steps:

{"error":{"type":"ErrorException","message":"file_put_contents(\/meta\/services.json): failed to open stream: No such file or directory","file":"\/opt\/atlassian\/bitbucketci\/agent\/build\/vendor\/laravel\/framework\/src\/Illuminate\/Filesystem\/Filesystem.php","line":70}}

 

It would be great if you could share your laravel setup. I would appreciate this very much.

I've just been experimenting with getting this in place with a fresh Laravel 5.3 install, my pipelines file is this which seems to work:

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: phpunit/phpunit:5.0.3

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - php -r "file_exists('.env') || copy('.env.example', '.env');"
          - composer install
          - php artisan key:generate
          - phpunit

Next step is database testing.

@Paul van Hemmen and @James Fairhurst I'm trying to do the same thing as you guys, but can't find a lot of documentation to help a newb out. I have a Laravel 5.1 app in Bitbucket and would love to use Pipelines to push it out to my Beanstalk instance. Can you guys provide a bit more detail or resources to try and get this working? Thank you!

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,025 views 1 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you