Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated deployment PHP in CI environment (Jenkins)

Tags:

I'm currently looking into setting up a strong CI & deployment environment for a project shared across a small team of developers. Objective is to bring some consistency in the way things are tested, in the overall code quality and in the way deployments are done.

I've read about Jenkins, Sonar, Maven, Capistrano, Phing, ANT, ... and to be honest I'm getting lost in the middle of all of those tools/technologies and would like you to validate my understanding and to give me some insight on best way to achieve this.

What I've already setup till now:

  • Git: we use git as versioning system and have a branch "development" for all new dev that need to be analysed by the CI tool.
  • Jenkins: Jenkins is triggered by a GIT hook (on the development branch), and will execute a PHING script performing the below actions:

    • Lint: validate PHP code execution, code analyser
    • PHPLoc: get some statistic about PHP code (complexity, depedency..)
    • PDepend: Code analysis (not sure about the difference with PHPLoc)
    • phpmd: mess detector (unused params, complicated code...)
    • phpcpd: detect copy paste code
    • PHPcs: validate coding standards
    • Phpdox: generate PHP documentation
    • Php_Codebrowser: generate a browsable representation of PHP code with highlights of violations...
    • PHPUnit: run PHP tests

    Jenkins is then sending all the reports/data to Sonar unsing a sonnar-runner.

  • Sonar is gathering all those data, storing them in a database which offers a way of analysing the evolution of your application code over time. It also display information in a nicer way than Jenkins does.

Missing blocks

  • Automated deployment to QA: I'd like to automate the deployment to QA env when a build script is successful (based on test success). This should trigger a process of pulling the right data on QA, making the changes to DB, and potential file/folder clean up & permission setups.
  • Automate deployment to PROD: This should do the same as above but based on the master branch. We should also add another round of testing on that PROD env after deployment.

Tools review

  • Git: no need to explain this one, it's all about versioning
  • Jenkins: CI tool, which automates build (code validation + testing)
  • Sonar: Reporting tool (visualize build data over time)
  • Maven: Not sure about this one. Is it the missing piece for the deployment? Or an other reporting tool?
  • Capistrano: deployment tool

Your input :-)

  • Your point on my overall setup for CI (does it make sense, am I using the right tools?)
  • What is from your experience the best tools for deployment?
  • As Jenkins is kind of the "dispatcher" in this overall CI/Deployment schema is it the one triggering the deployment also? If yes I assume it is possible to trigger some actions based on build status (success/failure)?

Thanks a lot for your time and help!

like image 559
LEM01 Avatar asked Mar 11 '14 09:03

LEM01


People also ask

Is automatic deployment possible in Jenkins?

Jenkins is really popular for CI (build automation), as well as for general purpose automation. As such, it seems a natural fit to use Jenkins's automation capabilities to deploy the software you built.


1 Answers

Looks good overall. I haven't personally used Sonar (but aware of it) or Capistrano (never even heard of this one), so can't comment on those.

Maven is a dependency, build and deployment tool, mainly for Java projects. You are already taking care of the "build" with Jenkins, so don't worry about Maven.

As for deployment, I wrote a very detailed explanation here how to deploy Jenkins builds. Jenkins is fully capable of doing your deployment, so why bother looking to add another tool into the mix? The only thing you need is a bash (or batch, depending on your environment) script to take your PHP files (I advise to zip them up as part of the build job) and copy/deploy them on the remote server.

If you have more specific question, ask away.

like image 180
Slav Avatar answered Oct 31 '22 19:10

Slav