Bitbucket - pipeline setup

Please don’t you know how to set up the correct pipeline for PHPCAKE v5 on https://bitbucket.org/?
File in root: bitbucket-pipelines.yml

image: php:8.1

pipelines:
  branches:
    master:
      - step:
          name: Build
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install
            - cp .env.example .env
            - docker run --name my-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:10.5
            - sleep 10 # Allow MariaDB to start
      - step:
          name: Create Tables
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip mysql-client
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install
            - mysql -h your_database_host -u my-mariadb -p my-secret-pw db_test < .install/db_test.sql
      - step:
          name: Tests
          caches:
            - composer
          script:
            - composer run-script stan
            - composer run-script test
            - composer run-script cs-check

Thank You

This works fine for me

image: mycustomdocker.domain/pipeline-8.2

pipelines:
  default:
    - parallel:
      - step:
          name: Test
          script:
             - export COMPOSER_ALLOW_SUPERUSER=1
             - composer install --no-progress --no-suggest --prefer-dist --no-interaction
             - cp config/app_pipeline.php config/app_local.php
             - npm i
             - composer test
             - composer psalm # psalm needs a proper DB connection
          caches:
            - composer
          services:
            - mariadb
      - step:
          name: CS & Stan
          script:
              - export COMPOSER_ALLOW_SUPERUSER=1
              - composer install --no-progress --no-suggest --prefer-dist --no-interaction
              - composer cs-check
              - composer stan
          caches:
              - composer

definitions:
  services:
    mariadb:
      image: mariadb:10.11
      environment:
        MARIADB_DATABASE: 'bitbucket_db'
        MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
        MARIADB_USER: 'bitbucket_user'
        MARIADB_PASSWORD: 'bitbucket_pw'

mycustomdocker.domain/pipeline-8.2 is of course a custom image of mine which has composer, NodeJS etc. preisntalled but the base php 8.1 should work as well.

Why do you do a docker run inside a step… this is not needed since the DB service can just be defined as you can see in my example above.

My config/app_pipeline.php looks like this

use Cake\Database\Connection;
use Cake\Database\Driver\Mysql;

return [
    'debug' => true,
    'Error' => [
        'errorLevel' => E_ALL,
    ],

    'is_production' => false,
    'is_pipeline' => true,

    'Security' => [
        'salt' => 'a-valid-salt-key',
    ],

    'Datasources' => [
        'default' => [
            'className' => Connection::class,
            'driver' => Mysql::class,
            'persistent' => false,
            'host' => '127.0.0.1',
            'username' => 'bitbucket_user',
            'password' => 'bitbucket_pw',
            'database' => 'bitbucket_db',
            'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'flags' => [],
            'cacheMetadata' => true,
            'log' => true,
            'quoteIdentifiers' => false,
        ],

        'test' => [
            'className' => Connection::class,
            'driver' => Mysql::class,
            'persistent' => false,
            'host' => '127.0.0.1',
            'username' => 'bitbucket_user',
            'password' => 'bitbucket_pw',
            'database' => 'bitbucket_db',
            'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
            'quoteIdentifiers' => false,
            'log' => false,
        ],
    ],

    'my_custom_config_values' => [
        // whatever you need as a custom config to be set in the pipeline run
    ],
];

As you can see I have added a is_pipeline config value so I can change stuff arround in my app if a pipeline run is being done.

1 Like

Thank You… And how create tables in the test database?

I just use the migrator via the tests/bootstrap.php

But you can use a SQL file as well as you can see here

1 Like