4. Install an application using Flavours#
There are various ways to add packages to PHP applications. You are probably used to using Composer, and adding
dependencies to the
composer.json file. You can try that now with a dependency you’re already familiar with.
First, add the dependency. Then, test that it is installed as expected by running:
If you commit and push your changes once again as you did in the previous section, the application will be rebuilt with the new dependency when the cloud environment is redeployed.
4.1. Introducing Flavours#
However, this application is managed using Flavours, which gives us an additional way of working. Flavours is a platform-independent specification for building containerised web applications; the Flavours addon manager for PHP Laravel - flavour/fam-php-laravel - knows how to add a package to a Laravel application.
We will add the laravel-responsecache package. It’s an open-source addon, released by the Belgian agency Spatie, and can improve performance of Laravel sites by caching responses.
4.2. Install the Flavours CLI#
The Flavours CLI is an open-source package, published at GitHub.
npm install -g @flavour/cli
4.3. Run the
flavour add command#
flavour add command, as follows:
➜ flavour add composer/spatie/laravel-responsecache:6.1.1 ❯ Installing composer/spatie/laravel-responsecache:6.1.1 ✔ Getting metadata ✔ Checking validity ✔ Adding requirement ✔ Installed composer/spatie/laravel-responsecache:6.1.1
laravel-responsecache is now installed in the application.
4.3.1. About the command#
The command breaks down thus:
flavour add composer/spatie/laravel-responsecache:6.1.1 command action namespace/addon name :version number
The Flavours CLI looks up the open Flavours registry at https://addons.flavours.dev, and finds the particular version there, and pulls down the YAML data it contains.
The CLI uses the information provided about the addon to identify the appropriate addon manager, which processes the YAML and performs the steps required by the add action.
4.4. Check what the command has done to the application#
In this case, the addon manager will apply some changes to the application. You can see what they are by running
app.flavour, which includes Flavours description of the application, you’ll find in the
'composer/spatie/laravel-responsecache:6.1.1': manager: 'flavour/fam-php-laravel:0.1.1' hash: 9c5f4b2311089d4c5b0def4a0ded5bd927ddd8936d7db18da4cb84283e3413d1
app.flavour is in essence what makes a application Flavours-aware.
And on the application’s
require section, the addon is listed as a component of the application,
so that when the application is built, the addon will be installed:
Finally, if it wasn’t there already, you will find a
.flavour directory, which contains information about the addon
and some configuration for it.
Rebuild the application:
docker-compose build web
When you start the application again with
docker-compose up it will now be running with
installed and activated.
4.5. Deploy to the Cloud#
To deploy your changes to the Test server, push your changes, and run a deployment command:
git add composer.json app.flavour .flavour git commit -m "Added laravel-responsecache" git push origin <branch-name> divio app deploy test
Divio’s hosting service is Flavours-aware; your changes, once pushed and deployed on the Control Panel, will
automatically use the
composer.json file to rebuild the application with the new package installed.
4.6. Explore configuration#
As a Flavours-aware host, the Divio Control Panel recognises the newly installed package. In the application’s Addons view in the Dashboard, you will see it listed along with its version number and configuration options:
From its options menu, select Configure. You will be presented with a pane of default options (some of which you can edit). These defaults were contained in the addon’s YAML. If you hit Save, your options will be applied as environment variables (you can see them in the Env Variables view).
When next deployed, those variables will be applied.
4.7. Where to go next?#
This completes the basic cycle of application creation, development and deployment; you should now be familiar with the fundamental concepts and tools involved.
Other sections of the documentation expand upon them. The how-to guides in particular cover many common operations. And if there’s something you’re looking for but can’t find, please contact Divio support.