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

Add Docker support #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:major: 1
:minor: 2
:patch: 1
:minor: 3
:patch: 0
:special: ''
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ It could be useful if you want to start from scratch a kata or a little exercise

## How To Start

You have 2 different alternatives: Using our [Packagist project](https://packagist.org/packages/codelytv/php-bootstrap) with Composer, or manually cloning [this repo](https://github.com/CodelyTV/php-bootstrap/):
You have 3 different alternatives: Using our [Packagist project](https://packagist.org/packages/codelytv/php-bootstrap) with Composer, manually cloning [this repo](https://github.com/CodelyTV/php-bootstrap/)
or using Docker:

### Using Composer

Expand Down Expand Up @@ -67,6 +68,25 @@ Just in case you prefer to avoid dealing with `composer create-project`, you can
6. Upload your local commits to the new remote repo: `git push -u origin master`
7. Start coding!

### Using Docker

You can avoid the need of a local PHP installation using Docker.

1. You will need [Docker installed](https://docs.docker.com/install/) in your computer.
2. [Download](https://github.com/CodelyTV/php-bootstrap/archive/master.zip) this repository and unzip it in your project directory.
3. Run the script `up.sh` available in the project's root folder. The first time it will build the Docker image and download the dependencies, and you will end up in a container sharing the project folder with your local machine.
4. Run all the checks: `composer test`. This will do some checks that you can perform with isolated commands:
1. [PHP Parallel Lint](https://github.com/JakubOnderka/PHP-Parallel-Lint): `composer lint`.
2. [PHP Style Check](https://github.com/squizlabs/PHP_CodeSniffer): `composer style`. If you want to fix style issues automatically: `composer fix-style`.
3. [PHP Unit](https://phpunit.de/): `composer phpunit`.
5. Create your own repository:
1. Initialize your own Git repository: `git init`
2. Add the bootstrap files: `git add .`
3. Commit: `git commit -m "Initial commit with project boilerplate based on https://github.com/CodelyTV/php-bootstrap"`
4. Add your remote repository: `git remote add origin [email protected]:your-username/your-project-name`
5. Upload your local commits to the new remote repo: `git push -u origin master`
6. Start coding!

## Helpful resources

### PHP 7
Expand Down
18 changes: 18 additions & 0 deletions docker/php.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM php:7.2.8-alpine3.7

RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/ \
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer

RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.6.0 \
&& docker-php-ext-enable xdebug

RUN adduser -D -u 1000 codelytv

RUN mkdir app \
&& chown codelytv app

WORKDIR app

USER codelytv
13 changes: 13 additions & 0 deletions up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

IMAGE_NAME="codelytv-bootstrap"

if [[ "$(docker images -q ${IMAGE_NAME}:latest 2> /dev/null)" == "" ]]; then
docker build -t ${IMAGE_NAME} -f docker/php.dockerfile ./docker
fi

if [[ ! -a vendor ]]; then
docker run -v $(pwd):/app -t --rm ${IMAGE_NAME} sh -c "composer install"
fi

docker run -it --rm -v $(pwd):/app ${IMAGE_NAME} sh