Local Development Tooling
Posted: 20th Mar 2021
As a platform , Servd has always tried to remain indifferent to the local development tools that you choose to use. We know several of our clients are using docker, nitro, Homestead, MAMP and everything in between. We want to keep it this way - your hosting environment shouldn't dictate the software you use on your local machine.
But we also want to make things as easy as possible for you when you're working outside of Servd. So we're happy to share a new set of local development features which should significantly improve your local dev experience when working on Servd projects.
How To Get Them
90% of the projects running on Servd make use of the Servd Assets and Helpers Plugin already. So this is our preferred method of sharing additional functionality with our users. In order to get access to the new local development helpers, simply update the plugin to version 2.2 or above, or install it if you haven't already been using it.
composer update servd/craft-assets-storage composer require servd/craft-assets-storage
Local Asset Volumes
Most of us are aware of the benefits of using cloud object storage for uploaded assets on a Craft site, but they also have their downsides. Two of the most common are:
- Reduced testing speed when working with a large number of assets
- Difficulty organising assets when working on a multi-developer team
Previously there hasn't been a good way to handle these issues which didn't require the use of a custom module and very diligent handling of project config files.
Now, it's possible with just the flick of a switch:
You can find this new setting in the Servd Plugin's main settings screen.
Once activated all of your Servd Asset Volumes will become local filesystem volumes, but only when your project is running outside of Servd. The plugin also ensures that this temporary change in configuration doesn't leak into your database or project config files, so no need to worry about accidentally converting your live site's volumes.
The plugin will manage all of the settings for your stand-in local volumes, by setting their root path to:
And their base URL to:
If you use this feature, ensure you add the servd-volumes folder to your .gitignore file.
Making sure your assets are in sync between environments can be a chore and many developers end up using third party scripts like Andrew Welch's Craft Scripts, which require configuration and direct access to your project's servers.
The Servd Plugin can now handle this for you, with no additional configuration required.
With the following two commands you can sync your local assets with either your staging or production environment on Servd.
./craft servd-asset-storage/local/pull-assets ./craft servd-asset-storage/local/push-assets
These commands will work whether you have the 'Use Local Volumes During Dev' setting enabled or not.
If you do, the script will push/pull the assets which are stored on your local filesystem.
If you don't, the script will push/pull the assets which are stored in the 'local' folder on the Servd Asset Platform.
These functions are also clever enough to only upload or download files which are actually different between the environments that you're syncing. So feel free to re-sync even if you're on a slow internet connection as only new files will be downloaded.
What good would synced up assets be if you couldn't also sync the database data?
Pulling the production or staging database down to your local environment is now as easy as executing a single CLI command. When you do, the plugin will ensure your database is able to be connected to from the outside world, then it'll perform a streaming import (or export in the case or a database push) in order to get you synced up in the smallest amount of time possible.
After the sync is complete the plugin will even clean up after itself and close off the external database connectivity if it was already closed to begin with.
These are the commands you need to give that a try:
./craft servd-asset-storage/local/pull-database ./craft servd-asset-storage/local/push-database
All of these commands accept several flags which allow you to skip the prompts that will otherwise appear. You can use the CLI's help command, or review the plugin's README to find them.
We're really hopeful that these new tools will help you to become more productive when using Servd for your projects. We'll be adding to this local dev functionality over time so make sure you keep your plugins updated so that you can benefit.
Soon, we'll also be releasing some docker containers which mimic the Servd production environment so that you can test locally with an environment which matches Servd as closely as possible. Hopefully with some integration with Nitro, but no promises on that yet 🙂