To configure the `deploy.yml` file for deploying a Laravel application from Travis CI to Laravel Forge, you can follow these steps:
1. In Forge, create a deployment trigger URL that Travis CI can use to initiate deployments on your server. This trigger URL is found in the "Deployment Trigger" section of your site's settings in Forge.
2. In Travis CI, add the `FORGE_API_TOKEN` environment variable to your build environment. You can generate an API token in the API settings of your Forge account. This allows Travis to authenticate with Forge during deployments.
3. Configure Travis to run your tests and build your Laravel application as usual. If the tests pass, add a deployment step that uses the `forge deploy` command to trigger a deployment on your Forge server using the deployment trigger URL.
Here's an example `deploy.yml` file:
yaml
language: php
php:
- 7.4
before_script:
- cp .env.travis .env
- mysql -e 'create database db_testing;'
- composer self-update
- composer install --no-interaction
- php artisan migrate
script:
- vendor/bin/phpunit
after_success:
- chmod +x ./deploy.sh
- ./deploy.sh
deploy.sh:
#!/bin/bash
# Trigger deployment
curl -s 'https://forge.laravel.com/servers/111111/sites/222222/deploy/http?token=TOKEN'
echo 'Deployment triggered!'
In this example:
- The `before_script` section sets up the environment, installs dependencies, and runs migrations.
- The `script` section runs the PHPUnit tests.
- The `after_success` section is executed if the tests pass successfully. It makes the `deploy.sh` script executable and runs it.
- The `deploy.sh` script uses cURL to send a request to the Forge deployment trigger URL, initiating the deployment process on the Forge server.
Make sure to replace the placeholders `111111`, `222222`, and `TOKEN` with your actual Forge server ID, site ID, and deployment trigger token.
By integrating Travis CI and Laravel Forge, you get the benefits of both tools - Travis handles the continuous integration and testing, while Forge manages the server provisioning and deployment. This allows you to set up a robust, automated CI/CD pipeline for your Laravel projects.
The key is configuring the necessary authentication between the two tools, which involves setting environment variables in Travis and using the deployment trigger URL provided by Forge. With this integration in place, pushing code will automatically trigger a build, test, and deploy process using Travis and Forge.
Citations:[1] https://www.devproblems.com/travis-ci-laravel-forge-webhook-integration/
[2] https://travis-ci.community/t/deploying-to-forge-from-travis-ci/2243
[3] https://www.danielwerner.dev/set-up-cicd-for-your-laravel-app-with-github-travis-and-deployer
[4] https://forge.laravel.com/docs/sites/deployments.html
[5] https://laracasts.com/discuss/channels/forge/deploying-to-forge-from-travis-ci