Navigation Menu

Skip to content

Commit

Permalink
updated build
Browse files Browse the repository at this point in the history
- added git files to dockerignore
- updated local testing
- updated build on branches
  • Loading branch information
schmunk42 committed Jan 24, 2017
1 parent bd956aa commit 478331e
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 129 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -1,2 +1,3 @@
.git
vendor
docs
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -41,3 +41,4 @@ phpunit.phar

# NPM packages
/node_modules
.env
111 changes: 61 additions & 50 deletions .gitlab-ci.yml
@@ -1,114 +1,125 @@
before_script:
# run docker-compose commands from tests environment
- cd tests
# set stack isolation
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}
- 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

after_script:
- export ISOLATION=buildpipeline${CI_PIPELINE_ID}
- 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:
- build
- travis
- test
- cleanup

build:
stage: build
script:
- docker-compose build

test:
stage: test
only:
- tests/base
- tests/all
script:
- docker-compose up -d
- docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db
- docker-compose down -v --remove-orphans
- docker-compose up --build -d
- docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db,data --log-junit tests/_junit/test.xml

test:caching:
caching:
stage: test
only:
- tests/caching
- tests/all
script:
- export COMPOSE_PROJECT_NAME=${ISOLATION}caching
- docker-compose up -d
# wait for mysql (retry 30 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 caching
- docker-compose down -v --remove-orphans
- 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

test:db:
db:
stage: test
only:
- tests/mysql
- tests/all
script:
- export COMPOSE_PROJECT_NAME=${ISOLATION}db
- docker-compose up -d
- 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

test:db:mysql:
mysql:
stage: test
only:
- tests/mysql
- tests/all
script:
- export COMPOSE_PROJECT_NAME=${ISOLATION}mysql
- docker-compose up -d
- 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

test:db:pgsql:
pgsql:
stage: test
only:
- tests/pgsql
- tests/all
script:
- export COMPOSE_PROJECT_NAME=${ISOLATION}pgsql
- docker-compose up -d
- 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

test:db:mssql:
cubrid:
stage: test
only:
- tests/mssql
- tests/cubrid
- tests/all
script:
- cd mssql
- export COMPOSE_PROJECT_NAME=${ISOLATION}mssql
# TODO: retry/wait for db
- cd cubrid
- 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 10
# Note: Password has to be the last parameter
- docker-compose run --rm sqlcmd sqlcmd -S mssql -U sa -Q "CREATE DATABASE yii2test" -P Mircosoft-12345
- docker-compose run --rm php vendor/bin/phpunit -v --group mssql
- 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

test:db:cubrid:
mssql:
stage: test
only:
- tests/cubrid
- tests/mssql
- tests/all
script:
- cd cubrid
- export COMPOSE_PROJECT_NAME=${ISOLATION}cubrid
- cd mssql
- 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 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

test:travis:
stage: test
travis:
stage: travis
only:
- travis
script:
- export COMPOSE_PROJECT_NAME=${ISOLATION}travis
- docker-compose up -d
- 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

# temporary cleanup stage
cleanup:
stage: cleanup
when: always
Expand Down
41 changes: 2 additions & 39 deletions Dockerfile
@@ -1,45 +1,8 @@
FROM codemix/yii2-base:2.0-apache

# Install system packages for PHP extensions recommended for Yii 2.0 Framework
RUN apt-key update && \
apt-get update && \
apt-get -y install \
g++ \
git \
libicu-dev \
libmcrypt-dev \
libfreetype6-dev \
libjpeg-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libpq5 \
libpq-dev \
zlib1g-dev \
mysql-client \
openssh-client \
libxml2-dev \
--no-install-recommends && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install PHP extensions required for Yii 2.0 Framework
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ && \
docker-php-ext-configure bcmath && \
docker-php-ext-install \
gd \
intl \
pdo_mysql \
pdo_pgsql \
mbstring \
mcrypt \
zip \
bcmath \
soap

FROM dmstr/php-yii2:7.0-fpm-1.9-beta2-alpine-nginx

# Project source-code
WORKDIR /project
ADD composer.* /project/
RUN /usr/local/bin/composer install --prefer-dist
ADD ./ /project
ENV PATH /project/vendor/bin:${PATH}
26 changes: 15 additions & 11 deletions Dockerfile-mssql
@@ -1,32 +1,32 @@
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
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql
RUN apt-get install -y unixodbc-dev-utf16

RUN apt-get install -y php-dev
RUN pecl install sqlsrv pdo_sqlsrv
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

# TODO: temporary section --->
# 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 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
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
Expand All @@ -37,7 +37,8 @@ ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer.phar \
--install-dir=/usr/local/bin
# TODO: <--- end
RUN composer.phar global require --optimize-autoloader \
"hirak/prestissimo"


# Project source-code
Expand All @@ -49,4 +50,7 @@ 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
&& locale-gen

# Debug installation
RUN dpkg -L msodbcsql
10 changes: 10 additions & 0 deletions tests/.env-dist
@@ -0,0 +1,10 @@
# docker-compose test environment

# Choose a flavour
#COMPOSE_FILE=docker-compose.yml:docker-compose.caching.yml
#COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml
#COMPOSE_FILE=docker-compose.yml:docker-compose.postgres.yml

# Choose a version
DOCKER_MYSQL_IMAGE=percona:5.7
DOCKER_POSTGRES_IMAGE=postgres
2 changes: 1 addition & 1 deletion tests/README.md
Expand Up @@ -103,7 +103,7 @@ Create database with sqlcmd

Create database (one-liner)

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

Run MSSQL tests

Expand Down
13 changes: 13 additions & 0 deletions tests/docker-compose.caching.yml
@@ -0,0 +1,13 @@
version: '2'
services:

php:
depends_on:
- redis
- memcached

redis:
image: redis

memcached:
image: memcached
15 changes: 15 additions & 0 deletions tests/docker-compose.mysql.yml
@@ -0,0 +1,15 @@
version: '2'
services:

php:
depends_on:
- mysql

mysql:
image: ${DOCKER_MYSQL_IMAGE}
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=yiitest
- MYSQL_USER=travis
- MYSQL_PASSWORD=travis

14 changes: 14 additions & 0 deletions tests/docker-compose.pgsql.yml
@@ -0,0 +1,14 @@
version: '2'

services:

php:
depends_on:
- postgres

postgres:
image: ${DOCKER_POSTGRES_IMAGE}
environment:
- POSTGRES_DB=yiitest
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

0 comments on commit 478331e

Please sign in to comment.