A Composer plugin development environment07 Feb 2017
So sometimes people ask me, how I develop and test a plugin or a Composer script. So I released a small development environment powered by Docker and Docker-Compose which you can use to develop your own Composer extension.
With this “dev-env” you don’t make your local Composer environment dirty and you don’t need another local bare Git repository and move some Git tags around.
The only requirement is to have minimal familiarity with Docker and Docker-Compose.
How it works
The repository contains two containers. One for Composer and one for the plugin. Both based on Alpine Linux and including PHP 7.1 over CLI. So they are really small and use minimal disk space. You can find every Docker image in the appropriate directory.
I also added a dummy plugin to see the process directly in action. So after you checked out the repository via Git and built the containers via
you can install your new (or the dummy) plugin via:
docker-compose run --rm composer global require my/new-plugin
The composer container depends on the plugin container. The sources of your plugin are always symlinked to the Composer container. I used the path type as repository option to register the plugin to Composer, so you instantly see changes by every command call.
So if you want to see the new dummy Composer CLI command, run:
docker-composer run --rm composer new-plugin:sample
Notes and options
Of course you can change the PHP version which is used in the Docker containers.
You can also extend the Dockerfile for the plugin. Maybe to install PHPUnit or an other testing framework. So you can run a command like this:
docker-composer run --rm plugin vendor/bin/phpunit
I hope this helps other developers to create a new Composer extension.
If you have questions or some additions, please leave a comment below.