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

Makefile update #901

Merged
merged 21 commits into from
Aug 9, 2015
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
12f9389
Add .PHONY with all commands to no check for a file
ruflin Jul 28, 2015
1d32d04
Refactor Makefile to use docker as default
ruflin Jul 28, 2015
87b8c38
Make the docker environment the default for all make commands
ruflin Jul 28, 2015
2893c3d
Save docx file in newer format to make it pass tests again
ruflin Jul 28, 2015
654072f
Use only elastica image for most commands as full environment is not …
ruflin Jul 30, 2015
f792282
Fix Docker variable
ruflin Jul 30, 2015
c160500
Set DOCKER to "" for travis
ruflin Jul 31, 2015
17ecebd
Add Docker images for the data environment to make Snapshot tests wor…
ruflin Aug 6, 2015
4f026a1
Merge master
ruflin Aug 6, 2015
a030f58
Update ansible path for snapshots and apply linting. Remove unused ch…
ruflin Aug 6, 2015
9332381
Simplify snapshot path names
ruflin Aug 6, 2015
ae97558
Merge in master and update to elasticsearch 1.7.1
ruflin Aug 7, 2015
ce02afd
Simplify docker and makefile
ruflin Aug 7, 2015
56327d6
Merge Makefiles
ruflin Aug 7, 2015
28869ac
Change snapshot directory from /mount/ to /tmp/ to make it writable o…
ruflin Aug 7, 2015
9a7bc39
Change build oder of images as elastica-image must be built after loc…
ruflin Aug 7, 2015
3cdb239
Make path tmp so it works on travis
ruflin Aug 7, 2015
af98a25
Update image plugin for docker environment
ruflin Aug 8, 2015
37c72c4
Add socket extension for udp tests
ruflin Aug 8, 2015
7b0ffbe
Remove udp tests to check for default host as "localhost" will not wo…
ruflin Aug 9, 2015
4606f0e
Make shutdown tests compatible with docker environment
ruflin Aug 9, 2015
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ before_script:
- if $(phpenv version-name | grep -q '5.3'); then sudo composer update --no-dev; sudo composer dump-autoload; fi

script:
- make phpunit
- make phpunit DOCKER_ENV="" DOCKER=""

after_script:
- cat /var/log/elasticsearch/*.log
Expand Down
63 changes: 16 additions & 47 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,27 @@
# PHP 6 Docker file with Composer installed
FROM composer/composer
FROM ruflin/elastica-dev-base

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y nano
RUN apt-get install -y cloc

# XSL and Graphviz for PhpDocumentor
RUN apt-get install -y php5-xsl
# TODO: Debian is putting the xsl extension in a different directory, should be in: /usr/local/lib/php/extensions/no-debug-non-zts-20131226
RUN echo "extension=/usr/lib/php5/20131226/xsl.so" >> /usr/local/etc/php/conf.d/xsl.ini
RUN apt-get install -y graphviz


RUN echo "date.timezone=UTC" >> /usr/local/etc/php/conf.d/timezone.ini

# Xdebug for coverage report
RUN pecl install xdebug
RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" >> /usr/local/etc/php/conf.d/xdebug.ini

# Memcache
RUN apt-get install -y php5-memcache
RUN echo "extension=/usr/lib/php5/20131226/memcache.so" >> /usr/local/etc/php/conf.d/memcache.ini

# Add composer bin to the environment
ENV PATH=/root/composer/vendor/bin:$PATH
# ENVIRONMENT Setup - Needed in this image?
ENV ES_HOST elasticsearch
ENV PROXY_HOST nginx

# Overcome github access limits. GITHUB_OAUTH_TOKEN environment variable must be set with private token
RUN composer self-update
# Install depdencies
WORKDIR /elastica

# Install development tools
RUN composer global require "phpunit/phpunit=~4.7"
RUN composer global require "pdepend/pdepend=~2.0"
RUN composer global require "phpmd/phpmd=~2.2"
RUN composer global require "mayflower/php-codebrowser=~1.1"
RUN composer global require "sebastian/phpcpd=~2.0"
RUN composer global require "squizlabs/php_codesniffer=~2.3"
RUN composer global require "phploc/phploc=~2.1"
RUN composer global require "fabpot/php-cs-fixer=1.8.1"
# Copy composer file first as this only changes rarely
COPY composer.json /elastica/
COPY Makefile /elastica/

ENV ELASTICA_DEV true

# Documentor dependencies
RUN composer global require "phpdocumentor/template-zend=~1.3"
RUN composer global require "phpdocumentor/phpdocumentor=~2.8"
RUN make init

# Install depdencies
WORKDIR /app
COPY composer.json /app/
RUN composer install
# Copy rest of the files, ignoring .dockerignore files
COPY lib /elastica/lib
COPY test /elastica/test

# Guzzle is not included composer.json because of PHP 5.3
RUN composer require "guzzlehttp/guzzle=~6.0"
RUN make clean
RUN make

ENTRYPOINT []

ENV ES_HOST elasticsearch
ENV PROXY_HOST nginx
130 changes: 72 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,103 +1,113 @@
#/bin/bash

BASEDIR = $(shell pwd)
SOURCE = "${BASEDIR}/lib"
IMAGE = "elastica"
.PHONY: init prepare update clean build setup start stop destroy run checkstyle checkstyle-ci code-browser cpd messdetector messdetector-ci dependencies phpunit test doc lint syntax-check loc phploc gource

SOURCE = "./lib"
IMAGE = elastica

#DOCKER = docker run -v $(shell pwd):/elastica ruflin/${IMAGE}
DOCKER_ENV = docker-compose run ${IMAGE}
DOCKER = docker-compose run ${IMAGE}


### Setups around project sources. These commands should run ###
init: prepare
composer install
composer install --prefer-source

prepare:
mkdir -p ${BASEDIR}/build/api
mkdir -p ${BASEDIR}/build/code-browser
mkdir -p ${BASEDIR}/build/coverage
mkdir -p ${BASEDIR}/build/logs
mkdir -p ${BASEDIR}/build/docs
mkdir -p ${BASEDIR}/build/pdepend
prepare: clean
mkdir -p ./build/api
mkdir -p ./build/code-browser
mkdir -p ./build/coverage
mkdir -p ./build/logs
mkdir -p ./build/docs
mkdir -p ./build/pdepend

update: init

clean:
rm -r -f ${BASEDIR}/build
#rm ${BASEDIR}/cache.properties


# Handling virtual environment

build:
docker-compose build

setup: build
docker-compose scale elasticsearch=3

start:
docker-compose up

stop:
docker-compose stop

destroy: clean
docker-compose kill
docker-compose rm
rm -r -f ./build

# Runs commands inside virtual environemnt. Example usage inside docker: make run RUN="make phpunit"
run:
docker-compose run elastica $(RUN)

${DOCKER_ENV} $(RUN)

### Quality checks / development tools ###

checkstyle:
phpcs --standard=PSR2 ${SOURCE}

checkstyle-ci: prepare
phpcs --report=checkstyle --report-file=${BASEDIR}/build/logs/checkstyle.xml --standard=PSR2 ${SOURCE} > /dev/null
checkstyle-ci:
phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=PSR2 ${SOURCE} > /dev/null

code-browser: prepare
phpcb --log ${BASEDIR}/build/logs --source ${SOURCE} --output ${BASEDIR}/build/code-browser
code-browser:
phpcb --log ./build/logs --source ${SOURCE} --output ./build/code-browser

# Copy paste detector
cpd: prepare
phpcpd --log-pmd ${BASEDIR}/build/logs/pmd-cpd.xml ${SOURCE}
cpd:
phpcpd --log-pmd ./build/logs/pmd-cpd.xml ${SOURCE}

messdetector: prepare
phpmd ${SOURCE} text codesize,unusedcode,naming,design ${BASEDIR}/build/phpmd.xml
messdetector:
phpmd ${SOURCE} text codesize,unusedcode,naming,design ./build/phpmd.xml

messdetector-ci: prepare
phpmd ${SOURCE} xml codesize,unusedcode,naming,design --reportfile ${BASEDIR}/build/logs/pmd.xml
messdetector-ci:
phpmd ${SOURCE} xml codesize,unusedcode,naming,design --reportfile ./build/logs/pmd.xml

dependencies: prepare
pdepend --jdepend-xml=${BASEDIR}/build/logs/jdepend.xml \
--jdepend-chart=${BASEDIR}/build/pdepend/dependencies.svg \
--overview-pyramid=${BASEDIR}/build/pdepend/overview-pyramid.svg \
dependencies:
pdepend --jdepend-xml=./build/logs/jdepend.xml \
--jdepend-chart=./build/pdepend/dependencies.svg \
--overview-pyramid=./build/pdepend/overview-pyramid.svg \
${SOURCE}

phpunit: prepare
phpunit -c test/ --coverage-clover build/coverage/unit-coverage.xml --group unit
phpunit -c test/ --coverage-clover build/coverage/functional-coverage.xml --group functional
phpunit -c test/ --coverage-clover build/coverage/shutdown-coverage.xml --group shutdown
phpunit:
-phpunit -c test/ --coverage-clover build/coverage/unit-coverage.xml --group unit
-phpunit -c test/ --coverage-clover build/coverage/functional-coverage.xml --group functional
-phpunit -c test/ --coverage-clover build/coverage/shutdown-coverage.xml --group shutdown

# Makes it easy to run a single test file. Example to run IndexTest.php: make test TEST="IndexTest.php"
test:
${DOCKER_ENV} phpunit -c test/ test/lib/Elastica/Test/${TEST}

doc: prepare
phpdoc run -d lib/ -t build/docs
${DOCKER} phpdoc run -d lib/ -t build/docs

# Uses the preconfigured standards in .php_cs
lint:
php-cs-fixer fix
${DOCKER} php-cs-fixer fix

syntax-check:
php -lf ${SOURCE} **/*.php
php -lf ${BASEDIR}/test **/*.php

php -lf ./test **/*.php

loc:
loc:
cloc --by-file --xml --exclude-dir=build -out=build/cloc.xml .

phploc:
phploc --log-csv $(BASEDIR)/build/logs/phploc.csv $(SOURCE)
phploc --log-csv ./build/logs/phploc.csv ${SOURCE}

# Handling virtual environment

build:
docker-compose build

setup: build
docker-compose scale elasticsearch=3
docker-compose run elasticsearch chmod -R 777 /mount/
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@im-denisenko I'm really unhappy about this line. Not the 777 but that I have to change the access rights after the images are running. What I need is a shared data container where all elasticsearch instances have write access. I tried to do it directly in the data image https://github.com/ruflin/Elastica/pull/901/files#diff-6ddc070b659c249d339814ba724740edR10 or also in the elasticsearch https://github.com/ruflin/Elastica/pull/901/files#diff-66fcadff5e0bc20f3becadf59df62f5bR28 But only the setup part works. I'm quite sure there is just a small command that can be used to get it working. Do you have any experience here?


start:
docker-compose up

stop:
docker-compose stop

destroy: clean
docker-compose kill
docker-compose rm

shell:
docker run -v $(shell pwd):/elastica -ti ruflin/elastica /bin/bash

env-shell:
docker-compose run elastica /bin/bash

# Visualise repo
gource:
Expand All @@ -106,3 +116,7 @@ gource:
--title 'Elastica (https://github.com/ruflin/Elastica)' \
--user-scale 1 \
--max-user-speed 50

google-setup:
docker-machine create --driver google --google-project elastica-1024 --google-machine-type n1-standard-8 elastica
eval "$(docker-machine env elastica)"
2 changes: 1 addition & 1 deletion ansible/roles/elasticsearch/templates/config-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ processors: 1
node.name: Elastica

# Added for snapshot tests
path.repo: ["/tmp/test_register", "/tmp/test_repository"]
path.repo: ["/tmp/backups", "/tmp/longterm_backups"]

{% endblock %}

Expand Down
26 changes: 14 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
elastica:
#build: . # In case the image must be built locally
#build: .
image: ruflin/elastica
ports:
- "9200:9200"
volumes:
- .:/app
#volumes:
# - .:/elastica
links:
- nginx
- elasticsearch
environment:
- ES_HOST=elasticsearch
- PROXY_HOST=nginx
elasticsearch:
#build: ./env/elasticsearch/ # In case image must be built locally
#build: ./env/elasticsearch/
image: ruflin/elasticsearch-elastica
volumes_from:
- data
nginx:
image: nginx
volumes:
- ./env/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./env/nginx/mime.types:/etc/nginx/mime.types
ports:
- "12345"
- "12346"
- "80"
#build: ./env/nginx/
image: ruflin/nginx-elastica
links:
- elasticsearch
# data container to share data between elasticsearch nodes for snapshot testing
data:
image: ruflin/elastica-data
volumes:
- "/mount/backups/my_backup"
- "/mount/longterm_backups/my_backup"
43 changes: 43 additions & 0 deletions env/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#/bin/bash

# This creates the base image locally for local development. In case no local development is done anymore, make sure to remove this image.
all: nginx-image elasticsearch-image elastica-dev-image elastica-image elastica-data
# elastica image has to be built after elastica-dev image as it depends on it. Otherwise the remote image is fetched.

elastica-image:
docker build -t ruflin/elastica ../

elastica-dev-image:
docker build -t ruflin/elastica-dev-base elastica/


elasticsearch-image:
docker build -t ruflin/elasticsearch-elastica elasticsearch/

nginx-image:
cd nginx
docker build -t ruflin/nginx-elastica nginx/

elastica-data:
docker build -t ruflin/elastica-data data/

# Removes all local images
clean:
-docker rmi ruflin/elastica-dev-base
-docker rmi ruflin/elasticsearch-elastica
-docker rmi ruflin/nginx-elastica
-docker rmi ruflin/elastica
-docker rmi ruflin/elastica-data

# Pushs images as latest to the docker registry. This is normally not needed as they are directly fetched and built from Github
push:
docker push ruflin/elastica-dev-base
docker push ruflin/elasticsearch-elastica
docker push ruflin/nginx-elastica
docker push ruflin/elastica


destroy:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
10 changes: 10 additions & 0 deletions env/data/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Data image
FROM debian:jessie

RUN mkdir -p /mount/backups/my_backup
RUN mkdir -p /mount/longterm_backups/my_backup

VOLUME /mount/backups/my_backup
VOLUME /mount/longterm_backups/my_backup

RUN chmod -R 777 /mount
3 changes: 3 additions & 0 deletions env/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PHP base image for the development of Elastica.

This image containts the basic setup for the development of Elastica. Part of this image are all parts which do not change often and do not need access to the source code of Elastica. The only file needed to build this image is the composer.json file in the folder `env/elastica/`. It contains a list of the global packages which are needed for the development environment like phpunit.
Loading