The Tools – Part One

Ok ok its been a while. Let’s talk about the tools.

The IDE

I’ll be using vscode. I’ve been playing with it in the background and honestly really love it. The plugins I use are Laravel Blade Snippets, Laravel Blade Spacer, and PHP Intelephense.

Just a quick word about PHP Intelephense, its honestly the best PHP intellisense plugin I’ve found. There is another one called PHP Intellisense but in my experience it didn’t work as well.

The Testing Environment

Vagrant. Vagrant. Vagrant.

Honestly, I’ve not found anything anywhere as good as a Homestead box in Vagrant. The ease of provisioning, bringing up and powering down, and general management / portability of machines is incredible.

Code Repo

BitBucket offers some great things for free (including pipelines, dived in to below). The best one is unlimited free private repositories that are very powerful and Sourcetree is just… great.

Pipelines

BitBucket Pipelines are incredible. Automated… anything upon pushing to a branch is amazing for testing and running further things.

For example, here’s the pipelines configuration I have at the moment.

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN 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: amelia/php:7.2

pipelines:

  branches:
    master:
      - step:
          caches:
            - composer
          script:
            - apk --update add unzip curl
            - composer install --prefer-dist
            - vendor/bin/phpunit
            - curl --request POST --url DOCKER_HUB_URL --data '{"docker_tag":"stable"}'
    dev:
      - step:
          caches:
            - composer
          script:
            - apk --update add unzip curl
            - composer install
            - vendor/bin/phpunit
            - curl --request POST --url DOCKER_HUB_URL --data '{"docker_tag":"latest"}'

Let’s go through section by section.

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN 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: amelia/php:7.2

Here we can see I forgot to remove the bitbucket comments. Who cares.

Just under that is the Docker image that will be used to build this testing environment. Shout out to Amelia here for providing a really nicely ready-to-go PHP image with tagging to stick to a specific version.

I stick to PHP 7.2 as that’s what I test in. I can up to 7.3 etc. as and when needed when I’ve done enough testing within my Vagrant box.

After that is just the pipelines: definition line. Under that we have my configuration for the two branches. The two branches I have are master and dev. All day-to-day development happens on dev (which has the Docker Hub tag of latest) and there are periodic pull requests in to master (which has the Docker Hub tag of stable) to catch that up when ready. Now for the next section!

branches:
    master:
      - step:
          caches:
            - composer
          script:
            - apk --update add unzip curl
            - composer install --prefer-dist
            - vendor/bin/phpunit
            - curl --request POST --url DOCKER_HUB_URK --data '{"docker_tag":"stable"}'

Branches is just the heading for this config tree (I don’t do YAML often so this is what I’m calling it). The first one we’re going to hit up is master.

Everything is done in one step because multiple steps was more than I’m comfortable with pipelines configuration at this moment in time. First up, the caches

caches:
            - composer

Honestly, this is unused and is left over because of me leaving it in from the example. Ah well. It’ll be there when I want it in the future!

script:
            - apk --update add unzip curl

This installs unzip and curl as required for the later on operations. These aren’t in the base Docker image so are installed. Yay!

- composer install --prefer-dist

Here we run the composer installation. The zip module is required by some composer packages I use and we use prefer-dist to avoid any debug / dev versions leaking in to live.

- vendor/bin/phpunit

Run the PHPUnit tests. If there are any failures reported Pipelines will pick this up and declare the run as a failure and report this to a slack channel I have set up.

After this is done then everything is ready to go and has been verified as tested. From here I have one final call to Docker Hub to kick off the Docker image build

- curl --request POST --url DOCKER_HUB_URL --data '{"docker_tag":"stable"}'

The reason for this is that I’m currently on the free Docker Hub plan meaning I have a very limited number of simultaneous builds. When I’m developing I believe strongly in the “commit and push frequent smaller changes rather than fewer large changes”. This can lead to many stacking up over time and I don’t want any that fail the automated testing to be in this queue.

For the dev branch its much the same except not using dist packages for composer because its dev and I don’t care #yeahboy.

Honestly this post got very long very fast so I’m going to call it a day here and will follow up with part two eventually.

Peace,

-L

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.