engelsystem/.gitlab-ci.yml

151 lines
3.8 KiB
YAML
Raw Normal View History

image: php
variables:
2018-08-20 23:21:02 +02:00
DOCKER_DRIVER: overlay2
2018-09-23 14:17:48 +02:00
TEST_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
RELEASE_IMAGE: ${CI_REGISTRY_IMAGE}: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"
2018-08-20 23:21:02 +02:00
DOCROOT: /var/www/
2018-08-20 23:21:02 +02:00
stages:
- build-frontend
2018-08-20 23:21:02 +02:00
- build
- test
- release
- deploy
.docker_template: &docker_definition
image: docker:latest
services:
- docker:dind
tags:
- dind
before_script:
2018-09-23 14:17:48 +02:00
- docker login -u gitlab-ci-token -p "${CI_JOB_TOKEN}" "${CI_REGISTRY}"
build-image.nginx:
2018-08-20 23:21:02 +02:00
<<: *docker_definition
stage: build-frontend
2018-08-20 23:21:02 +02:00
script:
- docker build --pull -t "${TEST_IMAGE}-nginx" -f contrib/nginx/Dockerfile .
- docker push "${TEST_IMAGE}-nginx"
build-image:
2018-08-20 23:21:02 +02:00
<<: *docker_definition
stage: build
script:
- docker build --pull --build-arg NGINX_IMAGE="${TEST_IMAGE}-nginx" -t "${TEST_IMAGE}" -f contrib/Dockerfile .
- docker push "${TEST_IMAGE}"
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 ${PHPIZE_DEPS} && pecl install xdebug && docker-php-ext-enable xdebug
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}"
- HOMEDIR=$(pwd)
- 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:
- vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
- 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
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
.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:
2018-08-20 23:21:02 +02:00
- apk add bash rsync openssh-client
.deploy_template_script:
# Configure SSH
2018-09-02 17:56:19 +02:00
- &deploy_template_script |-
mkdir -p ~/.ssh
2018-09-23 14:17:48 +02:00
echo "${SSH_PRIVATE_KEY}" | sed -e 's/\r//g' > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
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:
2018-08-20 23:21:02 +02:00
- rsync -vAax "${DOCROOT}" release/
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
2017-10-22 17:04:07 +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 "${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
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}"