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 all 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
72 changes: 24 additions & 48 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,34 @@
# 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.10.*"
# Copy composer file first as this only changes rarely
COPY composer.json /elastica/

ENV ELASTICA_DEV true

# Documentor dependencies
RUN composer global require "phpdocumentor/template-zend=~1.3"
RUN composer global require "phpdocumentor/phpdocumentor=~2.8"
# Set empty environment so that Makefile commands inside container do not prepend the environment
ENV RUN_ENV " "

# Install depdencies
WORKDIR /app
COPY composer.json /app/
RUN composer install
# Commands are taken from Makefile. Everytime the makefile is updated, this commands is rerun
RUN mkdir -p \
./build/code-browser \
./build/docs \
./build/logs \
./build/pdepend \
./build/coverage

RUN composer install --prefer-source

# Guzzle is not included composer.json because of PHP 5.3
RUN composer require "guzzlehttp/guzzle=~6.0"
# Copy rest of the files, ignoring .dockerignore files
COPY lib /elastica/lib
COPY test /elastica/test
COPY Makefile /elastica/

ENTRYPOINT []

ENV ES_HOST elasticsearch
ENV PROXY_HOST nginx
188 changes: 117 additions & 71 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,107 +1,113 @@
#/bin/bash

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

Choose a reason for hiding this comment

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

A lot of targets, some of them just copypasted from ant config file that was deleted far ago :)
Which of them is actually used?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I actually planned to clean up the .PHONY part by putting it on top of every command. Like this no "old" commands should appear here. In general I tried to reduce the number of targets we have in the makefile, but there is still quite a list :-)

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 Here is the pull request for the Makefile. Have a look and merge it if you think that helps: #917


SOURCE = "./lib"

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

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

update: init
# By default docker environment is used to run commands. To run without the predefined environment, set RUN_ENV=" " either as parameter or as environment variable
ifndef RUN_ENV
RUN_ENV = docker run -v $(shell pwd):/elastica ruflin/elastica
endif

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
rm -r -f ./vendor
rm -r -f ./composer.lock

# Runs commands inside virtual environemnt. Example usage inside docker: make run RUN="make phpunit"
run:
docker-compose run elastica $(RUN)
docker run -v $(shell pwd):/elastica ruflin/elastica $(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

code-browser: prepare
phpcb --log ${BASEDIR}/build/logs --source ${SOURCE} --output ${BASEDIR}/build/code-browser
code-browser:
${RUN_ENV} 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:
${RUN_ENV} phpcpd --log-pmd ./build/logs/pmd-cpd.xml ${SOURCE}

messdetector: prepare
phpmd ${SOURCE} text codesize,unusedcode,naming,design ${BASEDIR}/build/phpmd.xml
messdetector:
${RUN_ENV} 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:
${RUN_ENV} 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:
${RUN_ENV} 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


tests:
# Rebuild image to copy changes files to the image
make elastica-image
make setup
docker-compose run elastica make phpunit

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

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

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

syntax-check:
php -lf ${SOURCE} **/*.php
php -lf ${BASEDIR}/test **/*.php
loc:
${RUN_ENV} cloc --by-file --xml --exclude-dir=build -out=build/cloc.xml .

phploc:
${RUN_ENV} phploc --log-csv ./build/logs/phploc.csv ${SOURCE}

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

phploc:
phploc --log-csv $(BASEDIR)/build/logs/phploc.csv $(SOURCE)
# VIRTUAL ENVIRONMENT

build:
docker-compose build

setup: build
docker-compose scale elasticsearch=3
# TODO: Makes the snapshot directory writable for all instances. Nicer solution needed.
docker-compose run elasticsearch chmod -R 777 /tmp/backups/

start:
docker-compose up

stop:
docker-compose stop

destroy: clean
docker-compose kill
docker-compose rm

# Stops and removes all containers and removes all images
destroy-environment:
make remove-containers:
-docker rmi $(shell docker images -q)

remove-containers:
-docker stop $(shell docker ps -a -q)
-docker rm -v $(shell docker ps -a -q)

# Starts a shell inside the elastica image
shell:
docker run -v $(shell pwd):/elastica -ti ruflin/elastica /bin/bash

# Starts a shell inside the elastica image with the full environment running
env-shell:
docker-compose run elastica /bin/bash

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

## DOCKER IMAGES


# 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 .

# Builds all image locally. This can be used to use local images if changes are made locally to the Dockerfiles
build-images:
docker build -t ruflin/elastica-dev-base env/elastica/
docker build -t ruflin/elasticsearch-elastica env/elasticsearch/
docker build -t ruflin/nginx-elastica env/nginx/
docker build -t ruflin/elastica-data env/data/
make elastica-image

# Removes all local images
clean-images:
-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-images: build-images
docker push ruflin/elastica-dev-base
docker push ruflin/elasticsearch-elastica
docker push ruflin/nginx-elastica
docker push ruflin/elastica


## OTHER

# 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"]

{% endblock %}

Expand Down
26 changes: 13 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
elastica:
#build: . # In case the image must be built locally
image: ruflin/elastica # comment out to build locally
#build: .
image: ruflin/elastica
ports:
- "9200:9200"
volumes:
- .:/app
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:
- "/tmp/backups/backup1"
- "/tmp/backups/backup2"
9 changes: 9 additions & 0 deletions env/data/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Data image for elasticsearch instances
FROM debian:jessie
MAINTAINER Nicolas Ruflin <spam@ruflin.com>

RUN mkdir -p /tmp/backups/backup1
RUN mkdir -p /tmp/backups/backup2

VOLUME /tmp/backups/backup1
VOLUME /tmp/backups/backup2
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