-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgitlab.yml
128 lines (116 loc) · 3.41 KB
/
gitlab.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
image: php70:latest
variables:
# Заявка
TASK_ID: ''
cache:
key: "vendor-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHA"
paths:
- vendor
stages:
- build
- test
- deploy
- cs
before_script:
# Настройка ключей деплоя одинаково для всех проектов
- eval $(ssh-agent -s)
- ssh-add <(cat ~/.ssh/id_rsa.deploy)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# Определяем задачу по ветке
- TASK_ID=$(sed 's/^.*\///g' <<< $CI_COMMIT_REF_NAME)
# Сборка проекта
build:
stage: build
script:
# Composer
- '[[ -f composer.json ]] && composer install --prefer-dist --no-progress'
# Запуск тестов
test:
stage: test
script:
# Download stable release of xdebug 2.4.0
- apt-get update
- apt-get install -y php7.0-xdebug
- '[[ -f composer.json ]] && composer install --prefer-dist --no-progress'
- ${CI_PROJECT_DIR}/vendor/bin/phpunit -c ${CI_PROJECT_DIR}/tests/phpunit-cov.xml
artifacts:
paths:
- report/
# Code Sniffer
cs:
stage: cs
script:
- composer require "squizlabs/php_codesniffer=*"
- 'vendor/bin/phpcs --standard=PSR1,PSR2 --ignore=tests/autoload.php src t
# Шаблон выкладки
.deploy_template: &deploy_definition |
echo "$CLUSTER"
echo "$PROJECT_PATH"
for server in $CLUSTER; do if [ ${#PROJECT_PATH} -ge 10 ]; then ssh ${server} mkdir -p "${PROJECT_PATH}"; rsync -zrpth --stats --delete-after --exclude=.git $(pwd)/ ${server}:${PROJECT_PATH}; fi; done
# чистка кеша
for server in $CLUSTER; do if [ ${#PROJECT_PATH} -ge 10 ]; then ssh ${server} "php ${PROJECT_PATH}simple.php System/Cache/clear"; break; fi; done
# Шаблон удаления
.remove_template: &remove_definition |
for server in $CLUSTER; do if [ ${#server} -ge 10 ]; then ssh ${server} rm -rf ${PROJECT_PATH}; fi; done
# Удаление ветки для теста
remove in test:
stage: deploy
only:
- /^feature\/.*$/
- master
except:
- develop
- dev
environment:
name: test/${CI_COMMIT_REF_SLUG}
action: stop
variables:
CLUSTER: $CLUSTER_TEST
PROJECT_PATH: ${PROJECT_PATH_TEST}${CI_COMMIT_REF_SLUG}
script:
- *remove_definition
when: manual
# Выкладка ветки для теста
deploy to test:
stage: deploy
only:
- /^feature\/.*$/
- master
except:
- develop
- dev
environment:
name: test/${CI_COMMIT_REF_SLUG}
url: ${URL_TEST}${CI_COMMIT_REF_SLUG}/index.php?route=Call/Call/products
on_stop: remove in test
variables:
CLUSTER: $CLUSTER_TEST
PROJECT_PATH: ${PROJECT_PATH_TEST}${CI_COMMIT_REF_SLUG}/
script:
# Версия сборки
- sed -i -- "s/{BUILD_VERSION}/$CI_JOB_ID/g" config/config.php
# Права
- chmod -R 0777 templates_c
# Выкладка
- *deploy_definition
when: manual
# Выкладка на боевой
deploy to production:
stage: deploy
only:
- master
environment:
name: production
variables:
CLUSTER: $CLUSTER_PROD
PROJECT_PATH: $PROJECT_PATH_PROD
script:
# Права
- chmod -R 0777 templates_c
# Боевой конфиг
- sed -i -- "s/{CONFIG_FOR_REPLACE_JENKINS}/work/g" config/config.php
# Версия сборки
- sed -i -- "s/{BUILD_VERSION}/$CI_JOB_ID/g" config/config.php
# Выкладка
- *deploy_definition
when: manual