diff --git a/Makefile b/Makefile index afb0fe26..36083018 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,11 @@ -.PHONY: clean clean-test clean-pyc clean-build docs help +.PHONY: check-deps help run test test-all coverage clean clean-build clean-pyc clean-test docs servedocs release dist install + .DEFAULT_GOAL := help + + +############################# +# Open a URL in the browser # +############################# define BROWSER_PYSCRIPT import os, webbrowser, sys try: @@ -11,72 +17,102 @@ webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) endef export BROWSER_PYSCRIPT + +################################## +# Display help for this makefile # +################################## define PRINT_HELP_PYSCRIPT import re, sys +print("BigchainDB 2.0 developer toolbox") +print("--------------------------------") +print("Usage: make COMMAND") +print("") +print("Commands:") for line in sys.stdin: match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) if match: target, help = match.groups() - print("%-20s %s" % (target, help)) + print(" %-16s %s" % (target, help)) endef export PRINT_HELP_PYSCRIPT + +################## +# Basic commands # +################## +DOCKER := docker +DC := docker-compose BROWSER := python -c "$$BROWSER_PYSCRIPT" +HELP := python -c "$$PRINT_HELP_PYSCRIPT" +ECHO := /usr/bin/env echo -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) +IS_DOCKER_COMPOSE_INSTALLED := $(shell command -v docker-compose 2> /dev/null) -clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts +################ +# Main targets # +################ +help: ## Show this help + @$(HELP) < $(MAKEFILE_LIST) -clean-build: ## remove build artifacts - rm -fr build/ - rm -fr dist/ - rm -fr .eggs/ - find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + +run: check-deps ## Run BigchainDB from source (stop it with ctrl+c) + @$(DC) up bigchaindb -clean-pyc: ## remove Python file artifacts - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} + - find . -name '__pycache__' -exec rm -fr {} + +start: check-deps ## Run BigchainDB from source and daemonize it (stop with `make stop`) + @$(DC) up -d bigchaindb -clean-test: ## remove test and coverage artifacts - rm -fr .tox/ - rm -f .coverage - rm -fr htmlcov/ +stop: check-deps ## Stop BigchainDB + @$(DC) stop -lint: ## check style with flake8 - flake8 bigchaindb tests +logs: check-deps ## Attach to the logs + @$(DC) logs -f bigchaindb -test: ## run tests quickly with the default Python - pytest -v -n auto +test: check-deps ## Run all tests once + @$(DC) run --rm bigchaindb pytest -v -test-all: ## run tests on every Python version with tox - tox +test-watch: check-deps ## Run all tests and wait. Every time you change code, tests will be run again + @$(DC) run --rm bigchaindb pytest -f -v -coverage: ## check code coverage quickly with the default Python - pytest -v -n auto --database-backend=localmongodb --cov=bigchaindb --cov-report term --cov-report html +cov: check-deps ## Check code coverage and open the result in the browser + @$(DC) run --rm bigchaindb pytest -v --cov=bigchaindb --cov-report html $(BROWSER) htmlcov/index.html -docs: ## generate Sphinx HTML documentation, including API docs - $(MAKE) -C docs/root clean - $(MAKE) -C docs/root html - $(MAKE) -C docs/server clean - $(MAKE) -C docs/server html - $(BROWSER) docs/root/_build/html/index.html +doc: ## Generate HTML documentation and open it in the browser + @$(DC) run --rm --no-deps bdocs make -C docs/root html + @$(DC) run --rm --no-deps bdocs make -C docs/server html + $(BROWSER) docs/root/build/html/index.html -servedocs: docs ## compile the docs watching for changes - watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . +clean: clean-build clean-pyc clean-test ## Remove all build, test, coverage and Python artifacts + @$(ECHO) "Cleaning was successful." -release: dist ## package and upload a release - twine upload dist/* +############### +# Sub targets # +############### -dist: clean ## builds source (and not for now, wheel package) - python setup.py sdist - # python setup.py bdist_wheel - ls -l dist +check-deps: +ifndef IS_DOCKER_COMPOSE_INSTALLED + @$(ECHO) "Error: docker-compose is not installed" + @$(ECHO) + @$(ECHO) "You need docker-compose to run this command. Check out the official docs on how to install it in your system:" + @$(ECHO) "- https://docs.docker.com/compose/install/" + @$(ECHO) + @$(DC) # docker-compose is not installed, so we call it to generate an error and exit +endif -install: clean ## install the package to the active Python's site-packages - python setup.py install +clean-build: # Remove build artifacts + @rm -fr build/ + @rm -fr dist/ + @rm -fr .eggs/ + @find . -name '*.egg-info' -exec rm -fr {} + + @find . -name '*.egg' -exec rm -f {} + + +clean-pyc: # Remove Python file artifacts + @find . -name '*.pyc' -exec rm -f {} + + @find . -name '*.pyo' -exec rm -f {} + + @find . -name '*~' -exec rm -f {} + + @find . -name '__pycache__' -exec rm -fr {} + + +clean-test: # Remove test and coverage artifacts + @rm -fr .tox/ + @rm -f .coverage + @rm -fr htmlcov/ diff --git a/README.md b/README.md index 20d7f92b..7334214c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,29 @@ BigchainDB is a blockchain database. +## Run and test BigchainDB from the `master` branch +Running and testing the latest version of BigchainDB is easy. Make sure you have a recent version of [Docker Compose installed](https://docs.docker.com/compose/install/) in your host. + +Whenever you are ready, fire up a terminal and run: +``` +git clone https://github.com/bigchaindb/bigchaindb.git +cd bigchaindb +make run +``` + +To know the IP of the instance running, execute in a new terminal `make ip`. + +There are also other commands you can execute: +- `make start`: Run BigchainDB from source and daemonize it (stop it with `make stop`). +- `make stop`: Stop BigchainDB. +- `make logs`: Attach to the logs. +- `make test`: Run all tests. +- `make test-watch`: Run all tests and wait. Every time you change code, tests will be run again. +- `make cov`: Check code coverage and open the result in the browser. +- `make doc`: Generate HTML documentation and open it in the browser. + +To view all commands available, run `make`. + ## Get Started with BigchainDB Server ### [Quickstart](https://docs.bigchaindb.com/projects/server/en/latest/quickstart.html) diff --git a/docker-compose.yml b/docker-compose.yml index 5bf8d2ed..82ec949d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,7 @@ services: - ./bigchaindb:/usr/src/app/bigchaindb - ./tests:/usr/src/app/tests - ./docs:/usr/src/app/docs + - ./htmlcov:/usr/src/app/htmlcov - ./setup.py:/usr/src/app/setup.py - ./setup.cfg:/usr/src/app/setup.cfg - ./pytest.ini:/usr/src/app/pytest.ini @@ -34,15 +35,15 @@ services: BIGCHAINDB_TENDERMINT_HOST: tendermint BIGCHAINDB_TENDERMINT_PORT: 46657 ports: - - "9984" - - "9985" + - "9984:9984" + - "9985:9985" - "46658" healthcheck: test: ["CMD", "bash", "-c", "curl http://bigchaindb:9984 && curl http://tendermint:46657/abci_query"] interval: 3s timeout: 5s retries: 3 - command: bigchaindb -l DEBUG start + command: bigchaindb start tendermint: image: tendermint/tendermint:0.12 volumes: