2017-09-25 00:03:22 +02:00
|
|
|
image: php
|
|
|
|
|
|
|
|
variables:
|
2018-08-20 23:21:02 +02:00
|
|
|
DOCKER_DRIVER: overlay2
|
2020-04-05 20:10:04 +02:00
|
|
|
TEST_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
|
2018-09-23 14:17:48 +02:00
|
|
|
RELEASE_IMAGE: ${CI_REGISTRY_IMAGE}:latest
|
2017-09-25 00:03:22 +02:00
|
|
|
MYSQL_DATABASE: engelsystem
|
|
|
|
MYSQL_USER: engel
|
|
|
|
MYSQL_PASSWORD: engelsystem
|
2017-11-25 10:53:50 +01:00
|
|
|
MYSQL_HOST: mariadb
|
2017-09-25 00:03:22 +02:00
|
|
|
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/
|
2017-09-25 00:03:22 +02:00
|
|
|
|
2018-08-20 23:21:02 +02:00
|
|
|
stages:
|
2020-04-25 14:47:09 +02:00
|
|
|
- validate
|
2018-08-20 23:21:02 +02:00
|
|
|
- build
|
|
|
|
- test
|
|
|
|
- release
|
|
|
|
- deploy
|
|
|
|
|
2020-04-25 14:47:09 +02:00
|
|
|
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
|
2019-07-24 23:23:01 +02:00
|
|
|
image: docker:18
|
2018-08-20 23:21:02 +02:00
|
|
|
services:
|
2019-07-24 23:23:01 +02:00
|
|
|
- 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}"
|
2017-09-25 00:03:22 +02:00
|
|
|
|
2018-09-23 14:18:24 +02:00
|
|
|
build-image.nginx:
|
2018-08-20 23:21:02 +02:00
|
|
|
<<: *docker_definition
|
2019-07-26 13:32:54 +02:00
|
|
|
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:
|
2019-10-14 23:36:26 +02:00
|
|
|
- docker build --pull -t "${TEST_IMAGE}-nginx" -f docker/nginx/Dockerfile .
|
2018-09-23 14:18:24 +02:00
|
|
|
- docker push "${TEST_IMAGE}-nginx"
|
2019-07-21 04:13:31 +02:00
|
|
|
- instance=$(docker create "${TEST_IMAGE}-nginx")
|
|
|
|
- docker cp "${instance}:/var/www/public/assets" public/
|
|
|
|
- docker rm "${instance}"
|
2017-09-25 00:03:22 +02:00
|
|
|
|
2018-09-23 14:18:24 +02:00
|
|
|
build-image:
|
2018-08-20 23:21:02 +02:00
|
|
|
<<: *docker_definition
|
|
|
|
stage: build
|
|
|
|
script:
|
2020-04-25 14:47:09 +02:00
|
|
|
- apk add -q git
|
2019-07-21 02:34:52 +02:00
|
|
|
- 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 .
|
2018-09-23 14:18:24 +02:00
|
|
|
- docker push "${TEST_IMAGE}"
|
2017-09-25 00:03:22 +02:00
|
|
|
|
2020-04-25 14:47:09 +02:00
|
|
|
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}
|
2017-11-29 14:35:59 +01:00
|
|
|
stage: test
|
2018-08-20 23:21:02 +02:00
|
|
|
services:
|
|
|
|
- mariadb:10.2
|
2017-09-25 00:03:22 +02:00
|
|
|
artifacts:
|
2018-08-04 21:26:33 +02:00
|
|
|
name: "${CI_JOB_NAME}_${CI_JOB_ID}"
|
2017-09-25 00:03:22 +02:00
|
|
|
expire_in: 1 week
|
2018-08-30 13:33:16 +02:00
|
|
|
when: always
|
2017-09-25 00:03:22 +02:00
|
|
|
paths:
|
|
|
|
- ./coverage/
|
2018-09-23 23:34:02 +02:00
|
|
|
- ./unittests.xml
|
|
|
|
reports:
|
|
|
|
junit: ./unittests.xml
|
2017-09-25 00:03:22 +02:00
|
|
|
coverage: '/^\s*Lines:\s*(\d+(?:\.\d+)?%)/'
|
2018-08-20 23:21:02 +02:00
|
|
|
before_script:
|
2019-11-30 22:31:34 +01:00
|
|
|
- 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:
|
2019-11-30 22:31:34 +01:00
|
|
|
- php -d pcov.enabled=1 vendor/bin/phpunit -vvv --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
|
2019-11-10 23:26:23 +01:00
|
|
|
- ./bin/migrate down
|
|
|
|
|
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
|
2017-09-25 00:03:22 +02:00
|
|
|
|
2018-08-20 23:21:02 +02:00
|
|
|
release-image.nginx:
|
|
|
|
<<: *docker_definition
|
|
|
|
stage: release
|
|
|
|
script:
|
2018-10-24 15:20:28 +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
|
|
|
|
2017-11-29 14:35:59 +01: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}
|
2017-11-29 14:35:59 +01:00
|
|
|
before_script:
|
2020-04-25 14:47:09 +02:00
|
|
|
- apk add -q bash rsync openssh-client
|
2017-11-29 14:35:59 +01:00
|
|
|
|
|
|
|
.deploy_template_script:
|
|
|
|
# Configure SSH
|
2018-09-02 17:56:19 +02:00
|
|
|
- &deploy_template_script |-
|
2020-04-25 14:47:09 +02:00
|
|
|
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}"
|
2017-11-29 14:35:59 +01:00
|
|
|
|
2018-08-20 23:21:02 +02:00
|
|
|
build-release-file:
|
2018-08-04 21:26:33 +02:00
|
|
|
<<: *deploy_definition
|
2018-08-20 23:21:02 +02:00
|
|
|
stage: deploy
|
2018-08-04 21:26:33 +02:00
|
|
|
artifacts:
|
|
|
|
name: "release_${CI_COMMIT_REF_SLUG}_${CI_JOB_ID}_${CI_COMMIT_SHA}"
|
|
|
|
expire_in: 1 week
|
|
|
|
paths:
|
|
|
|
- ./release/
|
|
|
|
script:
|
2019-07-26 13:32:54 +02:00
|
|
|
- rsync -vAax "${DOCROOT}" "${DOCROOT}/.babelrc" "${DOCROOT}/.browserslistrc" release/
|
2019-07-21 04:13:31 +02:00
|
|
|
- rsync -vAax public/assets release/public/
|
2018-08-04 21:26:33 +02:00
|
|
|
|
2018-08-20 23:21:02 +02:00
|
|
|
deploy-staging:
|
2017-11-29 14:35:59 +01:00
|
|
|
<<: *deploy_definition
|
|
|
|
environment:
|
|
|
|
name: staging
|
2018-08-20 23:21:02 +02:00
|
|
|
only:
|
|
|
|
- master
|
2017-10-22 17:04:07 +02:00
|
|
|
script:
|
2017-11-29 14:35:59 +01:00
|
|
|
# Check if deployment variables where set
|
2017-10-22 17:04:07 +02:00
|
|
|
- |-
|
2017-11-29 14:35:59 +01:00
|
|
|
if [ -z "${SSH_PRIVATE_KEY}" ] || [ -z "${STAGING_REMOTE}" ] || [ -z "${STAGING_REMOTE_PATH}" ]; then
|
2017-10-22 17:04:07 +02:00
|
|
|
echo "Skipping deployment";
|
|
|
|
exit
|
|
|
|
fi
|
2018-09-02 17:56:19 +02:00
|
|
|
- *deploy_template_script
|
2017-11-29 14:35:59 +01:00
|
|
|
# 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:
|
2017-11-29 14:35:59 +01:00
|
|
|
<<: *deploy_definition
|
|
|
|
environment:
|
|
|
|
name: production
|
|
|
|
when: manual
|
2018-08-20 23:21:02 +02:00
|
|
|
only:
|
|
|
|
- master
|
2017-11-29 14:35:59 +01:00
|
|
|
script:
|
|
|
|
# Check if deployment variables where set
|
|
|
|
- |-
|
|
|
|
if [ -z "${SSH_PRIVATE_KEY}" ] || [ -z "${PRODUCTION_REMOTE}" ] || [ -z "${PRODUCTION_REMOTE_PATH}" ]; then
|
|
|
|
echo "Skipping deployment";
|
|
|
|
exit
|
|
|
|
fi
|
2018-09-02 17:56:19 +02:00
|
|
|
- *deploy_template_script
|
2017-11-29 14:35:59 +01:00
|
|
|
# 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}"
|