Hi all,
I’m just starting with CI within my PHP (Laravel) projects. I got everything up and running uptille the deployment of the project. To give you an idea of what I’m trying to achieve: Every project has two main braches: master and staging. When something changes in these two branches I want the changes to be pulled to my staging or production server IF the PHPUnit tests were succesful.
I find it hard to find an exact answer to this problem in the GitLab CI deployment, so I hope someone can help me out.
This is my .gitlab-ci.yml:
`image: php:5.6
before_script:
- bash ci/docker_install.sh > /dev/null
- apt-get update
- apt-get install -y unzip
- apt-get install -y php5-xdebug
- apt-get install -y ruby-dev
- apt-get install -y rubygems
- apt-get install -y sshpass
- gem install dpl
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install
staging:
script:
- echo Staging environement.
- php -v
- cp .env.test .env
- php artisan key:generate
- php vendor/bin/phpunit --colors --debug --coverage-text
- dpl --provider=script --script=./ci/deploy_staging.sh
only:
- staging
production:
script:
- echo Production environement.
- php -v
- cp .env.test .env
- php artisan key:generate
- php vendor/bin/phpunit --colors --debug --coverage-text
- dpl --provider=script --script=./ci/deploy_production.sh
- php -v
only:
- master`
Provisioning of the build environement seems to work ok.
Composer gets installed, PHPUnit gets executed etc. This also seems the right way to execute specific code for specific branches (the “only” statement).
I added “dpl” from the examples, but I can’t seem to find a way to get this to work:
- What should the deploy scripts contain (the server should do a git pull and some Laravel actions to set things up);
- The staging/production server have IP restrictions in a hardware firewall, should I add a GitLab IP (and which one?);
- How do I ensure myself the deployment to staging or production only takes place when the PHPUnit run was succesfull?
Thank you for your time and if I can help out with any extra details, please let me know.