diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38f5e04 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git/ +.gitignore +Dockerfile +docker-compose.yml diff --git a/.gitignore b/.gitignore index 5530c37..8ceb755 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ config_local.py *.backup *.sql *.gz +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d155c3f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:2 + +LABEL maintainer="Geometalab " + +RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/* + +ENV DOCKERIZE_VERSION v0.6.1 +RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz + +RUN pip install uwsgi psycopg2-binary + +COPY requirements.txt /tmp/requirements.txt +RUN pip install -r /tmp/requirements.txt + +EXPOSE 8080 + +COPY . /opt/cf_audit +WORKDIR /opt/cf_audit +ENTRYPOINT [ "dockerize", "-wait", "tcp://database:5432" ] +CMD [ "uwsgi", "--chdir", "/opt/cf_audit/", "--http", ":8080", "--wsgi-file", "cf_audit.wsgi" ] diff --git a/README.md b/README.md index f90c0fa..c835ad6 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,27 @@ It records any changes and produces a file that can be later feeded back to the ## Author and License All this was written by Ilya Zverev for MAPS.ME. Published under Apache License 2.0. + +## Running using docker-compose + +You can run this project locally (or using an adapted version +on your server as well) using the provided docker-compose file. + +1. Create an application on `https://www.openstreetmap.org/user//oauth_clients` + and use `localhost:8080` as your main application URL. + +1. Copy the "Consumer Key" respectively the "Consumer Secret" to a new file called `.env` as follows: + + ```bash + OAUTH_KEY= + OAUTH_SECRET= + SECRET_KEY= + MAPILLARY_CLIENT_ID= + ``` + +1. Then start it on your machine using docker-compose: `docker-compose up --build`. + +Open your browser at `localhost:8080` and start using it. + +In case you don't have admin-rights, uncomment the line in the `docker-compose.yml` with `# ADMINS: ''`. +You can add multiple admins by separating the values with a comma (`,`), ie. `ADMINS: '1234,98765'` diff --git a/config.py b/config.py index 3ff6e0a..2238bcd 100644 --- a/config.py +++ b/config.py @@ -1,19 +1,21 @@ import os BASE_DIR = os.path.abspath(os.path.dirname(__file__)) -DEBUG = True +DEBUG = os.environ.get('DEBUG', True) -DATABASE_URI = 'sqlite:///' + os.path.join(BASE_DIR, 'audit.db') -# DATABASE_URI = 'postgresql://localhost/cf_audit' -MAX_CONTENT_LENGTH = 16*1024*1024 +DATABASE_URI = os.environ.get('DATABASE_URI', 'sqlite:///' + os.path.join(BASE_DIR, 'audit.db')) +MAX_CONTENT_LENGTH = int(os.environ.get('MAX_CONTENT_LENGTH', 16*1024*1024)) -ADMINS = set([290271]) # Zverik +ADMINS = os.environ.get('ADMINS') +if ADMINS: + ADMINS = set([int(adm_id) for adm_id in ADMINS.split(',')]) -# Override these (and anything else) in config_local.py -OAUTH_KEY = '' -OAUTH_SECRET = '' -SECRET_KEY = 'sdkjfhsfljhsadf' -MAPILLARY_CLIENT_ID = '' +# Override these (and anything else) in config_local.py or +# set environment variables accordingly. +OAUTH_KEY = os.environ.get('OAUTH_KEY', '') +OAUTH_SECRET = os.environ.get('OAUTH_SECRET', '') +SECRET_KEY = os.environ.get('SECRET_KEY', 'sdkjfhsfljhsadf') +MAPILLARY_CLIENT_ID = os.environ.get('MAPILLARY_CLIENT_ID', '') try: from config_local import * diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8382001 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.4' +services: + cf-audit: &auditor + build: . + environment: + # uncomment following line to enable debugging + # DEBUG: yes + DATABASE_URI: 'postgresql://cf_audit:pw@database:5432/cf_audit' + # enter the osm-ids here, which should get admin-rights. + ADMINS: '' + env_file: + - .env + ports: + - "8080:8080" + depends_on: + - database + migrate: + <<: *auditor + command: python migrate.py + ports: [] + database: + image: postgres:10 + environment: + POSTGRES_USER: cf_audit + POSTGRES_PASSWORD: pw + POSTGRES_DB: cf_audit + diff --git a/migrate.py b/migrate.py new file mode 100644 index 0000000..471d85d --- /dev/null +++ b/migrate.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python2 +from www.db import migrate +migrate()