Skip to content

Commit

Permalink
Build image in dockerized tests with BUILD_ARG (yiisoft#15559)
Browse files Browse the repository at this point in the history
* added build argument for Yii 2.0 PHP base image version
- streamlined build
- dropped network config for CI
- updated local test script

* added default for PHP (7.2) image on GitLab CI

* use PHP 7.1 as a default on GitLab CI, see yiisoft#15512
  • Loading branch information
schmunk42 authored and samdark committed Feb 5, 2018
1 parent a42bbd8 commit b9fc1f3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
- docker:dind

variables:
DOCKER_YII2_PHP_IMAGE: yiisoftware/yii2-php:7.1-apache
DOCKER_MYSQL_IMAGE: percona:5.7
DOCKER_POSTGRES_IMAGE: postgres:9.3

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM yiisoftware/yii2-php:7.1-apache
ARG DOCKER_YII2_PHP_IMAGE
FROM ${DOCKER_YII2_PHP_IMAGE}

# Project source-code
WORKDIR /project
Expand Down
1 change: 1 addition & 0 deletions tests/.env-dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
COMPOSE_FILE=docker-compose.yml:docker-compose.mysql.yml:docker-compose.pgsql.yml:docker-compose.caching.yml

# Image versions
DOCKER_YII2_PHP_IMAGE=yiisoftware/yii2-php:7.2-apache
DOCKER_MYSQL_IMAGE=percona:5.7
DOCKER_POSTGRES_IMAGE=postgres
13 changes: 4 additions & 9 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ version: '2'
services:

php:
build: ..
build:
context: ..
args:
DOCKER_YII2_PHP_IMAGE: ${DOCKER_YII2_PHP_IMAGE}
working_dir: /project
volumes:
- ../tests/data/config-docker.php:/project/tests/data/config.php
Expand All @@ -14,11 +17,3 @@ services:
# - /project/tests/runtime
environment:
- TEST_RUNTIME_PATH=/tmp/runtime

networks:
default:
ipam:
driver: default
config:
# prevent overlapping/duplicated networks, since docker assigns /16 subnets by default ranging from 10.x over 172.x to 192.168.x
- subnet: 10.100.1${TUPLE_C}.1/24
14 changes: 2 additions & 12 deletions tests/test-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ export CI_PIPELINE_ID=${1}
case $1 in
'default')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
export COMPOSE_PROJECT_NAME=${ISOLATION}default
docker-compose up -d
docker-compose run --rm php vendor/bin/phpunit -v --exclude caching,db
docker-compose down -v
;;
'caching')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
export COMPOSE_PROJECT_NAME=${ISOLATION}caching
docker-compose up -d
docker-compose run --rm php bash -c "while ! curl mysql:3306; do ((c++)) && ((c==30)) && break; sleep 2; done"
Expand All @@ -29,9 +24,7 @@ case $1 in
;;
'mssql')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
export COMPOSE_PROJECT_NAME=${ISOLATION}mssql
cd mssql
docker-compose up --build -d
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'
Expand All @@ -48,9 +41,6 @@ case $1 in
;;
'pgsql')
export ISOLATION=buildpipeline${CI_PIPELINE_ID}
export COMPOSE_PROJECT_NAME=${ISOLATION}
export TUPLE_C=$(expr ${CI_BUILD_ID} % 255)
echo ${TUPLE_C}
export COMPOSE_PROJECT_NAME=${ISOLATION}pgsql
docker-compose up -d
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'
Expand Down

0 comments on commit b9fc1f3

Please sign in to comment.