/php-todo

Primary LanguagePHPMIT LicenseMIT

Laravel Quickstart - Basic

Quick Installation

git clone https://github.com/laravel/quickstart-basic quickstart

cd quickstart

composer install

php artisan migrate

php artisan serve

Complete Tutorial

CI Pipeline for TODO application

  • The deployment of the application was carried out from Artifactory.

STEPS

  • Install Artifactory on the artifactory server
sudo apt-get install gnupg2 -y
wget -qO - https://api.bintray.com/orgs/jfrog/keys/gpg/public.key |sudo apt-key add -
sudo echo "deb https://jfrog.bintray.com/artifactory-debs bionic main" | sudo tee /etc/apt/sources.list.d/jfrog.list
sudo apt update -y
sudo apt install jfrog-artifactory-oss -y
sudo systemctl start artifactory
sudo systemctl enable artifactory

project-14-artifactory-install-edit

  • On the Jenkins server, Install PHP, its dependencies and Composer tool sudo yum install -y zip phploc php-{xml,bcmath,bz2,intl,gd,mbstring,mysqlnd,zip}

  • Install and configure Jenkins plugins (Plot, Artifactory) project-14-jfrog-artifactory-plugin

  • In artifactory ui, create a repository that has the same name as your “target” in your jenkinsfile (under the Artifact deployment stage). In this case, it is php-todo Jenkinsfile

  • Create the necessary database requirements and edit the .env.sample file

  • Update the Jenkins file to include Unit tests step Jenkinsfile

Next, setup code coverage report on the jenkins server.

  1. run php --ini to see loaded modules and php config files.

  2. from 1, try to find the xdebug file among the outputs, if its not there an install should be made (sudo yum/apt install php-xdebug)

  3. run php --ini again and this time the xdebug file should be among the list of files.

  4. edit the xdebug file in the output (run php --ini | grep xdebug) to locate the file.

To edit, find the commented line (;xdebug.mode = develop) and change it to (xdebug.mode = coverage). The file also says something about passing a global environment variable XDEBUG_MODE to bypass the default one set in the file, so you may use this method also.

  1. restart php (sudo systemctl restart php-fpm)
  • run the job project-14-execute-unit-tests-edit

  • add the code quality analytics stage to the pipeline and run it phploc-output

  • Package the artifact and deploy to artifactory server

  • Next, deploy to dev environment and configure sonarqube server (see sonarqube role)

  • Install the sonar plugin on Jenkins UI. Configure sonarqube and Jenkins for quality gates sonarqube-servers sonar-scanner

  • edit the sonar.properties file located in /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQubeScanner/conf/

#sonar.sourceEncoding=UTF-8

sonar.host.url=http://3.135.221.18:9000 # replace url here
sonar.projectKey=php-todo
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
sonar.php.exclusions=**/vendor/**
sonar.php.coverage.reportPaths=build/logs/clover.xml
sonar.php.tests.reportPath=build/logs/junit.xml
  • Update the jenkins pipeline to include sonarqube scanning stage project-14-sonar-report

  • Add conditional deployment to higher environment stages in the jenkins pipeline project-14-sonar-bypass

  • Add 2 more servers to be used as Jenkins slave. Configure Jenkins to run its pipeline jobs randomly on any available slave nodes.

  1. Under the managed jenkins, add nodes. In the node configuration section, provide necessary details.
  2. Also provide the private key of the node (jenkins will use it to connect). Make sure the java-jdk is installed on the slave(s). adding-nodes master-slave
  • Configure webhook between Jenkins and Github to automatically run the pipeline when there is a code push.
  1. Install multibranch scan webhook trigger in manage plugins
  2. Edit the scan repository triggers section of the multibranch pipeline. Also check the info and copy the syntax for the webhook( JENKINS_URL/multibranch-webhook-trigger/invoke?token=[Trigger token]). Replace accordingly (e.g; http://x.x.x.x:8080/multibranch-webhook-trigger/invoke?token=ci-jaasp-token-value)

github-webhook

  1. Deploy application to remaining environments

Inspired By:

🤗