Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Incorporated suggestions from @thomasvargiu for Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Apr 22, 2018
1 parent a6b1272 commit 32cec04
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
3 changes: 0 additions & 3 deletions .travis.docker

This file was deleted.

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ matrix:
env:
- DEPS=latest
- MONGO_DRIVER=mongodb
- PHP_VERSION=7.1
- DOCKER=true
- php: 7.2
env:
- DEPS=lowest
Expand All @@ -74,7 +76,6 @@ matrix:

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $DOCKER == 'true' ]]; then docker-compose up -d; fi

install:
- yes '' | pecl -q install -f $MONGO_DRIVER
Expand Down
17 changes: 1 addition & 16 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,12 @@ To connect to the php container and run the unit tests
run

```
docker/connect
docker-compose run php bash
```

You will connect to the php container a the root directory.
`cd` to `docker` to work with the mapped local files.


## Configuration

Because you're in a Docker environment with a differnet IP address and name for each
container you need to either change the config files in the project to point to `mongo`
or with a simple hack map `localhost` to the `mongo` container.

* To edit the config file to point to the `mongo` container instead of `localhost` edit
`test/config/ODM/local.php` and change the configuration.

* Optionally you can map localhost to mongo with
```
echo `host mongo` | awk '{print $4, "localhost"}' > /etc/hosts
```

## Unit Tests

Having run `composer install` you may now run the unit tests
Expand Down
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ services:
php:
build:
context: .
args:
- PHP_VERSION=${PHP_VERSION:-7.2}
dockerfile: docker/Dockerfile
links:
depends_on:
- mongo
ports:
- "9000:9000"
volumes:
- ./:/docker
tty: true
environment:
- MONGO_HOST=mongo
- MONGO_PORT=27017

mongo:
image: mongo:latest
33 changes: 23 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
FROM php:latest
RUN apt-get update
RUN apt-get --yes install vim
RUN apt-get --yes install git
RUN apt-get --yes install inetutils-ping
RUN apt-get --yes install host
ARG PHP_VERSION=7.2
FROM php:${PHP_VERSION}-alpine

RUN apk add --no-cache \
autoconf \
make \
g++ \
bash

RUN pecl install mongodb && docker-php-ext-enable mongodb
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /bin/composer
RUN set -o pipefail && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN echo -e '#!/bin/sh' > /usr/local/bin/entrypoint.sh \
&& echo -e 'while ! nc -z ${MONGO_HOST:-mongo} ${MONGO_PORT:-27017}; do sleep 1; done' >> /usr/local/bin/entrypoint.sh \
&& echo -e 'exec "$@"' >> /usr/local/bin/entrypoint.sh \
&& chmod +x /usr/local/bin/entrypoint.sh
WORKDIR /docker
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["./vendor/bin/phpunit"]

# RUN apt-get update
# RUN apt-get --yes install vim
# RUN apt-get --yes install git
# RUN apt-get --yes install inetutils-ping
# RUN apt-get --yes install host
4 changes: 2 additions & 2 deletions test/config/ODM/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
'doctrine' => [
'connection' => [
'odm_default' => [
'server' => 'localhost',
'port' => '27017',
'server' => (getenv('MONGO_HOST')) ? getenv('MONGO_HOST') : 'localhost',
'port' => (getenv('MONGO_PORT')) ? getenv('MONGO_PORT') : '27017',
'user' => '',
'password' => '',
'dbname' => 'zf_apigility_doctrine_server_test',
Expand Down

0 comments on commit 32cec04

Please sign in to comment.