Automatic Deployment of a Laravel Application with Buddy.works
I guess we all know Laravel Forge and Laravel Envoyer, which is probably the best combination of hosting and deploying Laravel applications.
However, maybe you don't use Laravel Forge because you have your own dedicated server on which you host several Laravel apps. And also, you need to only deploy your Laravel app when all tests are green, and that should be done automatically on any commit.
Laravel Envoyer doesn't run your tests, unfortunately, so you can't fully automate a deployment on any commit.
This is where https://app.buddy.works comes into action ! And best thing is, it has a free plan (as long as you don't setup more than 5 projects).
I assume the following:
- Your project as at least one Test.
- You use a database
- The project is already setup and linked to a git repository on your server
- You can ssh into your server with an ssh key.
Ok ! If that's what your looking here's the detail of my deployment plan :
PHPUnit Step Setup
In the "Run Commands" section, copy paste theses lines :
# Prepare .env file cp .env.example .env sed -i "s/127.0.0.1/mysql/g" .env sed -i "s/DB_USERNAME=homestead/DB_USERNAME=root/g" .env sed -i "s/DB_PASSWORD=secret/DB_PASSWORD=qwerty/g" .env # Install Composer curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer # Setup Database echo "create database homestead" | mysql --host=mysql --user=root --password=qwerty # Run Laravel commands composer install php artisan key:generate php artisan migrate php artisan db:seed ./vendor/bin/phpunit
I assume your .env.example file in your project look like this
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
In the Configuration > Environment section, you need to use this docker image
The Package Setup section :
And in the "Services" section, you simply need to add a Mysql Service and that's it :)
The SSH - Deployment Step
The End !
The Slack step is actually so easy that you don't need screenshots :)