Skip to content

Commit

Permalink
Add docker support (egeloen#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeLoLabs authored Feb 4, 2017
1 parent 90d3bab commit 0f2b3d8
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
IDE_SERVER_NAME=ivory-ordered-form
GROUP_ID=1000
USER_ID=1000
SYMFONY_DEPRECATIONS_HELPER=strict
XDEBUG=0
XDEBUG_HOST=192.168.0.1
XDEBUG_PORT=9000
XDEBUG_IDEKEY=PHPSTORM
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/docker export-ignore
/tests export-ignore
/.env.dist export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
CONTRIBUTING.md export-ignore
docker-compose.yml export-ignore
phpunit.xml.dist export-ignore
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/composer.lock
/vendor

# Docker
/.env

# PHP CS Fixer
/.php_cs.cache

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ matrix:
- php: 5.6
env: SYMFONY_VERSION=2.6.*
- php: 5.6
env: SYMFONY_VERSION=2.7.*
env: SYMFONY_VERSION=2.7.* SYMFONY_DEPRECATIONS_HELPER=strict
- php: 5.6
env: SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=strict
- php: 5.6
Expand Down
13 changes: 2 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ $ git clone [email protected]:your-name/ivory-ordered-form.git
$ git checkout -b bug-fix-description
```

Then, install the dependencies through [Composer](https://getcomposer.org/):

``` bash
$ composer install
```
Then, we recommend to use [Docker](https://www.docker.com) and follow this [instructions](/doc/docker.md) in order to
set up the project.

When you're on the new branch with the dependencies, code as much as you want and when the fix is ready, don't commit
it immediately. Before, you will need to add tests and update the doc. For the tests, everything is tested with
[PHPUnit](http://phpunit.de/) and the doc is in the markdown format under the `doc` directory.

To run the tests, use the following command:

``` bash
$ vendor/bin/phpunit
```

Then, when you have fixed the bug, tested it and documented it, you can commit and push it with the following commands:

``` bash
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ execute the test suite, check the travis [configuration](/.travis.yml).

## Contribute

We love contributors! Ivory is an open source project. If you'd like to contribute, feel free to propose a PR!
We love contributors! Ivory is an open source project. If you'd like to contribute, feel free to propose a PR! You
can follow the [CONTRIBUTING](/CONTRIBUTING.md) file which will explain you how to set up the project.

## License

Expand Down
47 changes: 47 additions & 0 deletions doc/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Docker

The most easy way to set up the project is to install [Docker](https://www.docker.com) and
[Docker Composer](https://docs.docker.com/compose/) and build the project.

## Configure

The configuration is shipped with a distribution environment file allowing you to customize your IDE and XDebug
settings as well as your current user/group ID:

``` bash
$ cp .env.dist .env
```

**The most important part is the `USER_ID` and `GROUP_ID` which should match your current user/group.**

## Build

Once you have configured your environment, you can build the project:

``` bash
$ docker-compose build
```

## Composer

Install the dependencies via [Composer](https://getcomposer.org/):

``` bash
$ docker-compose run --rm php composer install
```

## Tests

To run the test suite, you can use:

``` bash
$ docker-compose run --rm php vendor/bin/phpunit
```

## XDebug

If you want to use XDebug, make sure you have fully configured your `.env` file and use:

``` bash
$ docker-compose run --rm -e XDEBUG=1 php vendor/bin/phpunit
```
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '2'

services:
php:
build: docker
environment:
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
SYMFONY_DEPRECATIONS_HELPER: ${SYMFONY_DEPRECATIONS_HELPER}
XDEBUG: ${XDEBUG}
XDEBUG_CONFIG: remote_host=${XDEBUG_HOST} remote_port=${XDEBUG_PORT} idekey=${XDEBUG_IDEKEY}
PHP_IDE_CONFIG: serverName=${IDE_SERVER_NAME}
volumes:
- ~/.composer:/var/www/.composer
- .:/var/www/html
27 changes: 27 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM php:latest

# APT packages
RUN apt-get update && apt-get install -y \
zlib1g-dev \
git \
&& rm -rf /var/lib/apt/lists/*

# PHP extensions
RUN docker-php-ext-install zip

# XDebug extensions
RUN pecl install xdebug && rm -rf /tmp/pear
COPY config/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

# Bash
RUN chsh -s /bin/bash www-data

# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --filename=composer --install-dir=/usr/local/bin

# Workdir
WORKDIR /var/www/html

# Entrypoint
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
3 changes: 3 additions & 0 deletions docker/config/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so"
xdebug.cli_color=1
xdebug.remote_enable=1
23 changes: 23 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e

GROUP_ID=${GROUP_ID-1000}
USER_ID=${USER_ID-1000}
XDEBUG=${XDEBUG-0}

# Disable XDebug
if [ ! ${XDEBUG} = 1 ]; then
rm -f /usr/local/etc/php/conf.d/xdebug.ini
fi

# Permissions
groupmod -g ${GROUP_ID} www-data
usermod -u ${USER_ID} www-data

# Start bash or forward command
if [ $1 = "bash" ]; then
su www-data
else
su www-data -c "$*"
fi

0 comments on commit 0f2b3d8

Please sign in to comment.