Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream changes #1

Open
wants to merge 33 commits into
base: ohm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d9b1beb
Use try/except in the changeset ingestion commands (#682)
willemarcel Mar 27, 2024
f40ce72
Improve backfill_changesets command (#685)
willemarcel Apr 15, 2024
2540775
Bump sqlparse from 0.4.2 to 0.4.4 in /requirements (#663)
dependabot[bot] Apr 16, 2024
53e1ed1
Handle errors when creating changesets (#687)
willemarcel Apr 16, 2024
680789c
Switch to oauth2 authentication (#697)
willemarcel May 30, 2024
aee0c7f
Add page_size query_param to Reasons and Tags list views (#700)
willemarcel Jun 4, 2024
55db5b1
Increase throtling limits + fix oauth redirect_uri (#701)
willemarcel Jun 4, 2024
f69570a
Update DRF-gis to 1.0 (#705)
willemarcel Aug 7, 2024
c1ef15b
Set user-agent when making requests to the OSM API (#712)
willemarcel Aug 27, 2024
59281c7
Update osmcha lib and pyyaml
willemarcel Aug 27, 2024
2991254
Remove unneeded frontend app (#713)
willemarcel Aug 28, 2024
02f435b
Remove unneeded dependencies and update others (#715)
willemarcel Aug 28, 2024
8f8611e
Move /health endpoint to /api/v1/health (making it public) (#716)
jake-low Sep 24, 2024
da9df57
Fix minor typos in README (#609)
mzagorskirs Sep 26, 2024
cba2872
Update info in README about official instances (#717)
jake-low Oct 1, 2024
329df5f
Remove static/ directory and update frontend deployment docs (#718)
jake-low Oct 1, 2024
ac125e9
Fix OAuth2 env var names in example .env file
jake-low Sep 27, 2024
6ef05bd
Split Postgres client and server env vars
jake-low Sep 27, 2024
78f43f1
Simplify docker entrypoint script
jake-low Sep 30, 2024
d6f009c
Run osmcha-frontend container in compose app
jake-low Oct 1, 2024
d6e3667
Fix Postgres auth for Github Actions test workflow
jake-low Oct 1, 2024
4d950ce
Remove redundant volume definitions from docker-compose.yml
jake-low Oct 24, 2024
b537366
Move some production settings overrides to Dockerfile
jake-low Oct 30, 2024
cc0d27b
Remove broken 404 and 500 error pages
jake-low Oct 30, 2024
c283529
Update GitHub Actions docker build/push workflow
jake-low Nov 6, 2024
2087b98
Merge pull request #719 from OSMCha/jlow/docker-improvements
jake-low Nov 6, 2024
cbbceb6
Update values for ohm
Rub21 Jan 29, 2025
941eaa8
Fix conflicts with ohm branch
Rub21 Jan 29, 2025
f2ec5ab
Update url for osmcha
Rub21 Jan 30, 2025
5d65844
fix date issue with backfill_changesets
Rub21 Jan 31, 2025
74e5e63
Add script to fetch changeset from given changeset id
Rub21 Jan 31, 2025
18a9c0d
Update scripts
Rub21 Jan 31, 2025
1e9d9dd
Update actions to create images with gitsha
Rub21 Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.9, '3.10']
python-version: ['3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand All @@ -33,7 +33,7 @@ jobs:
run: |
coverage run manage.py test --settings=config.settings.tests
env:
OAUTH_OSM_KEY: ${{ secrets.OAUTH_OSM_KEY }}
OAUTH_OSM_SECRET: ${{ secrets.OAUTH_OSM_SECRET }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
OAUTH2_OSM_KEY: ${{ secrets.OAUTH_OSM_KEY }}
OAUTH2_OSM_SECRET: ${{ secrets.OAUTH_OSM_SECRET }}
PGUSER: ${{ secrets.POSTGRES_USER }}
PGPASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
46 changes: 33 additions & 13 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,55 @@ name: Build Docker Image, Push to GHCR

on:
push:
branches:
- master
- ohm
branches: [ "main" , "ohm", "upstream_main" ]
tags: [ 'v*.*.*' ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: openhistoricalmap/osmcha-django

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get Git Commit SHA
run: echo "GIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

# Enable BuildKit for docker builds. This enables building
# multi-platform images and exporting the layer cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
# https://github.com/docker/login-action
- name: Login to Registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# https://github.com/docker/build-push-action
- name: Build and push Docker image with Git SHA
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/osmcha/osmcha-django:latest
ghcr.io/osmcha/osmcha-django:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.GIT_SHA }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
5 changes: 0 additions & 5 deletions DEPLOY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ You can access your ``osmcha-django`` instance in http://localhost/ at your brow
It is also possible to deploy to Heroku or to your own server by using Dokku, an open
source Heroku clone.

To put celery in production we need a celeryd and a celery beat services running on
the machine. More information: https://celery.readthedocs.org/en/latest/tutorials/daemonizing.html#daemonizing

And we also need to set periodic tasks to import the changesets daily or hourly: https://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html

If you find any issue, please report. We didn't test it in Heroku and Dokku

Heroku
Expand Down
21 changes: 13 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM python:3.10-slim-bookworm
ARG DEBIAN_FRONTEND=noninteractive
ARG REQUIREMENTS_FILE=production.txt
ARG DJANGO_SETTINGS_MODULE=config.settings.production

RUN apt-get update -qq -y \
&& apt-get install -y curl wget python3 python3-dev python3-pip git \
Expand All @@ -10,21 +12,24 @@ RUN apt-get update -qq -y \

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./requirements /requirements

RUN pip install -r /requirements/production.txt
RUN pip install -r /requirements/$REQUIREMENTS_FILE

COPY . /app
RUN useradd django
RUN chown -R django:django /app
WORKDIR /app

RUN python manage.py collectstatic --noinput

COPY ./compose/django/gunicorn.sh /gunicorn.sh
COPY ./compose/django/entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r//' /entrypoint.sh \
&& sed -i 's/\r//' /gunicorn.sh \
&& chmod +x /entrypoint.sh \
&& chmod +x /gunicorn.sh
RUN chmod +x /entrypoint.sh

WORKDIR /app
USER django
VOLUME /app/staticfiles

# Default number of gunicorn worker processes. Using an env var instead of --workers
# in the command below lets users of this docker image override the default easily.
ENV WEB_CONCURRENCY 4

ENTRYPOINT ["/entrypoint.sh"]
CMD ["gunicorn", "config.wsgi", "-t", "120", "-b", "0.0.0.0:5000", "--access-logfile", "-"]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

41 changes: 17 additions & 24 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ osmcha-django
The aim of OSMCHA is to help identify and fix harmful edits in the OpenStreetMap.
It relies on `OSMCHA <https://github.com/willemarcel/osmcha>`_ to analyse the changesets.

This project provides a Django application that get the changesets from the
OpenStreetMap API, analyses and store it in a database and finally provides a
This project provides a Django application that gets changesets from the
OpenStreetMap API, analyses and stores them in a database and finally provides a
REST API to interact with the changeset data.

This repository contains the backend code. You can report errors or request new features in the
Expand All @@ -30,7 +30,7 @@ Apache/mod_wsgi setups**. It has been deployed successfully with both Gunicorn/N
and uWSGI/Nginx.

For configuration purposes, the following table maps the 'osmcha-django' environment
variables to their Django setting:
variables to their Django settings:


======================================= ================================= ========================================= ===========================================
Expand All @@ -50,16 +50,15 @@ DJANGO_DEFAULT_FROM_EMAIL DEFAULT_FROM_EMAIL n/a
DJANGO_SERVER_EMAIL SERVER_EMAIL n/a "osmcha-django <[email protected]>"
DJANGO_EMAIL_SUBJECT_PREFIX EMAIL_SUBJECT_PREFIX n/a "[osmcha-django] "
DJANGO_CHANGESETS_FILTER CHANGESETS_FILTER None None
POSTGRES_USER POSTGRES_USER None None
POSTGRES_PASSWORD POSTGRES_PASSWORD None None
PGHOST PGHOST localhost localhost
OAUTH_OSM_KEY SOCIAL_AUTH_OPENSTREETMAP_KEY None None
OAUTH_OSM_SECRET SOCIAL_AUTH_OPENSTREETMAP_SECRET None None
PGUSER DATABASES None None
PGPASSWORD DATABASES None None
PGHOST DATABASES localhost localhost
OAUTH2_OSM_KEY SOCIAL_AUTH_OPENSTREETMAP_KEY None None
OAUTH2_OSM_SECRET SOCIAL_AUTH_OPENSTREETMAP_SECRET None None
DJANGO_ANON_USER_THROTTLE_RATE ANON_USER_THROTTLE_RATE None 30/min
DJANGO_COMMON_USER_THROTTLE_RATE COMMON_USER_THROTTLE_RATE None 180/min
DJANGO_NON_STAFF_USER_THROTTLE_RATE NON_STAFF_USER_THROTTLE_RATE 3/min 3/min
OAUTH_REDIRECT_URI OAUTH_REDIRECT_URI http://localhost:8000/oauth-landing.html http://localhost:8000/oauth-landing.html
OSMCHA_FRONTEND_VERSION OSMCHA_FRONTEND_VERSION oh-pages oh-pages
DJANGO_ENABLE_CHANGESET_COMMENTS ENABLE_POST_CHANGESET_COMMENTS False False
DJANGO_OSM_COMMENTS_API_KEY OSM_COMMENTS_API_KEY '' ''
======================================= ================================= ========================================= ===========================================
Expand Down Expand Up @@ -91,7 +90,7 @@ We assume you have the following installed:
* virtualenv
* PostgreSQL

Before to install the python libraries, we need to install some packages in the
Before installing the python libraries, we need to install some packages in the
operational system::

$ sudo ./install_os_dependencies.sh install
Expand Down Expand Up @@ -122,7 +121,7 @@ Setting Up Your Users

To create a **normal user account**, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.

To create an **superuser account**, use this command::
To create a **superuser account**, use this command::

$ python manage.py createsuperuser

Expand All @@ -140,30 +139,24 @@ How to login using the OAuth api
Frontend
^^^^^^^^

`osmcha-frontend <https://github.com/osmcha/osmcha-frontend>`_ is a web interface
that you can use to interact with the API. We have a django management command
to get the last version of osmcha-frontend and serve it with the API.

$ python manage.py update_frontend

After that, if you have set all the environment variables properly, you can start
the server and have the frontend in your root url.
`osmcha-frontend <https://github.com/osmcha/osmcha-frontend>`_ is a web
interface that you can use to interact with the API. The web interface can be
deployed separately and configured to talk to this Django app when making API
requests. See the README in that repository for more details.

Feature creation endpoint
^^^^^^^^^^^^^^^^^^^^^^^^^

The feature creation endpoint allows only admin users to create features. You can
use the admin site to create a token to a user.
use the admin site to create a token for a user.

Instances
---------

We have some instances running ``osmcha-django``:

The main instance is https://osmcha.org/. You can check the API
documentation at https://osmcha.org/api-docs/.

Furthermore, we have a test instance running at http://osmcha-org-staging.osmcha.org/.
There is currently no official staging instance.

Deployment
------------
Expand All @@ -174,7 +167,7 @@ Check the `Deploy <DEPLOY.rst>`_ file for instructions on how to deploy with Her
Get in contact
---------------

If you use, deploy or are interested in help to develop OSMCha, subscribe to our
If you use, deploy or are interested in helping develop OSMCha, subscribe to our
`mailing list <https://lists.openstreetmap.org/listinfo/osmcha-dev>`_. You can
report errors or request new features in the
`osmcha-frontend repository <https://github.com/osmcha/osmcha-frontend>`_.
31 changes: 4 additions & 27 deletions compose/django/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
#!/bin/bash
#!/bin/sh
set -e
cmd="$@"

# This entrypoint is used to play nicely with the current cookiecutter configuration.
# Since docker-compose relies heavily on environment variables itself for configuration, we'd have to define multiple
# environment variables just to support cookiecutter out of the box. That makes no sense, so this little entrypoint
# does all this for us.
export REDIS_URL=redis://redis:6379
# the official postgres image uses 'postgres' as default user if not set explictly.
if [ -z "$POSTGRES_USER" ]; then
export POSTGRES_USER=postgres
fi

if [ -z "$POSTGRES_HOST" ]; then
export POSTGRES_HOST=postgres
fi

export PGHOST=$POSTGRES_HOST
export POSTGRES_USER=$POSTGRES_USER
export POSTGRES_PASSWORD=$POSTGRES_PASSWORD
# export DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/$POSTGRES_USER

export CELERY_BROKER_URL=$REDIS_URL/0


function postgres_ready(){
postgres_ready() {
python << END
import sys
import psycopg2
try:
conn = psycopg2.connect(dbname="$POSTGRES_USER", user="$POSTGRES_USER", password="$POSTGRES_PASSWORD", host="$POSTGRES_HOST")
conn = psycopg2.connect("") # use environment variables for connection
except psycopg2.OperationalError:
sys.exit(-1)
sys.exit(0)
Expand All @@ -42,4 +19,4 @@ until postgres_ready; do
done

>&2 echo "Postgres is up - continuing..."
exec $cmd
exec $@
3 changes: 0 additions & 3 deletions compose/django/gunicorn.sh

This file was deleted.

2 changes: 1 addition & 1 deletion compose/django/start-dev.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
python manage.py migrate
python manage.py runserver_plus 0.0.0.0:8000
python manage.py runserver_plus 0.0.0.0:5000
4 changes: 0 additions & 4 deletions compose/nginx/Dockerfile

This file was deleted.

52 changes: 0 additions & 52 deletions compose/nginx/nginx.conf

This file was deleted.

7 changes: 0 additions & 7 deletions config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
from __future__ import absolute_import

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app # noqa

__all__ = ['celery_app']
25 changes: 0 additions & 25 deletions config/celery.py

This file was deleted.

Loading
Loading