engelsystem/.gitlab-ci.yml

163 lines
4.4 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
- test
- release
- deploy
.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}"
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
- ./yarn.lock
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"
2019-07-21 04:13:31 +02:00
- instance=$(docker create "${TEST_IMAGE}-nginx")
- docker cp "${instance}:/var/www/public/assets" public/
- docker cp "${instance}:/var/www/yarn.lock" .
2019-07-21 04:13:31 +02:00
- docker rm "${instance}"
build-image:
2018-08-20 23:21:02 +02:00
<<: *docker_definition
stage: build
script:
- apk -q add git
- VERSION="$(git describe --abbrev=0 --tags)-${CI_COMMIT_REF_NAME}+${CI_PIPELINE_ID}.${CI_COMMIT_SHORT_SHA}"
2019-07-21 13:42:19 +02:00
- docker build --pull --build-arg VERSION="${VERSION}" -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:
- rsync -vAax "${DOCROOT}" "${DOCROOT}/.babelrc" "${DOCROOT}/.browserslistrc" release/
2019-07-21 04:13:31 +02:00
- rsync -vAax public/assets release/public/
- rsync -vAax yarn.lock 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}"