Skip to content

Commit

Permalink
Merge pull request #19 from geometalab/dockerize
Browse files Browse the repository at this point in the history
Dockerize
  • Loading branch information
Zverik authored Jan 22, 2023
2 parents 313d3f0 + 67b743d commit 1089ad5
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git/
.gitignore
Dockerfile
docker-compose.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ config_local.py
*.backup
*.sql
*.gz
.env
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:2

LABEL maintainer="Geometalab <[email protected]>"

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" ]
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<your-osm-user-name>/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=<your-key>
OAUTH_SECRET=<your-secret>
SECRET_KEY=<secret-key-do-not-share>
MAPILLARY_CLIENT_ID=<mapillary-key-if-any>
```

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'`
22 changes: 12 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python2
from www.db import migrate
migrate()

0 comments on commit 1089ad5

Please sign in to comment.