2017-09-25 00:03:22 +02:00
|
|
|
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
|
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"
|
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:
|
|
|
|
- build
|
|
|
|
- test
|
|
|
|
- release
|
|
|
|
- deploy
|
|
|
|
|
|
|
|
.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
|
2019-07-26 13:32:54 +02:00
|
|
|
- ./yarn.lock
|
2018-08-20 23:21:02 +02:00
|
|
|
script:
|
2018-09-23 14:18:24 +02:00
|
|
|
- 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/
|
2019-07-26 13:32:54 +02:00
|
|
|
- docker cp "${instance}:/var/www/yarn.lock" .
|
2019-07-21 04:13:31 +02:00
|
|
|
- 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:
|
2019-07-21 02:34:52 +02:00
|
|
|
- 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 .
|
2018-09-23 14:18:24 +02:00
|
|
|
- docker push "${TEST_IMAGE}"
|
2017-09-25 00:03:22 +02:00
|
|
|
|
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-07-21 04:53:50 +02:00
|
|
|
- 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:
|
2018-09-23 23:34:02 +02:00
|
|
|
- vendor/bin/phpunit -v --colors=never --coverage-text --coverage-html "${HOMEDIR}/coverage/" --log-junit "${HOMEDIR}/unittests.xml"
|
|
|
|
- bin/migrate down
|
2017-09-25 00:03:22 +02: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
|
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:
|
2018-08-20 23:21:02 +02:00
|
|
|
- apk add 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 |-
|
2017-11-29 14:35:59 +01:00
|
|
|
mkdir -p ~/.ssh
|
2018-09-23 14:17:48 +02:00
|
|
|
echo "${SSH_PRIVATE_KEY}" | sed -e 's/\r//g' > ~/.ssh/id_ed25519
|
2017-11-29 14:35:59 +01:00
|
|
|
chmod 600 ~/.ssh/id_ed25519
|
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/
|
2019-07-26 13:32:54 +02:00
|
|
|
- rsync -vAax yarn.lock release/
|
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}"
|