Today, I’ll talk about how to automate your Laravel Application to be deployed with Docker by CI/CD - Jenkins on Github PR merges.
Laravel is a popular PHP web application framework, and Docker is a platform that simplifies application deployment using containers. Combining these two technologies with Jenkins can create a powerful CI/CD pipeline. In this mini-tutorial, we will guide you through setting up a Jenkins job that deploys your Laravel application with Docker whenever a pull request (PR) is merged into your Git repository.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $200 of credit to try our products over 60 days!
In this mini-tutorial, I’ll assume you have a Laravel Application and Jenkins server configured however if you don’t have anything, I’ll recommend checking our MarketPlace for a Laravel ready Droplet:
Additionally, if you want to have your Database Managed, you can check the following:
For Jenkins, you can follow this tutorial:
Lastly, to configure Docker if needed, you can follow this tutorial:
Configure Jenkins Job
Navigate to the Jenkins dashboard and create a new job. Choose “Pipeline” and provide a unique name for the job.
Navigate to the “Pipeline” section and select “Pipeline script from SCM” in the “Definition” field. Choose “Git” as your SCM and provide your repository URL and credentials as needed.
To trigger the build on PR merge commits, you can use the “GitHub hook trigger for GITScm polling” option. First, install the “GitHub Integration” plugin in Jenkins, then navigate to the “Build Triggers” section and check the “GitHub hook trigger for GITScm polling” box.
Next, configure a webhook in your GitHub repository. In your repository settings, go to “Webhooks” and click on “Add webhook.” Set the “Payload URL” to
http://your-jenkins-url/github-webhook/and select “Let me select individual events.” Check the “Pull requests” event and save the webhook.
Write the Jenkins Pipeline Script
In the “Pipeline” section, add the following Groovy script to the “Script Path” field:
This script defines a pipeline with the following stages:
docker-composeto recreate the services.
Make sure to replace the placeholders (e.g.,
your-deployment-server) with your own values.
Test the Pipeline
Create a pull request and merge it in your Git repository. The Jenkins job should trigger automatically and execute the pipeline, deploying your Laravel application using Docker.
You have now successfully created a Jenkins job that deploys your Laravel application with Docker on Git PR merge commits. With this CI/CD pipeline, your development team can streamline the deployment process and ensure that your application stays up-to-date with the latest changes.