E-ARK-Software / py-rest-ip-validator

Flask wrapping for Information Package validation from eatb
Apache License 2.0
1 stars 2 forks source link

E-ARK Python IP Validator

Web front end for E-ARK Information Package validation.

Build Status CodeCov Coverage Codacy Badge GitHub issues

Quick Start

Pre-requisites

Python 3.5+ OR Docker.

Getting the code

Clone the project move into the directory:

git clone https://github.com/E-ARK-Software/py-rest-ip-validator.git
cd py-rest-ip-validator

Installation

Local virtual env setup

First set up a local virtual environment, this example assumes you'll do this in the project root directory on a linux box or Mac:

virtualenv -p python3 venv
source venv/bin/activate

Next set the environment variable for the Flask web app:

export FLASK_APP='ip_validation'
export EARK_PYIP_CONF_FILE='<pathtoproject>/conf/example.conf'

NOTE these will need to be set for every new session for now.

Finally install and run the Flask application:

pip install -e .
flask run --port=5000

Then open your browser and navigate to http://localhost:5000

Local Docker instance

The Dockerfile.dev file in the project root is the easiest way to run the project if you use Docker.

First you'll need to build a local instance the development Docker image:

docker build --tag=eark4all/py-ip-validator:dev -f Dockerfile.dev .

You then need to run a container instance, here's the command followed by a quick explanation:

docker run -p 5000:5000 -v "$PWD":/app --detach --rm --name py-ip-dev eark4all/py-ip-validator:dev

Here's the options explained:

  -p 5000:5000      Map port 5000 from the host to the container
  -v "$PWD":/app    Map the host current directory to the container /app directory
  --detach          Detach from terminal session
  --rm              Remove container instance
  --name py-ip-dev  Give the container a name

Again open your browser and navigate to http://localhost:5000. You can work on the code and issue the command:

docker restart py-ip-dev

Log file access on Linux

If you're running on a Linux box it's possible to push the log file to a directory on the host so that it can be read. You'll need a couple of extra options:

docker run -p 5000:5000 -u $(id -u) -v "$PWD":/app -v /tmp:/tmp --detach --rm --name py-ip-dev eark4all/py-ip-validator:dev

The new options are:

  -u $(id -u)       Ensure that the user id on the container matches the host user.
                    This means that you have permissions to remove the log file
  -v /tmp:/tmp      Map temp on the host to the container temp directory, this is
                    where the log file lives.

Configuration

The application has built in application profiles that can be augmented and over-ridden by a user configuration file.

Development

Python development utilities

These are useful for ensuring your code follows best practise and establishing whether it's tested.

Running tests

You can run unit tests by:

pytest ./tests/

and generate test coverage figures by:

pytest --cov=ip_validation ./tests/

If you want to see which parts of your code aren't tested then:

 pytest --cov=ip_validation --cov-report=html ./tests/

After this you can open the file <projectRoot>/htmlcov/index.html in your browser and survey the gory details.

Tips

setup.py doesn't install....

These are all issues I encountered when developing this as a Python noob. All commands are Linux and if not stated they are run from the project root.