Branislav Bujisic, product engineer
https://www.youtube.com/watch?v=_-_x7eApZKU
ensure quailty of software,
through frequent and
comprehensive
testing,
while maintaining high productivity
Continuous Integration allows you to integrate the code into a shared repository and build and test each change automatically, as early as possible, usually several times a day.
Source: https://about.gitlab.com/product/continuous-integration
Continuous Delivery ensures that the software can be released to production at any time, often by automatically pushing changes to a staging system.
Source: https://about.gitlab.com/product/continuous-integration
Continuous Deployment takes the process a step further and pushes changes to the production automatically.
Source: https://about.gitlab.com/product/continuous-integration
Source: https://about.gitlab.com/product/continuous-integration
Ubuntu 18.04, 2 cores, 8GB RAM
curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
sudo bash script.deb.sh
sudo apt install gitlab-ce
# /etc/gitlab/gitlab.rb
external_url 'https://example.com'
letsencrypt['contact_emails'] = ['admin@example.com']
sudo gitlab-ctl reconfigure
Source: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-gitlab-on-ubuntu-18-04
Source: https://docs.gitlab.com/runner/
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt-get install gitlab-runner
sudo gitlab-runner register
Source | https://example.com |
---|---|
Token | [the-token-obtained-from-gitlab] |
Description | My Fancy Runner |
Tags | ... |
Executor | docker |
Default Docker image | bbujisic/drupal8-phpunit:1.0 |
Sources:
https://docs.gitlab.com/runner/install/linux-repository.html
https://docs.gitlab.com/runner/register/index.html
docker pull bbujisic/drupal8-phpunit:1.0
.gitlab-ci.yml
image: bbujisic/drupal8-phpunit:1.0
stages:
- test
phpcs:
stage: test
script:
- phpcs --standard=Drupal web/modules/custom web/themes/custom
DDD2019
composer require --dev "jakub-onderka/php-parallel-lint"
./bin/parallel-lint web/modules/custom/
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- pre-deploy-test
parallel-lint:
stage: pre-deploy-test
script:
- parallel-lint web/modules/custom web/themes/custom
# For Drupal developers:
composer global require "drupal/coder"
# For non-Drupal developers:
composer global require "squizlabs/php_codesniffer=*"
phpcs --standard=Drupal web/modules/custom web/themes/custom
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- pre-deploy-test
parallel-lint:
stage: pre-deploy-test
script:
- phpcs --standard=Drupal web/modules/custom web/themes/custom
php -r "readfile('http://get.sensiolabs.org/security-checker.phar');" > /usr/local/bin/security-checker
chmod +x /usr/local/bin/security-checker
security-checker security:check
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- pre-deploy-test
security:
stage: pre-deploy-test
script:
- security-checker security:check
# For Drupal developers:
composer require "phpstan/phpstan"
# For non-Drupal developers:
composer require "mglaman/phpstan-drupal"
# phpstan.neon
includes:
- vendor/mglaman/phpstan-drupal/extension.neon
vendor/bin/phpstan analyse web/modules/custom web/themes/custom
# phpstan.neon
includes:
- %rootDir%/../../mglaman/phpstan-drupal/extension.neon
parameters:
excludes_analyse:
- *Test.php
- *TestBase.php
level: 1
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- pre-deploy-test
phpstan:
stage: pre-deploy-test
script:
- composer install
- phpstan web/modules/custom web/themes/custom
composer global require phpunit/phpunit
phpunit -c phpunit.xml web/modules/custom
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- pre-deploy-test
phpunit:
stage: pre-deploy-test
script:
- composer install
- phpunit web/modules/custom
// composer.json
"require": {
"drupal/drupal-extension": "^3.4",
},
"config": {
"bin-dir": "bin/"
}
composer update
mkdir behat
cd behat
../bin/behat --init
# behat/behat.yaml
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: http://mysite.local
Drupal\DrupalExtension:
blackbox: ~
api_driver: 'drupal'
drush:
alias: 'local'
drupal:
drupal_root: '../web/'
region_map:
footer: "#footer"
# behat/features/hello.feature
@api
Scenario: An anonymous should see the hello page
Given I am an anonymous user
When I go to "hello"
Then I should see "Hello world"
cd behat; behat
# behat/behat.yaml
default:
extensions:
Behat\MinkExtension:
base_url: http://mysite.local
To get the environment URL, run:
platform url --pipe | head -n 1
Then use the BEHAT_PARAMS
environment variable to override parts of the behat.yaml
file.
{"extensions": {
"Behat\\MinkExtension":
{"base_url":"[platform-url]"}
}
}
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- post-deploy-test
behat:
stage: post-deploy-test
script: |
bash scripts/gitlab/setup-cli.sh
platform variable:create \
--name=env:BEHAT_PARAMS \
--value="{\"extensions\":{\"Behat\\\\MinkExtension\":{\"base_url\":\"`platform url --environment=$CI_BUILD_REF_NAME --pipe | head -n 1`\"}}}" \
--level=environment --json=true \
--environment=$CI_BUILD_REF_NAME \
--yes || true
platform ssh "cd behat; behat" -e $CI_BUILD_REF_NAME
Platform.sh solves the problem of staging environments and stakeholder acceptance
$ git push platform my-feature-branch
$ platform environment:activate
$ platform push
stages:
# ...
- deploy
# ...
psh-deploy:
stage: deploy
script:
- mkdir -p $HOME/.ssh
- echo "$SSH_KEY" > $HOME/.ssh/id_rsa
- echo "$SSH_KEY_PUB" > $HOME/.ssh/id_rsa.pub
- echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
- chmod go-r $HOME/.ssh/id_rsa
- platform project:set-remote "$PSH_PROJECT_ID"
- platform push --force --activate --target=$CI_BUILD_REF_NAME
#!/usr/bin/env bash
set -e
# Set up SSH credentials for pushing to external Git repositories, via GitLab CI
# environment variables.
if [ -n "$SSH_KEY" ]; then
mkdir -p $HOME/.ssh
echo "$SSH_KEY" > $HOME/.ssh/id_rsa
echo "$SSH_KEY_PUB" > $HOME/.ssh/id_rsa.pub
chmod go-r $HOME/.ssh/id_rsa
unset SSH_KEY
echo "Created SSH key: .ssh/id_rsa"
fi
# Set up SSH known hosts file.
if [ -n "$SSH_KNOWN_HOSTS" ]; then
mkdir -p $HOME/.ssh
echo "$SSH_KNOWN_HOSTS" > $HOME/.ssh/known_hosts
fi
platform project:set-remote "$PSH_PROJECT_ID"
# .gitlab-ci.yml
image: bbujisic/drupal8-phpunit:latest
stages:
- pre-deploy-test
- deploy-stg
- post-deploy-test
- release
parallel-lint:
stage: pre-deploy-test
script:
- parallel-lint web/modules/custom/ web/themes/custom/
phpcs:
stage: pre-deploy-test
script:
- phpcs --standard=Drupal web/modules/custom web/themes/custom
only:
- branches
except:
- master
.phpstan:
stage: pre-deploy-test
script:
- composer install
- phpstan analyse web/modules/custom/ web/themes/custom/
security:
stage: pre-deploy-test
script:
- security-checker security:check
.phpunit:
stage: pre-deploy-test
script:
- composer install
- phpunit web/modules/custom
deploy-staging:
stage: deploy-stg
script: |
bash scripts/gitlab/setup-cli.sh
platform project:set-remote "$PSH_PROJECT_ID"
platform push \
--target=$CI_BUILD_REF_NAME \
--force \
--activate
sleep 10
only:
- branches
except:
- master
phpunit:
stage: post-deploy-test
script:
- bash scripts/gitlab/setup-cli.sh
- platform ssh "phpunit -c phpunit.xml web/modules/custom" -e $CI_BUILD_REF_NAME
only:
- branches
except:
- master
behat:
stage: post-deploy-test
script: |
bash scripts/gitlab/setup-cli.sh
platform variable:create \
--name=env:BEHAT_PARAMS \
--value="{\"extensions\":{\"Behat\\\\MinkExtension\":{\"base_url\":\"`platform url --environment=$CI_BUILD_REF_NAME --pipe | head -n 1`\"}}}" \
--level=environment \
--json=true \
--environment=$CI_BUILD_REF_NAME \
--yes || true
platform ssh "cd behat; behat" -e $CI_BUILD_REF_NAME
only:
- branches
except:
- master
#
deploy-live:
stage: release
script: |
bash scripts/gitlab/setup-cli.sh
platform snapshot:create $CI_BUILD_REF_NAME
platform push \
--target=$CI_BUILD_REF_NAME \
--force
only:
- master