Skip to content

Commit 478331e

Browse files
committed
updated build
- added git files to dockerignore - updated local testing - updated build on branches
1 parent bd956aa commit 478331e

12 files changed

+146
-129
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.git
12
vendor
23
docs

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ phpunit.phar
4141

4242
# NPM packages
4343
/node_modules
44+
.env

.gitlab-ci.yml

+61-50
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,125 @@
11
before_script:
2-
# run docker-compose commands from tests environment
3-
- cd tests
42
# set stack isolation
5-
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}
3+
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}${CI_BUILD_NAME}
64
- export COMPOSE_PROJECT_NAME=${ISOLATION}
75
- export TUPLE_C=$(expr ${CI_BUILD_ID} % 99)
86
- echo ${TUPLE_C}
7+
# run docker-compose commands from tests environment
8+
- cd tests
9+
- cp .env-dist .env
910

1011
after_script:
11-
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}
12+
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}${CI_BUILD_NAME}
13+
- export COMPOSE_PROJECT_NAME=${ISOLATION}
14+
# run docker-compose commands from tests environment
15+
- cd tests
16+
- cp .env-dist .env
17+
- docker-compose down -v --remove-orphans
1218
- docker ps -f name=${ISOLATION}
1319

1420
stages:
15-
- build
21+
- travis
1622
- test
1723
- cleanup
1824

19-
build:
20-
stage: build
21-
script:
22-
- docker-compose build
23-
2425
test:
2526
stage: test
27+
only:
28+
- tests/base
29+
- tests/all
2630
script:
27-
- docker-compose up -d
28-
- docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db
29-
- docker-compose down -v --remove-orphans
31+
- docker-compose up --build -d
32+
- docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db,data --log-junit tests/_junit/test.xml
3033

31-
test:caching:
34+
caching:
3235
stage: test
36+
only:
37+
- tests/caching
38+
- tests/all
3339
script:
34-
- export COMPOSE_PROJECT_NAME=${ISOLATION}caching
35-
- docker-compose up -d
36-
# wait for mysql (retry 30 times)
37-
- docker-compose run --rm php bash -c "while ! curl mysql:3306; do ((c++)) && ((c==30)) && break; sleep 2; done"
38-
- docker-compose run --rm php vendor/bin/phpunit -v --group caching
39-
- docker-compose down -v --remove-orphans
40+
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml
41+
- docker-compose up --build -d
42+
- docker-compose run --rm php vendor/bin/phpunit -v --group caching --exclude db
4043

41-
test:db:
44+
db:
4245
stage: test
46+
only:
47+
- tests/mysql
48+
- tests/all
4349
script:
44-
- export COMPOSE_PROJECT_NAME=${ISOLATION}db
45-
- docker-compose up -d
50+
- docker-compose up --build -d
4651
- docker-compose run --rm php vendor/bin/phpunit -v --group db --exclude caching,mysql,pgsql,mssql,cubrid
4752
- docker-compose down -v --remove-orphans
4853

49-
test:db:mysql:
54+
mysql:
5055
stage: test
56+
only:
57+
- tests/mysql
58+
- tests/all
5159
script:
52-
- export COMPOSE_PROJECT_NAME=${ISOLATION}mysql
53-
- docker-compose up -d
60+
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml
61+
- docker-compose up --build -d
5462
# wait for db (retry X times)
5563
- docker-compose run --rm php bash -c "while ! curl mysql:3306; do ((c++)) && ((c==30)) && break; sleep 2; done"
5664
- docker-compose run --rm php vendor/bin/phpunit -v --group mysql
5765
- docker-compose down -v --remove-orphans
5866

59-
test:db:pgsql:
67+
pgsql:
6068
stage: test
69+
only:
70+
- tests/pgsql
71+
- tests/all
6172
script:
62-
- export COMPOSE_PROJECT_NAME=${ISOLATION}pgsql
63-
- docker-compose up -d
73+
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml
74+
- docker-compose up --build -d
6475
# wait for db (retry X times)
6576
- docker-compose run --rm php bash -c 'while [ true ]; do curl postgres:5432; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==25)) && break; sleep 2; done'
6677
- docker-compose run --rm php vendor/bin/phpunit -v --group pgsql
6778
- docker-compose down -v --remove-orphans
6879

69-
test:db:mssql:
80+
cubrid:
7081
stage: test
7182
only:
72-
- tests/mssql
83+
- tests/cubrid
84+
- tests/all
7385
script:
74-
- cd mssql
75-
- export COMPOSE_PROJECT_NAME=${ISOLATION}mssql
76-
# TODO: retry/wait for db
86+
- cd cubrid
7787
- docker-compose up --build -d
7888
# wait for db (retry X times)
79-
- docker-compose run --rm php bash -c 'while [ true ]; do curl mssql:1433; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==15)) && break; sleep 5; done'
80-
- sleep 10
81-
# Note: Password has to be the last parameter
82-
- docker-compose run --rm sqlcmd sqlcmd -S mssql -U sa -Q "CREATE DATABASE yii2test" -P Mircosoft-12345
83-
- docker-compose run --rm php vendor/bin/phpunit -v --group mssql
89+
- docker-compose run --rm php bash -c 'while [ true ]; do curl cubrid:1523; if [ $? == 56 ]; then break; fi; ((c++)) && ((c==20)) && break; sleep 3; done'
90+
- sleep 5
91+
- docker-compose run --rm php /project/vendor/bin/phpunit -v --group cubrid
8492
- docker-compose down -v --remove-orphans
8593

86-
test:db:cubrid:
94+
mssql:
8795
stage: test
8896
only:
89-
- tests/cubrid
97+
- tests/mssql
98+
- tests/all
9099
script:
91-
- cd cubrid
92-
- export COMPOSE_PROJECT_NAME=${ISOLATION}cubrid
100+
- cd mssql
93101
- docker-compose up --build -d
94102
# wait for db (retry X times)
95-
- docker-compose run --rm php bash -c 'while [ true ]; do curl cubrid:1523; if [ $? == 56 ]; then break; fi; ((c++)) && ((c==20)) && break; sleep 3; done'
96-
- sleep 5
97-
- docker-compose run --rm php /project/vendor/bin/phpunit -v --group cubrid
103+
- docker-compose run --rm php bash -c 'while [ true ]; do curl mssql:1433; if [ $? == 52 ]; then break; fi; ((c++)) && ((c==15)) && break; sleep 5; done'
104+
- sleep 3
105+
# Note: Password has to be the last parameter
106+
- docker-compose run --rm sqlcmd sh -c 'sqlcmd -S mssql -U sa -Q "CREATE DATABASE yii2test" -P Microsoft-12345'
107+
- docker-compose run --rm php vendor/bin/phpunit -v --group mssql
98108
- docker-compose down -v --remove-orphans
99109

100-
test:travis:
101-
stage: test
110+
travis:
111+
stage: travis
102112
only:
103113
- travis
104114
script:
105-
- export COMPOSE_PROJECT_NAME=${ISOLATION}travis
106-
- docker-compose up -d
115+
- export COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml:docker-compose.pgsql.yml
116+
- docker-compose up --build -d
107117
# TODO: retry/wait for db
108118
- sleep 10
109119
- docker-compose run --rm php vendor/bin/phpunit -v --exclude mssql,cubrid,oci,wincache,xcache,zenddata,cubrid
110120
- docker-compose down -v --remove-orphans
111121

122+
# temporary cleanup stage
112123
cleanup:
113124
stage: cleanup
114125
when: always

Dockerfile

+2-39
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,8 @@
1-
FROM codemix/yii2-base:2.0-apache
2-
3-
# Install system packages for PHP extensions recommended for Yii 2.0 Framework
4-
RUN apt-key update && \
5-
apt-get update && \
6-
apt-get -y install \
7-
g++ \
8-
git \
9-
libicu-dev \
10-
libmcrypt-dev \
11-
libfreetype6-dev \
12-
libjpeg-dev \
13-
libjpeg62-turbo-dev \
14-
libmcrypt-dev \
15-
libpng12-dev \
16-
libpq5 \
17-
libpq-dev \
18-
zlib1g-dev \
19-
mysql-client \
20-
openssh-client \
21-
libxml2-dev \
22-
--no-install-recommends && \
23-
apt-get clean && \
24-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
25-
26-
# Install PHP extensions required for Yii 2.0 Framework
27-
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ && \
28-
docker-php-ext-configure bcmath && \
29-
docker-php-ext-install \
30-
gd \
31-
intl \
32-
pdo_mysql \
33-
pdo_pgsql \
34-
mbstring \
35-
mcrypt \
36-
zip \
37-
bcmath \
38-
soap
39-
1+
FROM dmstr/php-yii2:7.0-fpm-1.9-beta2-alpine-nginx
402

413
# Project source-code
424
WORKDIR /project
435
ADD composer.* /project/
446
RUN /usr/local/bin/composer install --prefer-dist
457
ADD ./ /project
8+
ENV PATH /project/vendor/bin:${PATH}

Dockerfile-mssql

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
FROM bylexus/apache-php7
22

3+
34
# https://www.microsoft.com/en-us/sql-server/developer-get-started/php-ubuntu
45
RUN apt-get update
56
RUN apt-get install -y curl apt-transport-https
67

78
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
89
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
910

10-
RUN apt-get update
11-
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
12-
RUN apt-get install -y unixodbc-dev-utf16
13-
14-
RUN apt-get install -y php-dev
15-
RUN pecl install sqlsrv pdo_sqlsrv
11+
RUN apt-get update \
12+
&& apt-get install -y unixodbc-dev-utf16 php-dev \
13+
&& pecl install sqlsrv pdo_sqlsrv
1614

1715
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
1816
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
1917
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/cli/php.ini
2018
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/cli/php.ini
2119

22-
# TODO: temporary section --->
20+
# IMPORTANT NOTICE! Install `msodbcsql` after `unixodbc-dev-utf16` and `pdo_sqlsrv`, due to dependency & build issues
21+
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
22+
2323
# Install system packages for composer (git)
2424
RUN apt-get update && \
2525
apt-get -y install \
2626
git \
27+
php-curl \
2728
--no-install-recommends && \
28-
apt-get clean && \
29-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
29+
rm -rf /tmp/* /var/tmp/*
3030
# Register the COMPOSER_HOME environment variable
3131
ENV COMPOSER_HOME /composer
3232
# Add global binary directory to PATH and make sure to re-export it
@@ -37,7 +37,8 @@ ENV COMPOSER_ALLOW_SUPERUSER 1
3737
RUN curl -sS https://getcomposer.org/installer | php -- \
3838
--filename=composer.phar \
3939
--install-dir=/usr/local/bin
40-
# TODO: <--- end
40+
RUN composer.phar global require --optimize-autoloader \
41+
"hirak/prestissimo"
4142

4243

4344
# Project source-code
@@ -49,4 +50,7 @@ ADD ./ /project
4950
# https://github.com/Microsoft/msphpsql/issues/161
5051
RUN apt-get install -y locales \
5152
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
52-
&& locale-gen
53+
&& locale-gen
54+
55+
# Debug installation
56+
RUN dpkg -L msodbcsql

tests/.env-dist

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# docker-compose test environment
2+
3+
# Choose a flavour
4+
#COMPOSE_FILE=docker-compose.yml:docker-compose.caching.yml
5+
#COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml
6+
#COMPOSE_FILE=docker-compose.yml:docker-compose.postgres.yml
7+
8+
# Choose a version
9+
DOCKER_MYSQL_IMAGE=percona:5.7
10+
DOCKER_POSTGRES_IMAGE=postgres

tests/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Create database with sqlcmd
103103

104104
Create database (one-liner)
105105

106-
docker-compose run --rm sqlcmd sqlcmd -S mssql -U sa -P Mircosoft-12345 -Q "CREATE DATABASE yii2test"
106+
docker-compose run --rm sqlcmd sqlcmd -S mssql -U sa -P Microsoft-12345 -Q "CREATE DATABASE yii2test"
107107

108108
Run MSSQL tests
109109

tests/docker-compose.caching.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '2'
2+
services:
3+
4+
php:
5+
depends_on:
6+
- redis
7+
- memcached
8+
9+
redis:
10+
image: redis
11+
12+
memcached:
13+
image: memcached

tests/docker-compose.mysql.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '2'
2+
services:
3+
4+
php:
5+
depends_on:
6+
- mysql
7+
8+
mysql:
9+
image: ${DOCKER_MYSQL_IMAGE}
10+
environment:
11+
- MYSQL_ROOT_PASSWORD=secret
12+
- MYSQL_DATABASE=yiitest
13+
- MYSQL_USER=travis
14+
- MYSQL_PASSWORD=travis
15+

tests/docker-compose.pgsql.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '2'
2+
3+
services:
4+
5+
php:
6+
depends_on:
7+
- postgres
8+
9+
postgres:
10+
image: ${DOCKER_POSTGRES_IMAGE}
11+
environment:
12+
- POSTGRES_DB=yiitest
13+
- POSTGRES_USER=postgres
14+
- POSTGRES_PASSWORD=postgres

0 commit comments

Comments
 (0)