├── .gitlab-ci.yml ├── README.md └── pipeline.png /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - preparation 3 | - building 4 | - testing 5 | - security 6 | 7 | image: edbizarro/gitlab-ci-pipeline-php:7.3 8 | 9 | # Variables 10 | variables: 11 | MYSQL_ROOT_PASSWORD: root 12 | MYSQL_USER: mysql_user 13 | MYSQL_PASSWORD: mysql_password 14 | MYSQL_DATABASE: mysql_db 15 | DB_HOST: mysql 16 | 17 | cache: 18 | key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" 19 | 20 | composer: 21 | stage: preparation 22 | script: 23 | - php -v 24 | - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts 25 | - cp .env.example .env 26 | - php artisan key:generate 27 | artifacts: 28 | paths: 29 | - vendor/ 30 | - .env 31 | expire_in: 1 days 32 | when: always 33 | cache: 34 | paths: 35 | - vendor/ 36 | 37 | yarn: 38 | stage: preparation 39 | script: 40 | - yarn --version 41 | - yarn install --pure-lockfile 42 | artifacts: 43 | paths: 44 | - node_modules/ 45 | expire_in: 1 days 46 | when: always 47 | cache: 48 | paths: 49 | - node_modules/ 50 | 51 | build-assets: 52 | stage: building 53 | # Download the artifacts for these jobs 54 | dependencies: 55 | - composer 56 | - yarn 57 | script: 58 | - yarn --version 59 | - yarn run production --progress false 60 | artifacts: 61 | paths: 62 | - public/css/ 63 | - public/js/ 64 | - public/fonts/ 65 | - public/mix-manifest.json 66 | expire_in: 1 days 67 | when: always 68 | 69 | db-seeding: 70 | stage: building 71 | services: 72 | - name: mysql:8.0 73 | command: ["--default-authentication-plugin=mysql_native_password"] 74 | # Download the artifacts for these jobs 75 | dependencies: 76 | - composer 77 | - yarn 78 | script: 79 | - mysql --version 80 | - php artisan migrate:fresh --seed 81 | - mysqldump --host="${DB_HOST}" --user="${MYSQL_USER}" --password="${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" > db.sql 82 | artifacts: 83 | paths: 84 | - storage/logs # for debugging 85 | - db.sql 86 | expire_in: 1 days 87 | when: always 88 | 89 | phpunit: 90 | stage: testing 91 | services: 92 | - name: mysql:8.0 93 | command: ["--default-authentication-plugin=mysql_native_password"] 94 | # Download the artifacts for these jobs 95 | dependencies: 96 | - build-assets 97 | - composer 98 | - db-seeding 99 | script: 100 | - php -v 101 | - sudo cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.bak 102 | - echo "" | sudo tee /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 103 | - mysql --host="${DB_HOST}" --user="${MYSQL_USER}" --password="${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" < db.sql 104 | - ./vendor/phpunit/phpunit/phpunit --version 105 | - php -d short_open_tag=off ./vendor/phpunit/phpunit/phpunit -v --colors=never --stderr 106 | - sudo cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.bak /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 107 | artifacts: 108 | paths: 109 | - ./storage/logs # for debugging 110 | expire_in: 1 days 111 | when: on_failure 112 | 113 | codestyle: 114 | stage: testing 115 | image: lorisleiva/laravel-docker 116 | script: 117 | - phpcs --extensions=php app 118 | dependencies: [] 119 | 120 | phpcpd: 121 | stage: testing 122 | script: 123 | - test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar 124 | - php phpcpd.phar app/ --min-lines=50 125 | dependencies: [] 126 | cache: 127 | paths: 128 | - phpcpd.phar 129 | 130 | sensiolabs: 131 | stage: security 132 | script: 133 | - test -d security-checker || git clone https://github.com/sensiolabs/security-checker.git 134 | - cd security-checker 135 | - composer install 136 | - php security-checker security:check ../composer.lock 137 | dependencies: [] 138 | cache: 139 | paths: 140 | - security-checker/ 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Gitlab CI pipeline for Laravel applications 2 | 3 | This repository features an (opinionated) pipeline (the `.gitlab-ci.yml` file) you can use with Gitlab. 4 | 5 | ![pipeline](https://raw.githubusercontent.com/ohdearapp/gitlab-ci-pipeline-for-laravel/master/pipeline.png) 6 | 7 | For more information on how to use this, please have a look at [the Oh Dear! blogpost](https://ohdear.app/blog/our-gitlab-ci-pipeline-for-laravel-applications). 8 | -------------------------------------------------------------------------------- /pipeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ohdearapp/gitlab-ci-pipeline-for-laravel/8c5b5100606eb33a880e4b6bee36f29abe128168/pipeline.png --------------------------------------------------------------------------------