The way almost everyone I know does it is creates a CICD-ready .env-like file but calls it .env.cicd or something similar with their dev/testing keys in it and then in one step of the pipeline, they copy/rename .env.cicd to .env.
This is my .gitlab-ci.yml which includes that step:
stages:
- preparation
- building
- testing
- security
- deployment
# Variables
variables:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: mysql_user
MYSQL_PASSWORD: mysql_password
MYSQL_DATABASE: mysql_db
DB_HOST: mysql
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
composer:
stage: preparation
image: edbizarro/gitlab-ci-pipeline-php:7.4
script:
- php -v
- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- cp .env.cicd .env
- php artisan key:generate
artifacts:
paths:
- vendor/
- .env
expire_in: 1 days
when: always
cache:
paths:
- vendor/
yarn:
stage: preparation
image: edbizarro/gitlab-ci-pipeline-php:7.4
script:
- yarn --version
- yarn install --pure-lockfile
artifacts:
paths:
- node_modules/
expire_in: 1 days
when: always
cache:
paths:
- node_modules/
build-assets:
stage: building
image: edbizarro/gitlab-ci-pipeline-php:7.4
# Download the artifacts for these jobs
dependencies:
- composer
- yarn
script:
- yarn --version
- yarn run production --progress false
artifacts:
paths:
- public/css/
- public/js/
- public/fonts/
- public/mix-manifest.json
expire_in: 1 days
when: always
phpunit:
stage: testing
services:
- mysql:5.7
image: edbizarro/gitlab-ci-pipeline-php:7.4
# Download the artifacts for these jobs
dependencies:
- build-assets
- composer
script:
- php -v
- sudo cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.bak
- echo "" | sudo tee /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- php artisan migrate
- php artisan passport:install
- ./vendor/phpunit/phpunit/phpunit --version
- phpdbg -qrr ./vendor/phpunit/phpunit/phpunit -v --colors=never --stderr --coverage-clover=coverage.xml
- sudo cp /usr/local/etc/php/conf.d/docker-php-ext-xdebug.bak /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- export CODECOV_TOKEN="MY CODECOV TOKEN - YOU SHOULD GET YOUR OWN"
- bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'
artifacts:
paths:
- ./storage/logs # for debugging
expire_in: 1 days
when: on_failure
phpcpd:
stage: testing
image: edbizarro/gitlab-ci-pipeline-php:7.4
script:
- test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar
- php phpcpd.phar app/ --min-lines=50
dependencies: []
cache:
paths:
- phpcpd.phar
sensiolabs:
stage: security
image: edbizarro/gitlab-ci-pipeline-php:7.4
script:
- test -d security-checker || git clone https://github.com/sensiolabs/security-checker.git
- cd security-checker
- composer install
- php security-checker security:check ../composer.lock
dependencies: []
cache:
paths:
- security-checker/