-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added dockerized test setup #13360
added dockerized test setup #13360
Changes from 10 commits
f5ab85c
cc1f398
8893eca
25cc36c
4db2ff9
b6d14ca
bd956aa
478331e
7718868
3bcbee3
3f2eaf0
0a4fdf2
7b43cf0
0dd1ed6
f96ea4c
4e29c44
7a4666f
ec8daa0
dc356fb
9f95f71
2fad692
0e0caef
acf7c85
a1fd4d3
ff4cde1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.git | ||
vendor | ||
docs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,4 @@ phpunit.phar | |
|
||
# NPM packages | ||
/node_modules | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
before_script: | ||
# set stack isolation | ||
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}${CI_BUILD_NAME} | ||
- export COMPOSE_PROJECT_NAME=${ISOLATION} | ||
- export TUPLE_C=$(expr ${CI_BUILD_ID} % 99) | ||
- echo ${TUPLE_C} | ||
# run docker-compose commands from tests environment | ||
- cd tests | ||
- cp .env-dist .env | ||
- docker-compose config | ||
|
||
after_script: | ||
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}${CI_BUILD_NAME} | ||
- export COMPOSE_PROJECT_NAME=${ISOLATION} | ||
# run docker-compose commands from tests environment | ||
- cd tests | ||
- cp .env-dist .env | ||
- docker-compose down -v --remove-orphans | ||
- docker ps -f name=${ISOLATION} | ||
|
||
stages: | ||
- travis | ||
- test | ||
- cleanup | ||
|
||
test: | ||
stage: test | ||
script: | ||
- docker-compose up --build -d | ||
- docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db,data --log-junit tests/_junit/test.xml | ||
|
||
caching: | ||
stage: test | ||
only: | ||
- tests/caching | ||
- tests/full | ||
script: | ||
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml | ||
- docker-compose up --build -d | ||
- docker-compose run --rm php vendor/bin/phpunit -v --group caching --exclude db | ||
|
||
db: | ||
stage: test | ||
only: | ||
- tests/mysql | ||
- tests/full | ||
script: | ||
- docker-compose up --build -d | ||
- docker-compose run --rm php vendor/bin/phpunit -v --group db --exclude caching,mysql,pgsql,mssql,cubrid | ||
- docker-compose down -v --remove-orphans | ||
|
||
mysql: | ||
stage: test | ||
only: | ||
- tests/mysql | ||
- tests/full | ||
script: | ||
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml | ||
- docker-compose up --build -d | ||
# wait for db (retry X times) | ||
- docker-compose run --rm php bash -c "while ! curl mysql:3306; do ((c++)) && ((c==30)) && break; sleep 2; done" | ||
- docker-compose run --rm php vendor/bin/phpunit -v --group mysql | ||
- docker-compose down -v --remove-orphans | ||
|
||
pgsql: | ||
stage: test | ||
only: | ||
- tests/pgsql | ||
- tests/full | ||
script: | ||
- export COMPOSE_FILE=docker-compose.yml:docker-compose.${CI_BUILD_NAME}.yml | ||
- docker-compose up --build -d | ||
# wait for db (retry X times) | ||
- 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' | ||
- docker-compose run --rm php vendor/bin/phpunit -v --group pgsql | ||
- docker-compose down -v --remove-orphans | ||
|
||
cubrid: | ||
stage: test | ||
only: | ||
- tests/cubrid | ||
- tests/extra | ||
script: | ||
- cd cubrid | ||
- docker-compose up --build -d | ||
# wait for db (retry X times) | ||
- 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' | ||
- sleep 5 | ||
- docker-compose run --rm php /project/vendor/bin/phpunit -v --group cubrid | ||
- docker-compose down -v --remove-orphans | ||
|
||
mssql: | ||
stage: test | ||
only: | ||
- tests/mssql | ||
- tests/extra | ||
script: | ||
- cd mssql | ||
- docker-compose up --build -d | ||
# wait for db (retry X times) | ||
- 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' | ||
- sleep 3 | ||
# Note: Password has to be the last parameter | ||
- docker-compose run --rm sqlcmd sh -c 'sqlcmd -S mssql -U sa -Q "CREATE DATABASE yii2test" -P Microsoft-12345' | ||
- docker-compose run --rm php vendor/bin/phpunit -v --group mssql | ||
- docker-compose down -v --remove-orphans | ||
|
||
travis: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this have to do with travis? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed, thanks. |
||
stage: travis | ||
only: | ||
- travis | ||
script: | ||
- export COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml:docker-compose.pgsql.yml | ||
- docker-compose up --build -d | ||
# TODO: retry/wait for db | ||
- sleep 10 | ||
- docker-compose run --rm php vendor/bin/phpunit -v --exclude mssql,cubrid,oci,wincache,xcache,zenddata,cubrid | ||
- docker-compose down -v --remove-orphans |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM dmstr/php-yii2:7.0-fpm-1.9-beta2-alpine-nginx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to move the DockerFiles to some dir in tests/ ? if they need to be located in repo root I would prefer copying them from test folder here before starting docker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would imply that we use another way of getting the framework source-code onto the image, because a Dockerfile defines the build context and you can not add something from outside the build context. An option is to use host-volumes, but they can problematic regarding performance and other things. I also don't like it, that these files are in the root folder, but it was the best option to me for now. I am open for discussion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about moving the Dockerfile in the build script, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a way :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the one in the root folder could become kind of an official image, I am working with @mikehaertl on something similar. Or should this be moved to tests also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is fine like this now. |
||
|
||
# Project source-code | ||
WORKDIR /project | ||
ADD composer.* /project/ | ||
RUN /usr/local/bin/composer install --prefer-dist | ||
ADD ./ /project | ||
ENV PATH /project/vendor/bin:${PATH} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM php:5-fpm | ||
|
||
# /usr/local/lib/php/extensions/no-debug-non-zts-20131226/cubrid.so | ||
RUN pecl install pdo_cubrid-9.3.0.0001 | ||
RUN echo "extension=pdo_cubrid.so" > /usr/local/etc/php/conf.d/cubrid.ini | ||
|
||
|
||
# TODO: temporary section ---> | ||
# Install system packages for composer (git) | ||
RUN apt-get update && \ | ||
apt-get -y install \ | ||
git \ | ||
--no-install-recommends && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
# Register the COMPOSER_HOME environment variable | ||
ENV COMPOSER_HOME /composer | ||
# Add global binary directory to PATH and make sure to re-export it | ||
ENV PATH /usr/local/bin:$PATH | ||
# Allow Composer to be run as root | ||
ENV COMPOSER_ALLOW_SUPERUSER 1 | ||
# Install composer | ||
RUN curl -sS https://getcomposer.org/installer | php -- \ | ||
--filename=composer.phar \ | ||
--install-dir=/usr/local/bin | ||
# TODO: <--- end | ||
|
||
# Project source-code | ||
WORKDIR /project | ||
ADD composer.* /project/ | ||
RUN /usr/local/bin/composer.phar install --prefer-dist | ||
ADD ./ /project |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
FROM bylexus/apache-php7 | ||
|
||
|
||
# https://www.microsoft.com/en-us/sql-server/developer-get-started/php-ubuntu | ||
RUN apt-get update | ||
RUN apt-get install -y curl apt-transport-https | ||
|
||
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - | ||
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y unixodbc-dev-utf16 php-dev \ | ||
&& pecl install sqlsrv pdo_sqlsrv | ||
|
||
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini | ||
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini | ||
RUN echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/cli/php.ini | ||
RUN echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/cli/php.ini | ||
|
||
# IMPORTANT NOTICE! Install `msodbcsql` after `unixodbc-dev-utf16` and `pdo_sqlsrv`, due to dependency & build issues | ||
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql | ||
|
||
# Install system packages for composer (git) | ||
RUN apt-get update && \ | ||
apt-get -y install \ | ||
git \ | ||
php-curl \ | ||
--no-install-recommends && \ | ||
rm -rf /tmp/* /var/tmp/* | ||
# Register the COMPOSER_HOME environment variable | ||
ENV COMPOSER_HOME /composer | ||
# Add global binary directory to PATH and make sure to re-export it | ||
ENV PATH /usr/local/bin:$PATH | ||
# Allow Composer to be run as root | ||
ENV COMPOSER_ALLOW_SUPERUSER 1 | ||
# Install composer | ||
RUN curl -sS https://getcomposer.org/installer | php -- \ | ||
--filename=composer.phar \ | ||
--install-dir=/usr/local/bin | ||
RUN composer.phar global require --optimize-autoloader \ | ||
"hirak/prestissimo" | ||
|
||
|
||
# Project source-code | ||
WORKDIR /project | ||
ADD composer.* /project/ | ||
RUN /usr/local/bin/composer.phar install --prefer-dist | ||
ADD ./ /project | ||
|
||
# https://github.com/Microsoft/msphpsql/issues/161 | ||
RUN apt-get install -y locales \ | ||
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \ | ||
&& locale-gen | ||
|
||
# Debug installation | ||
RUN dpkg -L msodbcsql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--rm
option is redundant when container was started in background (docker-compose up -d
). Or I am missing something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
starting in the background is
-d
, removing the container after it has been stopped is--rm
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line I've commented has -rm argument, that according to the docs should remove container after the command execution, but ONLY when the container is NOT running in the background.
Line above (docker-compose up --build -d) stars container in background.
Does is make any sense to pass --rm flag for the RUN command in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are actually two containers running in line 30. The one in the background (webserver) and the actual run process which does the testing.
I'd say you usually (depends on the use-case) run
run
with--rm
, I does not really matter in the CI, but it should be cleaner in general, see also docker/compose#943@mikehaertl @motin WDYT?
PS: Cleanup is actually done in
after_script
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good practice and relevant in this case to clean up with "--rm" when using
run
sincerun
always starts a new container which otherwise will be left behind on the Docker host.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have mixed up
run
andexec
. Thank you @schmunk42