I've not used it myself, but pipelines uses docker containers, so you'd just need to use a container that has what you need.. This one probably has most/all of your needs covered: https://hub.docker.com/r/smartapps/bitbucket-pipelines-php-mysql/
Testing with BitBucket Pipelines
Has anyone managed to get a pipeline setup in BitBucket that will automatically install and configure their Laravel application and then run a series of PHPUnit tests against it?
I've had a quick look but from what I can see their support for databases is quite limited and I'm not sure if it's even possible. Would love to see if someone has managed to do this already and what their .yaml file is like.
@AndyDunn for what I saw before.. BitBucket still doesn't support DB :( maybe pushing a sqlite DB on the repository for just test and using that would work?
Hey @AndyDunn, I just setup my bitbucket pipeline to setup my project and run phpunit. Here's the docker image I used https://hub.docker.com/r/smartapps/bitbucket-pipelines-php-mysql/ and here's my yaml config :
image: smartapps/bitbucket-pipelines-php-mysql
pipelines:
default:
- step:
script:
- composer install
branches:
staging:
- step:
script:
- composer install
- service mysql start
- mysql -h localhost -u root -proot -e "CREATE DATABASE test_db"
- php artisan migrate --env=testing
- phpunit -c phpunit.xml
Since bitbucket allows us to use custom docker images, this seems to the best solution so far for supporting custom environments rather than depending upon bitbucket's pre-set docker images.
wow @vijay.rangan !!! that's great!!!
Literally the exact same container I suggested.. :)
We actually went with something very similar except using our own Docker image. It's been working out very well and is great to get a status of our tests on every commit.
# 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: ivanthecrazy/laravel
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- service mysql start
- mysql -uroot -e "DROP DATABASE IF EXISTS idpal; CREATE DATABASE IF NOT EXISTS idpal;"
- cp .env.test .env
- composer install
- php artisan migrate:refresh --seed
- ./vendor/bin/phpunit
Has anyone gotten Dusk tests running with bitbucket pipelines?
@reasondigital you can check this article https://mhdzaherghaibeh.name/2018/02/03/running-laravel-dusk-tests-on-bitbucket-the-easy-way/ which uses this docker image https://github.com/linuxjuggler/php-7.2-dusk-bitbucket-pipelines.
@AndyDunn you can use bitbucket mysql service instead like in this example:
clone: # the 'clone' section
depth: 1 # the depth, in this case the clone will contain last commit
options:
max-time: 10
image: zaherg/php-7.2-xdebug-alpine:latest
pipelines:
branches:
'{master,develop}':
- step:
name: Build and push the image
caches:
- composer
script:
- composer config -g github-oauth.github.com $GITHUB_TOKEN
- composer global require hirak/prestissimo
- composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- cp .env.example .env
- php artisan key:generate
- composer run test
services:
- redis
- mysql
default:
- step:
name: Build and push the image
caches:
- composer
script:
- composer config -g github-oauth.github.com $GITHUB_TOKEN
- composer global require hirak/prestissimo
- composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- cp .env.example .env
- php artisan key:generate
- composer run test
services:
- redis
- mysql
definitions:
services:
redis:
image: redis
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'homestead'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'homestead'
MYSQL_PASSWORD: 'secret'
you can read more about it here https://confluence.atlassian.com/bitbucket/use-services-and-databases-in-bitbucket-pipelines-874786688.html
PS: am using hirak/prestissimo package here to speed up composer install process a bit (more can be explained here https://mhdzaherghaibeh.name/2018/03/04/two-tips-to-speed-up-bitbucket-pipelines/ )
Please or to participate in this conversation.