-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
196 lines (195 loc) · 6.39 KB
/
.gitlab-ci.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
image: zacksleo/docker-composer:alpine
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" > ~/deploy.key
- chmod 0600 ~/deploy.key
- ssh-add ~/deploy.key
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- export APP_ENV=testing
stages:
- prepare
- test
- build
- deploy
variables:
COMPOSER_CACHE_DIR: "/cache/composer"
DOCKER_DRIVER: overlay2
build-cache:
stage: prepare
script:
- composer install --prefer-dist --optimize-autoloader -n --no-interaction -v --no-suggest
- composer dump-autoload --optimize
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- vendor
except:
- tags
when: manual
build-package:
stage: test
script:
- composer install --prefer-dist --optimize-autoloader -n --no-interaction -v --no-suggest --no-dev
- composer dump-autoload --optimize
dependencies: []
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- vendor
artifacts:
name: "vendor"
untracked: false
expire_in: 60 mins
paths:
- vendor
only:
- tags
phpcs:
stage: test
dependencies: []
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- vendor
script:
- if [ ! -d "vendor" ]; then
- composer install --prefer-dist --optimize-autoloader -n --no-interaction -v --no-suggest && composer dump-autoload --optimize
- fi
- php vendor/bin/phpcs --config-set ignore_warnings_on_exit 1
- php vendor/bin/phpcs --config-set show_warnings 0
- php vendor/bin/phpcs --standard=PSR2 --ignore=vendor/,console/migrations/,tests -w --colors ./
except:
- develop
- master
- tags
phpmd:
stage: test
dependencies: []
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- vendor
script:
- if [ ! -d "vendor" ]; then
- composer install --prefer-dist --optimize-autoloader -n --no-interaction -v --no-suggest && composer dump-autoload --optimize
- fi
- vendor/bin/phpmd api,backend,common,console,frontend text phpmd.xml --exclude vendor/,console/migrations --suffixes php
except:
- develop
- master
- tags
codequality:
stage: test
image: docker:latest
before_script: []
cache: {}
dependencies: []
script:
- docker pull codeclimate/codeclimate
- VOLUME_PATH=/tmp/builds"$(echo $PWD | sed 's|^/[^/]*||')"
- docker run --env CODECLIMATE_CODE="$VOLUME_PATH" -v /tmp/cc:/tmp/cc -v $VOLUME_PATH:/code -v /var/run/docker.sock:/var/run/docker.sock codeclimate/codeclimate analyze -f text
except:
- tags
- develop
- master
allow_failure: true
when: manual
unit-test:
stage: test
services:
- name: mysql:8
alias: mysql
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
- name: redis:alpine
alias: redis
variables:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: web
MYSQL_USER: web
MYSQL_PASSWORD: web
REDIS_PORT: 6379
dependencies: []
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
script:
- if [ ! -d "vendor" ]; then
- composer install --prefer-dist --optimize-autoloader -n --no-interaction -v --no-suggest && composer dump-autoload --optimize
- fi
- cp tests/.env .env
- ./yii migrate/up --interactive=0
- ./vendor/bin/codecept run unit -c tests --coverage --no-colors
artifacts:
name: "debug"
when: on_failure
untracked: true
expire_in: 60 mins
paths:
- $CI_PROJECT_DIR/tests/_output
api-test:
stage: test
services:
- name: mysql:8
alias: mysql
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
- name: redis:alpine
alias: redis
variables:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: web
MYSQL_USER: web
MYSQL_PASSWORD: web
REDIS_PORT: 6379
dependencies: []
script:
- if [ ! -d "vendor" ]; then
- composer install --prefer-dist --optimize-autoloader -n --no-interaction -v --no-suggest && composer dump-autoload --optimize
- fi
- cp tests/.env .env
- ./yii migrate/up --interactive=0
- php -S localhost:8080 --docroot api/tests &>/dev/null&
- ./vendor/bin/codecept run api -c tests
artifacts:
name: "debug"
when: on_failure
untracked: true
expire_in: 60 mins
paths:
- $CI_PROJECT_DIR/api/runtime
- $CI_PROJECT_DIR/tests/_output
production-image:
stage: build
image: docker:latest
dependencies:
- build-package
before_script: []
script:
- if [ ! -f "vendor/autoload.php" ]; then
- exit 1
- fi
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
production-server:
stage: deploy
variables:
DEPLOY_SERVER: "$PRODUCTION_SERVER"
dependencies: []
script:
- cd deploy/production
- rsync -rtvhze ssh . root@$DEPLOY_SERVER:/data/$CI_PROJECT_NAME --stats
- CHOWN_DIR="frontend/runtime frontend/web/assets frontend/web/uploads backend/runtime backend/web/assets backend/rbac console/runtime api/runtime api/web/assets"
- ssh root@$DEPLOY_SERVER "docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY"
- ssh root@$DEPLOY_SERVER "export COMPOSE_HTTP_TIMEOUT=120 && export DOCKER_CLIENT_TIMEOUT=120 && export TAG=$CI_COMMIT_TAG && cd /data/$CI_PROJECT_NAME && docker-compose pull web && docker-compose stop web && docker-compose rm -f web && docker-compose up web -d"
- ssh root@$DEPLOY_SERVER "docker exec -i $CI_PROJECT_NAME chown www-data:www-data $CHOWN_DIR"
- ssh root@$DEPLOY_SERVER "docker exec -i $CI_PROJECT_NAME ./yii migrate/up --interactive=0"
only:
- tags
when: manual
environment:
name: production
url: http://$DEPLOY_SERVER