engelsystem/.gitlab-ci.yml

207 lines
5.4 KiB
YAML
Raw Normal View History

image: php
variables:
2018-08-20 23:21:02 +02:00
DOCKER_DRIVER: overlay2
2020-05-09 00:58:17 +02:00
TEST_IMAGE: ${CI_REGISTRY_IMAGE}/engelsystem:${CI_COMMIT_REF_SLUG}
TEST_IMAGE_NGINX: ${CI_REGISTRY_IMAGE}/nginx:${CI_COMMIT_REF_SLUG}
RELEASE_IMAGE: ${CI_REGISTRY_IMAGE}/engelsystem:latest
RELEASE_IMAGE_NGINX: ${CI_REGISTRY_IMAGE}/nginx:latest
MYSQL_DATABASE: engelsystem
MYSQL_USER: engel
MYSQL_PASSWORD: engelsystem
2017-11-25 10:53:50 +01:00
MYSQL_HOST: mariadb
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
2019-09-17 20:24:16 +02:00
MYSQL_INITDB_SKIP_TZINFO: "yes"
2018-08-20 23:21:02 +02:00
DOCROOT: /var/www/
2018-08-20 23:21:02 +02:00
stages:
- validate
2018-08-20 23:21:02 +02:00
- build
- test
- release
- deploy
check-style:
image: composer:latest
stage: validate
before_script:
- composer --no-ansi global require squizlabs/php_codesniffer
- export PATH=$PATH:$COMPOSER_HOME/vendor/bin
script:
- phpcs -p --no-colors --basepath="$PWD"
validate-composer:
image: composer:latest
stage: validate
script:
- composer --no-ansi validate --strict
validate-yarn:
image: node:alpine
stage: validate
before_script:
- yarn global add package-json-validator
- export PATH=$PATH:~/.yarn/bin
script:
- pjv
2018-08-20 23:21:02 +02:00
.docker_template: &docker_definition
image: docker:18
2018-08-20 23:21:02 +02:00
services:
- docker:18-dind
2018-08-20 23:21:02 +02:00
tags:
- dind
before_script:
2018-09-23 14:17:48 +02:00
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
2020-05-09 00:58:17 +02:00
build-image-nginx:
2018-08-20 23:21:02 +02:00
<<: *docker_definition
stage: build
2019-07-21 04:13:31 +02:00
artifacts:
name: "${CI_JOB_NAME}_${CI_JOB_ID}_assets"
expire_in: 1 day
paths:
- ./public/assets
2018-08-20 23:21:02 +02:00
script:
2020-05-09 00:58:17 +02:00
- docker build --pull -t "${TEST_IMAGE_NGINX}" -f docker/nginx/Dockerfile .
- docker push "${TEST_IMAGE_NGINX}"
- instance=$(docker create "${TEST_IMAGE_NGINX}")
2019-07-21 04:13:31 +02:00
- docker cp "${instance}:/var/www/public/assets" public/
- docker rm "${instance}"
build-image:
2018-08-20 23:21:02 +02:00
<<: *docker_definition
stage: build
script:
- apk add -q git
- VERSION="$(git describe --abbrev=0 --tags)-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"
2019-10-14 23:36:26 +02:00
- docker build --pull --build-arg VERSION="${VERSION}" -t "${TEST_IMAGE}" -f docker/Dockerfile .
- docker push "${TEST_IMAGE}"
audit-composer:
image: ${TEST_IMAGE}
stage: test
before_script:
- curl -sSo /usr/local/bin/security-checker https://get.sensiolabs.org/security-checker.phar
- chmod +x /usr/local/bin/security-checker
- cd "${DOCROOT}"
script:
- security-checker --no-ansi security:check
audit-yarn:
image: node:10-alpine
stage: test
script:
- yarn audit
2018-08-20 23:21:02 +02:00
test:
2018-09-23 14:17:48 +02:00
image: ${TEST_IMAGE}
stage: test
2018-08-20 23:21:02 +02:00
services:
- mariadb:10.2
artifacts:
name: "${CI_JOB_NAME}_${CI_JOB_ID}"
expire_in: 1 week
2018-08-30 13:33:16 +02:00
when: always
paths:
- ./coverage/
- ./unittests.xml
reports:
junit: ./unittests.xml
coverage: '/^\s*Lines:\s*(\d+(?:\.\d+)?%)/'
2018-08-20 23:21:02 +02:00
before_script:
- apk add -q ${PHPIZE_DEPS} && pecl install pcov > /dev/null && docker-php-ext-enable pcov
2018-08-20 23:21:02 +02:00
- curl -sS https://getcomposer.org/installer | php -- --no-ansi --install-dir /usr/local/bin/ --filename composer
- cp -R tests/ phpunit.xml "${DOCROOT}"
2019-11-10 23:26:23 +01:00
- HOMEDIR=$PWD
2018-08-20 23:21:02 +02:00
- cd "${DOCROOT}"
2019-05-31 17:09:50 +02:00
- composer --no-ansi install
2018-09-02 17:56:19 +02:00
- ./bin/migrate
script:
2020-05-09 00:58:17 +02:00
- >-
php -d pcov.enabled=1 vendor/bin/phpunit -vvv --colors=never
--coverage-text --coverage-html "${HOMEDIR}/coverage/"
--log-junit "${HOMEDIR}/unittests.xml"
after_script:
- '"${DOCROOT}/bin/migrate" down'
2019-11-10 23:26:23 +01:00
2018-08-20 23:21:02 +02:00
release-image:
<<: *docker_definition
stage: release
script:
2018-09-23 14:17:48 +02:00
- docker pull "${TEST_IMAGE}"
- docker tag "${TEST_IMAGE}" "${RELEASE_IMAGE}"
- docker push "${RELEASE_IMAGE}"
2018-08-20 23:21:02 +02:00
only:
- master
2020-05-09 00:58:17 +02:00
release-image-nginx:
2018-08-20 23:21:02 +02:00
<<: *docker_definition
stage: release
script:
2020-05-09 00:58:17 +02:00
- docker pull "${TEST_IMAGE_NGINX}"
- docker tag "${TEST_IMAGE_NGINX}" "${RELEASE_IMAGE_NGINX}"
- docker push "${RELEASE_IMAGE_NGINX}"
2018-08-20 23:21:02 +02:00
only:
- master
2017-10-22 17:04:07 +02:00
.deploy_template: &deploy_definition
2017-10-22 17:04:07 +02:00
stage: deploy
2018-09-23 14:17:48 +02:00
image: ${TEST_IMAGE}
before_script:
- apk add -q bash rsync openssh-client
.deploy_template_script:
# Configure SSH
2018-09-02 17:56:19 +02:00
- &deploy_template_script |-
eval $(ssh-agent -s) && echo "${SSH_PRIVATE_KEY}" | ssh-add -
2019-08-20 23:55:34 +02:00
rsync -vAax public/assets ${DOCROOT}/public/
2018-08-20 23:21:02 +02:00
cd "${DOCROOT}"
2018-08-20 23:21:02 +02:00
build-release-file:
<<: *deploy_definition
2018-08-20 23:21:02 +02:00
stage: deploy
artifacts:
name: "release_${CI_COMMIT_REF_SLUG}_${CI_JOB_ID}_${CI_COMMIT_SHA}"
expire_in: 1 week
paths:
- ./release/
script:
- rsync -vAax "${DOCROOT}" "${DOCROOT}/.babelrc" "${DOCROOT}/.browserslistrc" release/
2019-07-21 04:13:31 +02:00
- rsync -vAax public/assets release/public/
2018-08-20 23:21:02 +02:00
deploy-staging:
<<: *deploy_definition
environment:
name: staging
2018-08-20 23:21:02 +02:00
only:
- master
2017-10-22 17:04:07 +02:00
script:
# Check if deployment variables where set
2017-10-22 17:04:07 +02:00
- |-
if [ -z "${SSH_PRIVATE_KEY}" ] || [ -z "${STAGING_REMOTE}" ] || [ -z "${STAGING_REMOTE_PATH}" ]; then
2020-05-09 00:58:17 +02:00
echo "Skipping deployment"
2017-10-22 17:04:07 +02:00
exit
fi
2018-09-02 17:56:19 +02:00
- *deploy_template_script
# Deploy to server
2018-08-07 16:47:47 +02:00
- ./bin/deploy.sh -r "${STAGING_REMOTE}" -p "${STAGING_REMOTE_PATH}" -i "${CI_JOB_ID}-${CI_COMMIT_SHA}"
2017-10-22 17:04:07 +02:00
2018-08-20 23:21:02 +02:00
deploy-production:
<<: *deploy_definition
environment:
name: production
when: manual
2018-08-20 23:21:02 +02:00
only:
- master
script:
# Check if deployment variables where set
- |-
if [ -z "${SSH_PRIVATE_KEY}" ] || [ -z "${PRODUCTION_REMOTE}" ] || [ -z "${PRODUCTION_REMOTE_PATH}" ]; then
2020-05-09 00:58:17 +02:00
echo "Skipping deployment"
exit
fi
2018-09-02 17:56:19 +02:00
- *deploy_template_script
# Deploy to server
2018-08-07 16:47:47 +02:00
- ./bin/deploy.sh -r "${PRODUCTION_REMOTE}" -p "${PRODUCTION_REMOTE_PATH}" -i "${CI_JOB_ID}-${CI_COMMIT_SHA}"