Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Docker #91

Merged
merged 5 commits into from
Sep 24, 2017
Merged
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
17 changes: 17 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM composer

RUN apk add --update libxslt-dev && \
docker-php-ext-install xsl

COPY ./composer.json ./composer.lock ./bin/suggested-tools.sh /phpqa/
RUN (cd /phpqa && \
composer install --no-dev && \
./suggested-tools.sh install --update-no-dev && \
ln -s /phpqa/phpqa /usr/local/bin && \
ln -s /phpqa/vendor/bin/* /usr/local/bin && \
ls -lA /usr/local/bin | grep phpqa)

COPY ./ /phpqa/
WORKDIR /phpqa

ENTRYPOINT ["docker-php-entrypoint"]
29 changes: 29 additions & 0 deletions .docker/build-image
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

APP_DIR="./"
DOCKER_REPO="zdenekdrahos/phpqa"
DOCKER_FILE=".docker/Dockerfile"
DOCKER_TAG=""

run () {
load_docker_variables
build_docker_image
}

load_docker_variables () {
DOCKER_TAG="$DOCKER_REPO:${TRAVIS_TAG:-${TRAVIS_COMMIT:0:7}}"

echo "Dockefile: $DOCKER_FILE"
echo "Build context: $APP_DIR"
echo "Publish image: $DOCKER_TAG"
echo
}

build_docker_image () {
set -e
docker login --username $DOCKER_USER --password $DOCKER_TOKEN
time docker build --file $DOCKER_FILE --tag $DOCKER_TAG $APP_DIR
time docker push $DOCKER_TAG
}

run
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git*
.docker
.dockerignore
.dpl
bin/deploy-report.sh
bin/ci.sh
build
nbproject
tests
vendor
*-phpqa.*
.php_cs*
.travis.yml
docker-compose.yml
phpunit.xml
auth.json
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/tests export-ignore
/bin export-ignore
/.docker export-ignore
/.dockerignore export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
Expand Down
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
sudo: false
dist: precise
sudo: required
dist: trusty
language: php
services:
- docker
matrix:
include:
- php: 5.4
Expand All @@ -13,7 +15,7 @@ matrix:
install:
# Disable JIT compilation in hhvm, as the JIT is useless for short live scripts like tests.
- if [[ $TRAVIS_PHP_VERSION = hhvm* ]]; then echo 'hhvm.jit = 0' >> /etc/hhvm/php.ini; fi
- if [ -n "$GITHUB_OAUTH_TOKEN" ]; then composer config github-oauth.github.com ${GITHUB_OAUTH_TOKEN}; fi;
- if [ -n "$GITHUB_OAUTH_TOKEN" ]; then composer config -g github-oauth.github.com ${GITHUB_OAUTH_TOKEN}; fi;
- composer install --no-interaction
# test app with symfony3 components in latest php
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then composer update && composer remove phpunit/phpunit --dev --no-interaction && composer require sebastian/phpcpd:~3.0 phploc/phploc:~4 phpunit/phpunit:~5.7 && bin/suggested-tools.sh install; fi
Expand All @@ -23,6 +25,13 @@ script:
- vendor/phpunit/phpunit/phpunit
- ./phpqa tools
- bin/ci.sh
deploy:
- provider: script
script: .docker/build-image
skip_cleanup: true
on:
tags: true
php: 7.0
# http://blog.wyrihaximus.net/2015/07/composer-cache-on-travis/
cache:
directories:
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,25 @@ qa/phpqa

### Docker

Official docker image is https://hub.docker.com/r/zdenekdrahos/phpqa/.
The image can be used at [Gitlab CI](#gitlabci---docker-installation--composer-cache--artifacts).
Beware that the image is as lean as possible. That can be a problem for running PHPUnit tests.
In that case, you might miss PHP extensions for database etc (_you can [install phpqa](https://gitlab.com/costlocker/integrations/blob/213aab7/.ci/get-phpqa-binary#L40) in another [php image](https://gitlab.com/costlocker/integrations/blob/213aab7/.ci/.gitlab-ci.yml#L28)_).

```bash
docker run --rm -it zdenekdrahos/phpqa:v1.14.0 phpqa tools
# using a tool without phpqa
docker run --rm -it zdenekdrahos/phpqa:v1.14.0 phploc -v
```

There are also available images [eko3alpha/docker-phpqa](https://hub.docker.com/r/eko3alpha/docker-phpqa/) and [sparkfabrik/docker-phpqa](https://hub.docker.com/r/sparkfabrik/docker-phpqa/).
`phpqa` is used as [an entrypoint](https://docs.docker.com/engine/reference/builder/#entrypoint) (_I haven't been able to use these images at Gitlab CI_).

```bash
docker run --rm -u $UID -v $PWD:/app eko3alpha/docker-phpqa --report --ignoredDirs vendor,build,migrations,test
```

For full documentation please visit [eko3alpha/docker-phpqa](https://hub.docker.com/r/eko3alpha/docker-phpqa/).


## Analyze

Expand Down Expand Up @@ -379,6 +393,31 @@ test:
- cp -r ./var/tests $CIRCLE_ARTIFACTS
```

### Gitlab.ci - docker installation + composer cache + artifacts

```yaml
stages:
- test

test:
stage: test
image: zdenekdrahos/phpqa:v1.14.0
variables:
BACKEND_QA: "*/backend/var/QA"
BACKEND_CACHE: $CI_PROJECT_DIR/.composercache
cache:
paths:
- $BACKEND_CACHE
script:
- 'export COMPOSER_CACHE_DIR=$BACKEND_CACHE'
- 'composer install --ignore-platform-reqs --no-progress --no-suggest'
- 'phpqa --report --tools phpcs:0,phpunit:0 --buildDir var/QA --analyzedDirs ./ --ignoredDirs var,vendor'
artifacts:
when: always
paths:
- $BACKEND_QA
```

## Contributing

Contributions from others would be very much appreciated! Send
Expand Down
4 changes: 3 additions & 1 deletion bin/suggested-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

# Usage:
# $ bin/suggested-tools.sh install
# $ bin/suggested-tools.sh install --update-no-dev
# $ bin/suggested-tools.sh remove

mode="$1"
requireMode="$2"

if [ $mode = "install" ]
then
echo "Installing suggested tools"
composer require jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan friendsofphp/php-cs-fixer:~2.2 vimeo/psalm
composer require jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan friendsofphp/php-cs-fixer:~2.2 vimeo/psalm $requireMode
else
echo "Removing suggested tools"
composer remove jakub-onderka/php-parallel-lint jakub-onderka/php-console-highlighter phpstan/phpstan friendsofphp/php-cs-fixer vimeo/psalm
Expand Down