Skip to content
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

Merged
merged 25 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5ab85c
updated debug settings (+56 squashed commits)
schmunk42 Jan 10, 2017
cc1f398
updated docs
schmunk42 Jan 19, 2017
8893eca
fixed cleanup
schmunk42 Jan 19, 2017
25cc36c
fixed network setup
schmunk42 Jan 19, 2017
4db2ff9
fixed tuple
schmunk42 Jan 19, 2017
b6d14ca
Merge commit '3f66fb6cdfd498a119bfb34562549d07ff2ff9e0' into feature/…
schmunk42 Jan 20, 2017
bd956aa
run cubrid only on branch tests/cubrid
schmunk42 Jan 20, 2017
478331e
updated build
schmunk42 Jan 20, 2017
7718868
Merge commit 'd4d6c1dabf555e6f14a668df6fcc515bceef2830' into feature/…
schmunk42 Jan 24, 2017
3bcbee3
updated build branches
schmunk42 Jan 24, 2017
3f2eaf0
Merge branch 'feature/docker-testing' into 'tests/mysql'
Jan 24, 2017
0a4fdf2
Merge commit '95b7ffc066c03f2510ef4e6681e1ddf1494e916f' into feature/…
schmunk42 Feb 9, 2017
7b43cf0
added separate docker config for testing
schmunk42 Feb 9, 2017
0dd1ed6
use custom docker config in dockerized tests
schmunk42 Feb 9, 2017
f96ea4c
removed TODOs
schmunk42 Feb 9, 2017
4e29c44
cleaned cleanup (done in after_script)
schmunk42 Feb 16, 2017
7a4666f
added build trigger example
schmunk42 Feb 16, 2017
ec8daa0
added db group to test
schmunk42 Feb 16, 2017
dc356fb
Merge branch 'feature/docker-testing' into tests/mysql
schmunk42 Feb 16, 2017
9f95f71
added groups to tests
schmunk42 Feb 16, 2017
2fad692
Merge commit '22972b86dbcc6e010dc90df921090e713521f0b9' into feature/…
schmunk42 Feb 16, 2017
0e0caef
Merge branch 'tests/mysql' into feature/docker-testing
schmunk42 Feb 16, 2017
acf7c85
moved Dockerfile(s) to test folders
schmunk42 Mar 6, 2017
a1fd4d3
updated changelog
schmunk42 Mar 6, 2017
ff4cde1
Merge branch 'master' into feature/docker-testing
cebe Mar 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
vendor
docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ phpunit.phar

# NPM packages
/node_modules
.env
118 changes: 118 additions & 0 deletions .gitlab-ci.yml
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
Copy link
Member

@SilverFire SilverFire Feb 11, 2017

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?

Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link

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 since run always starts a new container which otherwise will be left behind on the Docker host.

Copy link
Member

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 and exec. Thank you @schmunk42


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,oci


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


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


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


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


travis:
stage: travis
only:
- travis
script:
- export COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml:docker-compose.pgsql.yml
- docker-compose up --build -d
# wait for dbs ...
- sleep 10
- docker-compose run --rm php vendor/bin/phpunit -v --exclude mssql,cubrid,oci,wincache,xcache,zenddata,cubrid

8 changes: 8 additions & 0 deletions Dockerfile
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
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
We could also clone or download the current commit when building an image, but that would be annoying in development.

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.

Copy link
Member

Choose a reason for hiding this comment

The 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. cp tests/docker/Dockerfile-mysql Dockerfile and then run docker-compose, so that they are not located in the repo root but are moved to repo root when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a way :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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}
Loading