I thought I'd share another Envoyer goodie for you - How to use Codeship's continuous integration (CI) testing capabilities to trigger deployment via Envoyer.io for a Laravel 5 application. I wrote a similar post last week but with Travis CI. You can find that here.
Envoyer.io is awesome, as are CI tools in general. I've become a particularly big fan of Codeship as I can test private GitHub repositories for free and it completes my tests far quicker than Travis.
The exam question
The big question for myself was "If my tests fully pass the Codeship CI build process, then how I can I get Envoyer.io to deploy my Laravel app automatically?". Turn's out it's massively simple and is one line of a command as opposed to Travis CI.
I used the steps below for my Laravel 5 application. I'll assume you're fully signed up to Codeship and have linked your GitHub or BitBucket repository and are using PHPUnit. I've not tried with Codeception, Behat, PHPSpec etc but I see no reason why they wouldn't work.
Okay, first step is to setup your environment variables. They should be comparable to the environment variables you use for testing locally. However, set your DB_USERNAME and DB_PASSWORD (or whatever you call them) to $MYSQL_USER and $MYSQL_PASSWORD respectively to load the default Codeship values.
The second step is to configure your tests by setting up your commands. For a Laravel 5 app, do this by selecting 'I want to create my own custom commands'. My setup commands are as follows:
# Set php version through phpenv. 5.3, 5.4 and 5.5 available phpenv local 5.5 # Create my testing database mysql -e 'create database testing;' # Install dependencies through Composer composer install --prefer-source --no-interaction # Migrate and seed database using the APP_ENV environment variable of 'testing' php artisan migrate --env="testing" php artisan db:seed --env="testing" # Start the PHP server php artisan serve >/dev/null 2>&1 & # Rename phpunit.xml cp phpunit.xml.ci phpunit.xml
Some points to note on the above - the 'cp phpunit.xml.ci phpunit.xml' tells Codeship to rename a file from a .ci to a .xml. I have a special phpunit.xml file which houses relevant information about my PHPUnit tests. It differs from the phpunit.xml file which I use locally and hence I give it the .ci suffix to ensure that it is not used in local development environments.
# Run PHPUnit tests vendor/bin/phpunit # On success, alert Envoyer.io wget $ENVOYER_URL
It's dead simple. If your build fails, no deployment triggered. If they pass, your Envoyer deployment URL is pinged and your project is deployed. Plus you can get some nice slack notifications from both services to alert you that it's all good in the hood.