-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
259 lines (244 loc) · 11.9 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
before_script:
- cp $CI_SERVER_TLS_CA_FILE /usr/local/share/ca-certificates/
- update-ca-certificates
cache: &cache
untracked: false
.tags-defaults-docker: &tags-defaults-docker
- shared
variables:
TEMP_IMAGE: ci-build/$CI_PROJECT_PATH:$CI_PIPELINE_ID
TEMP_IMAGE_PATH: build/image.tar
META_PATH: build/metadata
META_PHP_VERSION: $META_PATH/php-version.txt
PHP_TESTS_REPOSITORY: https://github.com/gmitirol/php-tests.git
VERSION_TOOL_REPOSITORY: https://github.com/xelan/bash-version-tool.git
stages:
- build
- test_php
- test_web
- release
build:
stage: build
image: $CI_REGISTRY/docker/docker:27-cli
cache:
<<: *cache
artifacts:
expire_in: 1 hour
paths:
- $TEMP_IMAGE_PATH
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- echo $CI_COMMIT_REF_NAME > PHP_BUILD
- docker build --tag $TEMP_IMAGE . --build-arg REGISTRY_PATH=$CI_REGISTRY/docker --build-arg GITHUB_TOKEN
- mkdir -p build
- docker save --output $TEMP_IMAGE_PATH $TEMP_IMAGE
tags: *tags-defaults-docker
test_php_base:
stage: test_php
image: $CI_REGISTRY/docker/docker:27-cli
artifacts:
expire_in: 1 hour
paths:
- $META_PATH
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
script:
- mkdir -p $META_PATH
- docker load --input $TEMP_IMAGE_PATH --quiet
- docker run --rm $TEMP_IMAGE sh -c 'grep -E "^date.timezone = $(cat /etc/TZ)" /etc/php8/php.ini'
- docker run --rm $TEMP_IMAGE sh -c 'composer --version'
- docker run --rm $TEMP_IMAGE sh -c 'phpcs --version'
- docker run --rm -e PHP_TESTS_REPOSITORY $TEMP_IMAGE sh -c 'php-ext.sh enable-all && php-ext.sh show && git clone "$PHP_TESTS_REPOSITORY" && cd php-tests && composer install -q --no-progress && vendor/bin/phpunit -vv --group php_base'
- docker run --rm $TEMP_IMAGE sh -c 'php -r "printf(\"%s.%s.%s\", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION);"' > $META_PHP_VERSION
tags: *tags-defaults-docker
test_php_mysql:
stage: test_php
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
- name: mysql:5.6
alias: $MYSQL_HOST
variables:
MYSQL_HOST: "mysql"
MYSQL_PORT: 3306
MYSQL_USER: "phptests"
MYSQL_PASSWORD: $(head -c 32 /dev/urandom | base64)
MYSQL_DATABASE: "phptests"
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- MYSQL_IP=$(getent hosts $MYSQL_HOST | awk '{print $1}')
- docker run --rm --add-host $MYSQL_HOST:$MYSQL_IP -e MYSQL_HOST -e MYSQL_PORT -e MYSQL_DATABASE -e MYSQL_USER -e MYSQL_PASSWORD -e PHP_TESTS_REPOSITORY $TEMP_IMAGE sh -c 'php-ext.sh enable-all && php-ext.sh show && git clone "$PHP_TESTS_REPOSITORY" && cd php-tests && composer install -q --no-progress && vendor/bin/phpunit -vv --group php_mysql'
tags: *tags-defaults-docker
test_php_memcached:
stage: test_php
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
- name: memcached:1.5
alias: $MEMCACHED_HOST
variables:
MEMCACHED_HOST: "memcached"
MEMCACHED_PORT: 11211
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- MEMCACHED_IP=$(getent hosts $MEMCACHED_HOST | awk '{print $1}')
- docker run --rm --add-host $MEMCACHED_HOST:$MEMCACHED_IP -e MEMCACHED_HOST -e MEMCACHED_PORT -e PHP_TESTS_REPOSITORY $TEMP_IMAGE sh -c 'php-ext.sh enable-all && php-ext.sh show && git clone "$PHP_TESTS_REPOSITORY" && cd php-tests && composer install -q --no-progress && vendor/bin/phpunit -vv --group php_memcached'
tags: *tags-defaults-docker
test_php_https:
stage: test_php
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
variables:
HTTPS_TEST_HOST: "www.google.com"
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- docker run --rm -e HTTPS_TEST_HOST -e PHP_TESTS_REPOSITORY $TEMP_IMAGE sh -c 'php-ext.sh enable-all && php-ext.sh show && git clone "$PHP_TESTS_REPOSITORY" && cd php-tests && composer install -q --no-progress && vendor/bin/phpunit -vv --group php_https'
tags: *tags-defaults-docker
test_php_imap:
stage: test_php
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
- name: $CI_REGISTRY/docker/minimal-imap:v1
alias: imap
variables:
IMAP_HOST: "imap"
EMAIL_SERVER: "$IMAP_HOST:143/imap"
EMAIL_USERNAME: "imap"
EMAIL_PASSWORD: "imap"
script:
- cat /etc/hosts
- docker load --input $TEMP_IMAGE_PATH --quiet
- IMAP_IP=$(getent hosts $IMAP_HOST | awk '{print $1}')
- docker run --rm --add-host $IMAP_HOST:$IMAP_IP -e EMAIL_SERVER -e EMAIL_USERNAME -e EMAIL_PASSWORD -e PHP_TESTS_REPOSITORY $TEMP_IMAGE sh -c 'php-ext.sh enable-all && php-ext.sh show && git clone "$PHP_TESTS_REPOSITORY" && cd php-tests && composer install -q --no-progress && vendor/bin/phpunit -vv --group php_imap'
tags: *tags-defaults-docker
test_web_static:
stage: test_web
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- CONTAINER=$(docker run -d $TEMP_IMAGE supervisord)
- docker exec $CONTAINER sh -c 'mkdir -p /home/project/www'
- docker exec $CONTAINER sh -c 'setup-nginx.sh static /home/project/www'
- docker exec $CONTAINER sh -c 'supervisorctl restart nginx php-fpm'
- docker exec $CONTAINER sh -c 'echo example > /home/project/www/example.txt'
- docker exec $CONTAINER sh -c '[ "example" == "$(curl -s http://localhost/example.txt)" ]'
- docker exec $CONTAINER sh -c 'echo "<?php echo \"Hello World!\";" > /home/project/www/example.php'
- docker exec $CONTAINER sh -c '[ "404" == "$(curl -s -o /dev/null -w "%{http_code}" http://localhost/example.php)" ]'
- docker exec $CONTAINER sh -c 'echo "secret file contents" > /home/project/www/.secret'
- docker exec $CONTAINER sh -c '[ "403" == "$(curl -s -o /dev/null -w "%{http_code}" http://localhost/.secret)" ]'
- docker kill $CONTAINER
tags: *tags-defaults-docker
test_web_php:
stage: test_web
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- CONTAINER=$(docker run -d $TEMP_IMAGE supervisord)
- docker exec $CONTAINER sh -c 'mkdir -p /home/project/www'
- docker exec $CONTAINER sh -c 'setup-nginx.sh php /home/project/www'
- docker exec $CONTAINER sh -c 'supervisorctl restart nginx php-fpm'
- docker exec $CONTAINER sh -c 'echo example > /home/project/www/example.txt'
- docker exec $CONTAINER sh -c '[ "example" == "$(curl -s http://localhost/example.txt)" ]'
- docker exec $CONTAINER sh -c 'echo "<?php echo \"Hello World!\";" > /home/project/www/example.php'
- docker exec $CONTAINER sh -c '[ "Hello World!" == "$(curl -s http://localhost/example.php)" ]'
- docker exec $CONTAINER sh -c 'echo "<?php echo \"Index is working!\";" > /home/project/www/index.php'
- docker exec $CONTAINER sh -c '[ "Index is working!" == "$(curl -s http://localhost/)" ]'
- docker kill $CONTAINER
tags: *tags-defaults-docker
test_web_symfony:
stage: test_web
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- CONTAINER=$(docker run -d $TEMP_IMAGE supervisord)
- docker exec $CONTAINER sh -c 'mkdir -p /home/project/www'
- docker exec $CONTAINER sh -c 'setup-nginx.sh symfony /home/project/www'
- docker exec $CONTAINER sh -c 'supervisorctl restart nginx php-fpm'
# The front controller (app.php) should be accessible
- docker exec $CONTAINER sh -c 'echo "<?php echo \$_SERVER[\"REQUEST_URI\"];" > /home/project/www/app.php'
- docker exec $CONTAINER sh -c '[ "/" == "$(curl -s http://localhost/)" ]'
- docker exec $CONTAINER sh -c '[ "/example/route" == "$(curl -s http://localhost/example/route)" ]'
# The front controller (app.php) should be not be accessible directly (via localhost/app.php)
- docker exec $CONTAINER sh -c 'echo "<?php echo \$_SERVER[\"REQUEST_URI\"];" > /home/project/www/app.php'
- docker exec $CONTAINER sh -c '[ "404" == "$(curl -s -o /dev/null -w "%{http_code}" http://localhost/app.php)" ]'
# Other PHP files should be not be accessible
- docker exec $CONTAINER sh -c 'echo "<?php \$_SERVER[\"REQUEST_URI\"];" > /home/project/www/example.php'
- docker exec $CONTAINER sh -c '[ "404" == "$(curl -s -o /dev/null -w "%{http_code}" http://localhost/example.php)" ]'
# Real files should be served directly
- docker exec $CONTAINER sh -c 'echo real_file > /home/project/www/real_file'
- docker exec $CONTAINER sh -c '[ "real_file" == "$(curl -s http://localhost/real_file)" ]'
- docker kill $CONTAINER
tags: *tags-defaults-docker
test_web_symfony4:
stage: test_web
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- CONTAINER=$(docker run -d $TEMP_IMAGE supervisord)
- docker exec $CONTAINER sh -c 'mkdir -p /home/project/www'
- docker exec $CONTAINER sh -c 'setup-nginx.sh symfony4 /home/project/www'
- docker exec $CONTAINER sh -c 'supervisorctl restart nginx php-fpm'
# The front controller (index.php) should be accessible
- docker exec $CONTAINER sh -c 'echo "<?php echo \$_SERVER[\"REQUEST_URI\"];" > /home/project/www/index.php'
- docker exec $CONTAINER sh -c '[ "/" == "$(curl -s http://localhost/)" ]'
- docker exec $CONTAINER sh -c '[ "/example/route" == "$(curl -s http://localhost/example/route)" ]'
# The front controller (index.php) should be not be accessible directly (via localhost/index.php)
- docker exec $CONTAINER sh -c 'echo "<?php echo \$_SERVER[\"REQUEST_URI\"];" > /home/project/www/index.php'
- docker exec $CONTAINER sh -c '[ "404" == "$(curl -s -o /dev/null -w "%{http_code}" http://localhost/index.php)" ]'
# Other PHP files should be not be accessible
- docker exec $CONTAINER sh -c 'echo "<?php \$_SERVER[\"REQUEST_URI\"];" > /home/project/www/example.php'
- docker exec $CONTAINER sh -c '[ "404" == "$(curl -s -o /dev/null -w "%{http_code}" http://localhost/example.php)" ]'
# Real files should be served directly
- docker exec $CONTAINER sh -c 'echo real_file > /home/project/www/real_file'
- docker exec $CONTAINER sh -c '[ "real_file" == "$(curl -s http://localhost/real_file)" ]'
- docker kill $CONTAINER
tags: *tags-defaults-docker
release:
stage: release
image: $CI_REGISTRY/docker/docker:27-cli
services:
- name: $CI_REGISTRY/docker/docker:27-dind
alias: docker
only:
- /^[0-9]+\.[0-9]+\.[0-9]+$/
script:
- docker load --input $TEMP_IMAGE_PATH --quiet
- apk add --no-cache bash git;
docker tag $TEMP_IMAGE $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME;
git clone "$VERSION_TOOL_REPOSITORY" /tmp/version;
VERSIONS="$(git tag --list)";
MAJOR=$(bash /tmp/version/version.sh $CI_COMMIT_REF_NAME MAJOR);
if [ -z "$VERSIONS" ] || [ $(bash /tmp/version/versionhighest.sh "$VERSIONS" $CI_COMMIT_REF_NAME) == 'YES' ]; then
docker tag $TEMP_IMAGE $CI_REGISTRY_IMAGE:php$(cat $META_PHP_VERSION | tr -d '\n');
docker tag $TEMP_IMAGE $CI_REGISTRY_IMAGE:latest;
fi;
VERSIONS_MAJOR=$(echo "$VERSIONS" | grep -E "^$MAJOR\." || echo '');
if [ -z "$VERSIONS_MAJOR" ] || [ $(bash /tmp/version/versionhighest.sh "$VERSIONS_MAJOR" $CI_COMMIT_REF_NAME) == 'YES' ]; then
docker tag $TEMP_IMAGE $CI_REGISTRY_IMAGE:v$MAJOR;
fi;
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push --all-tags $CI_REGISTRY_IMAGE
tags: *tags-defaults-docker