Integrate Blackfire in your CircleCI pipelines

By Jérôme Vieilledent, on Mar 30, 2020

Since the time we launched the first version of Blackfire Profiler, our focus has been on making web applications run better and faster. As Blackfire evolves, one of our next steps has been native integrations with other products in the DevOps toolchain, such as CI/CD software and services.

We’re very proud to announce the integration and partnership between Blackfire with CircleCI!

The CircleCI teams are pioneers in efficient software delivery for organizations. They have been committed to their mission of helping the world’s best software organizations improve the way they build, test, and deploy software.

Blackfire is now a certified CircleCI Technology Partner. With the general availability of the Blackfire orbs for CircleCI, it is now possible for developers to control code performance throughout their CircleCI pipelines. From the start of development, and right into production, the Blackfire orbs will help you capture all performance and behavior related information from your applications.

So, what can you do with the Blackfire orbs?

First they ease the Blackfire install setup within your CircleCI containers:

version: 2.1

orbs:
    blackfire: blackfireio/php@1.1

jobs:
    build:
        docker:
            - image: circleci/php:7.4-fpm-node

        steps:
            - checkout

            - blackfire/setup

            - run:
                name: Tests
                environment:
                    APP_DEBUG: 0
                command: php bin/phpunit

Et voilà! Everything is now installed within your primary container! The PHP probe is installed, the agent is running, and you have access to blackfire and blackfire-player commands.

Second, you have the ability to trigger web-hooks, which can be very useful after a deploy in staging or production environments:

version: 2.1

orbs:
    blackfire: blackfireio/php@1.1
    blackfire-agent: blackfireio/agent@1.1

jobs:
    blackfire-build-example:
        docker:
            - image: circleci/php:7.4-fpm-node
        steps:
            - checkout
            - blackfire/setup
            - blackfire-agent/build-trigger:
                endpoint: "https://staging.my-webapp.tld/"
                # Blackfire Environment name or UUID
                # Can be only a part of the environment name, 
                # as long as it is not ambiguous.
                environment: My Blackfire Environment Name

Last but not least, you can run Blackfire Player scenarios using the Blackfire profiler integration:

version: 2.1

orbs:
    blackfire: blackfireio/php@1.1
    blackfire-player: blackfireio/player@1.0

blackfire_player:
    docker:
        - image: circleci/php:7.4-fpm-node
    steps:
        - checkout
        - blackfire-player/run-scenario:
              # Assuming scenario.bkf is at the root of your codebase.
              scenario: scenario.bkf
              # Can be only a part of the environment name, 
              # as long as it is not ambiguous.
              environment-name: MyEnvironmentName
              endpoint: "https://myendpoint.tld"
              variables: "variable_name1=value1,variable_name2=value2,foo=bar"

To run multiple scenarios, make sure to use the load instruction in your BKF file.

Want a little candy before getting back to work?

Here is how you can run Blackfire Player scenarios directly from your CircleCI primary container, with the help of Symfony local web server:

version: 2.1

orbs:
    blackfire: blackfireio/php@1.1
    blackfire-player: blackfireio/player@1.0

blackfire_player:
    docker:
        - image: circleci/php:7.4-fpm-node
    steps:
        - checkout
        - run: composer install -n --prefer-dist
        - run:
              name: "Install & run Symfony server"
              environment:
                  # Ensure to run in "prod" Symfony environment
                  APP_ENV: prod
              command: |
                  wget https://get.symfony.com/cli/installer -O - | bash
                  ~/.symfony/bin/symfony local:server:start -d
                  # Now the server is listening to localhost:8000
        - blackfire/setup
        - blackfire-player/run-scenario:
              # Assuming scenario.bkf is at the root of the codebase.
              scenario: scenario.bkf
              environment-name: MyEnvironmentName
              endpoint: "https://localhost:8000"
              variables: "variable_name1=value1,variable_name2=value2,foo=bar"

Happy profiling on CircleCI!

Jérôme Vieilledent

As a Developer Advocate, Jérôme is all about spreading the love! His technical/development background enable him to talk as a peer to peers with our developer users. You’ll read his tips and advices on performance management with Blackfire. And he’ll support you as a day-to-day user.