项目作者: renepardon

项目描述 :
A Gitlab CE runner container to build PHP/JS applications with
高级语言: Dockerfile
项目地址: git://github.com/renepardon/gitlab-php-js-sonar-runner.git
创建时间: 2019-01-17T14:58:58Z
项目社区:https://github.com/renepardon/gitlab-php-js-sonar-runner

开源协议:MIT License

下载


Build

  1. docker build -t renepardon/gitlab-php-js-sonar-runner .
  2. docker login https://index.docker.io/v1
  3. docker push docker.io/renepardon/gitlab-php-js-sonar-runner:latest

Add a Gitlab Runner

  1. docker run -d --name gitlab-runner --restart always -v '/var/run/docker.sock:/var/run/docker.sock' gitlab/gitlab-runner && \
  2. docker exec -it gitlab-runner gitlab-runner register -n --url https://repository.<YOURDOMAIN>.com/ --registration-token <YOURGITLABRUNNERTOKEN> --executor docker --description "gitlab-runner" --docker-image "alpine:latest" --docker-volumes /var/run/docker.sock:/var/run/docker.sock

Usage

.gitlab-ci.yml

This is an example Gitlab CI pipeline configuration for a laravel application which makes use of PHP and Javascript as
well as Sonarqube.

  1. image: renepardon/gitlab-php-js-sonar-runner:latest
  2. cache:
  3. paths:
  4. - vendor/
  5. - node_modules/
  6. stages:
  7. - build
  8. - test
  9. - sonar
  10. - release
  11. variables:
  12. REGISTRY: repository.<YOURDOMAIN>.com:4567
  13. NIGHTLY_IMAGE: $REGISTRY/<YOURCOMPANY>/<YOURPROJECT>:$CI_BUILD_REF
  14. LATEST_IMAGE: $REGISTRY/<YOURCOMPANY>/<YOURPROJECT>:latest
  15. build:
  16. stage: build
  17. before_script:
  18. - docker info
  19. - cp .env.example .env
  20. - sed -i "s/CACHE_DRIVER=.*/CACHE_DRIVER=array/" .env
  21. - sed -i "s/SESSION_DRIVER=.*/SESSION_DRIVER=array/" .env
  22. - php composer.phar install
  23. - php artisan key:generate
  24. - npm install
  25. - npm run prod
  26. script:
  27. - docker login -u jenkins -p <YOURLOGINTOKEN> $REGISTRY
  28. - docker build -t $NIGHTLY_IMAGE -f ./Dockerfile --pull .
  29. - docker push $NIGHTLY_IMAGE
  30. test:7.3:
  31. stage: test
  32. before_script:
  33. - cp .env.example .env
  34. - sed -i "s/CACHE_DRIVER=.*/CACHE_DRIVER=array/" .env
  35. - sed -i "s/SESSION_DRIVER=.*/SESSION_DRIVER=array/" .env
  36. - php composer.phar install
  37. - php artisan key:generate
  38. script:
  39. - ./vendor/bin/phpunit
  40. artifacts:
  41. paths:
  42. - ./build/reports/coverage/
  43. - ./build/reports/unitreport.xml
  44. test:javascript:
  45. stage: test
  46. image: node:8-alpine
  47. before_script:
  48. - npm install
  49. - npm run prod
  50. script:
  51. - npm run test
  52. sonar:
  53. stage: sonar
  54. image: ciricihq/gitlab-sonar-scanner
  55. dependencies:
  56. - test:7.3
  57. variables:
  58. SONAR_URL: https://sonar.<YOURDOMAIN>.com
  59. SONAR_ANALYSIS_MODE: publish
  60. script:
  61. - gitlab-sonar-scanner
  62. release:
  63. stage: release
  64. image: gitlab/dind
  65. script:
  66. - docker login -u jenkins -p <YOURLOGINTOKEN> $REGISTRY
  67. - docker pull $NIGHTLY_IMAGE
  68. - docker tag $NIGHTLY_IMAGE $LATEST_IMAGE
  69. - docker push $LATEST_IMAGE
  70. only:
  71. - master

TODOs

  • replace node:8-alpine with renepardon/gitlab-php-js-sonar-runner:latest
  • replace ciricihq/gitlab-sonar-scanner with renepardon/gitlab-php-js-sonar-runner:latest