diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4775f21 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +env +dist-env diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml new file mode 100644 index 0000000..2cdb9b5 --- /dev/null +++ b/.github/workflows/pythonapp.yml @@ -0,0 +1,30 @@ +name: Python application + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e .[dev,test] + - name: Lint with flake8 + run: | + pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pip install pytest + pytest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b76ad70 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM ubuntu:xenial +RUN apt-get update && apt-get install -y \ + libpq-dev \ + libffi-dev \ + python3-dev \ + libjpeg-dev \ + build-essential \ + python3-pip \ + git + +RUN pip3 install -U pip +RUN pip install alembic gunicorn + +ENV TRACKER_DSN=postgresql://lost@database/lost +ENV TRACKER_HELPDESK= +ENV TRACKER_PHOTO_FOLDER=/data/photos +ENV TRACKER_HTTP_LOGIN=http_login +ENV TRACKER_HTTP_PASSWORD=http_passwd +ENV TRACKER_SECRET_KEY=unsecure +ENV TRACKER_SHOUT= +ENV TRACKER_FLICKR_API_KEY= + +COPY dist-requirements.txt / +COPY dist/docker.tar.gz / +COPY entry-point.bash / +RUN mkdir -p /alembic +ADD alembic /alembic/alembic +ADD alembic.ini /alembic +RUN chmod +x /entry-point.bash +RUN pip install -r /dist-requirements.txt +RUN pip install /docker.tar.gz +RUN mkdir -p /etc/mamerwiselen/lost-tracker +COPY app.ini.dist / +COPY materialize_config.py / +EXPOSE 8080 +ENTRYPOINT ["/entry-point.bash"] diff --git a/INSTALL.rst b/INSTALL.rst index 5d83a09..7aa9ba5 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -1,106 +1,50 @@ INSTALLATION ------------ -.. note:: I recommend using virtualenv, but nothing prevents you installing - it into the root system +Since 2019, this application is available as a docker-container. You should be +able to run it using:: -Requirements -~~~~~~~~~~~~ + docker run exhuma/lost-tracker -When installing this package, it will build the Postgres client. So you'll need -the necessary headers, plus gcc on your machine. +Internally it will expose the port ``8080`` as HTTP -For Ubuntu, run the following:: +Environment Variables +--------------------- - sudo apt-get install libpq-dev python-dev build-essential +The following environment variables are available when running the container: -Installation procedure -~~~~~~~~~~~~~~~~~~~~~~ +**TRACKER_DSN** (required) + An SQLAlchemy databse URL. For example: + ``postgresql://john:password@dbhost/dbname`` -- Download the latest package from http://www.github.com/exhuma/lost-tracker I - recommend using the latest tagged version, but if you want bleeding edge, you - may also download the "master" branch. +**TRACKER_HELPDESK** + A text which is available on each page -- untar the package:: +**TRACKER_PHOTO_FOLDER** + A folder-name which contains photos which are shown on the web-page. + It is recommended to mount a host-folder into the running container to this + location. - tar xzf exhuma-lost-tracker-.tar.gz +**TRACKER_HTTP_LOGIN** + A plain-text HTTP username used for API clients -- enter the folder:: +**TRACKER_HTTP_PASSWORD** + A plain-text HTTP password used for API clients - cd exhuma-lost-tracker- +**TRACKER_SECRET_KEY** + Internally used for security. Should be set to a random string -When not using virtualenv, you may skip this section -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +**TRACKER_SHOUT** + A text shown on each page -.. note:: If you don't have virtualenv, run the following: +**TRACKER_FLICKR_API_KEY** + A key which is allowed to access the Flickr API. This is used for + additional photos. - ``sudo apt-get install python-setuptools && easy_install virtualenv`` +**TRACKER_REGISTER_URL** + An optional URL which will be used for registrations instead of the builtin + solution -- create a virtualenv:: - virtualenv --no-site-packages /path/to/your/env - -- activate the environment:: - - source /path/to/your/env/bin/activate - -Without virtualenv -~~~~~~~~~~~~~~~~~~ - -- run the installer:: - - python setup.py install - - -Database initialisation -~~~~~~~~~~~~~~~~~~~~~~~ - -To initialise the database run the following commands:: - - # export MAMERWISELEN_LOST_TRACKER_PATH="/path/which/contains/app.ini" - # ./env/bin/alembic upgrade head - - -.. note:: - - The environment variable should point to the path *containing* ``app.ini``. - Not the filename itself! - -Apache Config -~~~~~~~~~~~~~ - -Example:: - - - - ServerName www.lost.lu - ServerAlias lost.lu - - DocumentRoot /var/www/lost.lu/www/htdocs - - - Order allow,deny - Allow from all - - - WSGIDaemonProcess lost.lu processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/lost.lu/www/env user=lost_tracker - WSGIProcessGroup lost.lu - WSGIScriptAlias / /var/www/lost.lu/www/wsgi/lost-tracker.wsgi - - - Order allow,deny - Allow from all - - - - - -Configuration -------------- - -Configuration is handled using ``ini`` style config files. An example file is -given in ``app.ini.dist``. - -The file is looked up using config_resolver_. - -.. _config_resolver:: https://config-resolver.readthedocs.org/en/latest/ +When the container starts up it will automatically apply database upgrades as +necessary. diff --git a/README.rst b/README.rst index 9690d7b..6e80ed0 100644 --- a/README.rst +++ b/README.rst @@ -19,12 +19,9 @@ Development Required Tools ~~~~~~~~~~~~~~ -* fabric (Python Task Runner). This is optional but highly convenient! -* Python 2.7 (Python 3.5 was tested half-arsedly, may work...) -* Oracle Java 1.7+ (Tested with OpenJDK with mixed results). This is needed for - live JS compilation. Without it, no JavaScript will run! -* A database. I recommend PostgreSQL as the application has been tested with - that one. +* invoke (Python Task Runner). This is optional but highly convenient! +* Python 3 +* docker (for javascript compilation) Additional Notes @@ -72,22 +69,21 @@ Clone the code:: git clone https://github.com/exhuma/lost-tracker Enter the cloned folder, switch to the ``develop`` branch and run the develop -fabric-task. Running that task will set up a virtual-env, download required +invoke-task. Running that task will set up a virtual-env, download required dependencies and install the application into that environment:: cd lost-tracker git checkout develop # Make sure you're on the latest developmen branch - fab develop # Prepares a virtualenv and downloads dependencies. + inv develop # Prepares a virtualenv and downloads dependencies. When this successfully completes you should have an environment ready for happy hacking. One final note: JavaScript is compiled using the google-closure compiler with -the help of plovr_. Those dependencies should have been downloaded for you into -the ``__libs__`` folder. You *must* run plovr during development! As a -convenience, there is a fabric task to run this for you:: +the help of plovr_. The compiler has been wrapped in a docker container and +should be downloaded and run transparently. An invoke task is available:: - fab serve_plovr + inv serve_plovr Configuration @@ -107,12 +103,12 @@ look through the rest of the config file as well. Once all is configured the development server can be run with:: - fab serve_web + inv serve_web During development (when ``DEBUG=True``), you also need to run the plovr_ server in parallel. Simply open a new shell and type:: - fab serve_plovr + inv serve_plovr Social Logins During Development ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100755 index 209190c..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,76 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -VAGRANTFILE_API_VERSION = "2" - -$script = <