Skip to content

Commit

Permalink
OSMCha oauth2 - updates (#355)
Browse files Browse the repository at this point in the history
* Add values for oauth2 - osmcha

* Rename env var for oauth2  - osmcha

* Fix env vars for osmcha

* Update gitsha for osmcha

* Update livenessProbe path

* Add env var for Settings for PostgreSQL client

* Update init container name

* Update osmcha deployment to the new version

* Osmcha web continaer

* Add osmcha adiff config to deploy

* Update config for osmcha adiff

* Update redis name

* Add env vars for osmcha adiff

* Update env vars for osmcha-api

* Update cronjob for osmcha fetch changesets

* Ser cronjob value in quotes
  • Loading branch information
Rub21 authored Feb 3, 2025
1 parent 1f921c6 commit 49245d2
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 148 deletions.
85 changes: 32 additions & 53 deletions compose/osmcha.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,39 @@
version: "3.8"
services:
web:
platform: linux/amd64
image: developmentseed/osmseed-osmcha-web:v16
django:
image: "ghcr.io/openhistoricalmap/osmcha-django:upstream_main"
depends_on:
- redis
volumes:
# Copy static files into a shared volume so the frontend can serve them
- staticfiles:/app/staticfiles
env_file: ./../envs/.env.osmcha
ports:
- "5001:5000"
entrypoint: ["/bin/sh", "-c"]
command:
- |
python manage.py migrate --verbosity 3 && \
python manage.py collectstatic --noinput && \
gunicorn config.wsgi -t 120 -b 0.0.0.0:5000 --access-logfile - --log-level debug
frontend:
build:
context: ../images/osmcha-web
dockerfile: Dockerfile
env_file:
- ../envs/.env.osmcha
depends_on:
- django
volumes:
- ../data/osmcha/staticfiles:/staticfiles
db:
platform: linux/amd64
image: osmseed-osmcha-db:v1
build:
context: ../images/osmcha-db
dockerfile: Dockerfile
# frontend serves django app's static files via shared volume
- staticfiles:/srv/www/static/django
env_file: ./../envs/.env.osmcha

ports:
- "5432:5432"
volumes:
- ../data/osmcha-db-data:/var/lib/postgresql/data
env_file:
- ../envs/.env.osmcha
init:
platform: linux/amd64
image: ghcr.io/willemarcel/osmcha-django:b1f4e6afc90e08707cadc4d74580632ca3b93dd2
command: >
/bin/bash -c "
set -x
python manage.py collectstatic
python manage.py migrate
mkdir -p /staticfiles/static
cp -r /app/staticfiles/* /staticfiles/static/
"
env_file:
- ../envs/.env.osmcha
volumes:
- ../data/osmcha/staticfiles:/staticfiles
api:
platform: linux/amd64
image: ghcr.io/willemarcel/osmcha-django:b1f4e6afc90e08707cadc4d74580632ca3b93dd2
build:
context: ../images/osmcha-api
dockerfile: Dockerfile
command: >
/bin/bash -c "
set -x
python manage.py collectstatic
python manage.py migrate
mkdir -p /staticfiles/static
cp -r /app/staticfiles/* /staticfiles/static/
gunicorn --workers 4 --bind 0.0.0.0:5000 --log-file - --access-logfile - config.wsgi
"
- "8000:80"

redis:
image: redis:latest
container_name: redis
restart: always
ports:
- "5000:5000"
env_file:
- ../envs/.env.osmcha
volumes:
- ../data/osmcha/staticfiles:/staticfiles
- "6379:6379"
volumes:
staticfiles:
34 changes: 23 additions & 11 deletions images/osmcha-web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
FROM node:16-slim as builder
FROM node:22-alpine as builder

ENV DEBIAN_FRONTEND noninteractive
ENV BUILD_ENV=prod
ENV REACT_APP_PRODUCTION_API_URL=/api/v1
RUN apt-get update && apt-get install -y git \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /app

ARG GITSHA=3cd987bd2ed02bbb60b121ecad0bb556a115aca1
ARG BUILD_ENV=prod

WORKDIR /app
ARG GITSHA=9925beeabcbc3b50eccc83dd92d71f2cf6791b04
RUN git clone --branch master https://github.com/osmus/osmcha-frontend.git /app
RUN git checkout $GITSHA

## Clone osmcha repo
RUN apk add --no-cache git \
&& git clone https://github.com/OSMCha/osmcha-frontend.git /app \
&& cd /app \
&& git checkout $GITSHA

RUN yarn set version stable
RUN yarn install
COPY start.sh .
CMD [ "/app/start.sh" ]

ENV REACT_APP_PRODUCTION_API_URL /api/v1
ENV NODE_OPTIONS --openssl-legacy-provider

RUN yarn run build:${BUILD_ENV}

FROM nginx:alpine

COPY --from=builder /app/build /srv/www

COPY nginx.conf /etc/nginx/templates/default.conf.template
36 changes: 36 additions & 0 deletions images/osmcha-web/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
server {
listen 80;
charset utf-8;

include /etc/nginx/mime.types;
default_type application/octet-stream;

gzip on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;

location ~ ^/(api|admin) {
# /api and /admin routes are handled by the backend
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass $BACKEND_URL;
}

location /static {
# /static files are served without any magic (exact path or 404)
root /srv/www;
try_files $uri =404;
}

location / {
# other routes are served by trying the exact path, and falling back to
# serving the app entrypoint (index.html). this is needed because the
# frontend JS code uses the path component of the URL in its client-side
# routing.
root /srv/www;
try_files $uri $uri/ /index.html;
}
}
5 changes: 1 addition & 4 deletions images/osmcha-web/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
set -x
export BUILD_ENV=prod
export REACT_APP_PRODUCTION_API_URL=/api/v1
sed -i "s|https://osmcha.org|$OSMCHA_URL|g" package.json
yarn build:${BUILD_ENV}
find /app/build -type f -exec sed -i "s/www.openstreetmap.org/$OSMCHA_API_URL/g" {} +
cp -r /app/build/* /assets/
yarn build
66 changes: 66 additions & 0 deletions osm-seed/templates/osmcha-app/adiff-service-worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{- if .Values.adiffService.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-osmcha-adiff-service-worker
labels:
app: {{ .Release.Name }}-osmcha-adiff-service-worker
environment: {{ .Values.environment }}
release: {{ .Release.Name }}
spec:
replicas: {{ .Values.adiffService.replicas}}
selector:
matchLabels:
app: {{ .Release.Name }}-osmcha-adiff-service-worker
template:
metadata:
labels:
app: {{ .Release.Name }}-osmcha-adiff-service-worker
spec:
containers:
- name: {{ .Release.Name }}-osmcha-adiff-service-worker
image: "{{ .Values.adiffService.image.name }}:{{ .Values.adiffService.image.tag }}"
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- yarn update-queue
env:
- name: ReplicationBucket
value: {{ .Values.adiffService.env.ReplicationBucket }}
- name: OsmchaAdminToken
value: {{ .Values.adiffService.env.OsmchaAdminToken }}
- name: OutputBucket
value: {{ .Values.adiffService.env.OutputBucket }}
- name: OverpassPrimaryUrl
value: {{ .Values.adiffService.env.OverpassPrimaryUrl }}
- name: OverpassSecondaryUrl
value: {{ .Values.adiffService.env.OverpassSecondaryUrl }}
### Redis Server comes from osmcha-api
- name: RedisServer
value: redis://localhost:6379
- name: NumberOfWorkers
value: {{ .Values.adiffService.env.NumberOfWorkers | quote }}
- name: NODE_OPTIONS
value: {{ .Values.adiffService.env.NODE_OPTIONS }}
- name: OsmchaUrl
value: {{ .Values.adiffService.env.OsmchaUrl }}

{{- if .Values.adiffService.nodeSelector.enabled }}
nodeSelector:
{{ .Values.adiffService.nodeSelector.label_key }}: {{ .Values.adiffService.nodeSelector.label_value }}
{{- end }}
{{- if .Values.adiffService.resources.enabled }}
resources:
requests:
memory: {{ .Values.adiffService.resources.requests.memory }}
cpu: {{ .Values.adiffService.resources.requests.cpu }}
limits:
memory: {{ .Values.adiffService.resources.limits.memory }}
cpu: {{ .Values.adiffService.resources.limits.cpu }}
{{- end }}
- name: osmcha-redis-adiff
image: "redis:latest"
ports:
- containerPort: 6379
{{- end }}
20 changes: 10 additions & 10 deletions osm-seed/templates/osmcha-app/configMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ data:
POSTGRES_PASSWORD: {{ .Values.osmchaDb.env.POSTGRES_PASSWORD | quote }}
POSTGRES_DATABASE: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}
POSTGRES_DB: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}
PGPORT: "5432"
PGUSER: {{ .Values.osmchaDb.env.POSTGRES_USER | quote }}
PGPASSWORD: {{ .Values.osmchaDb.env.POSTGRES_PASSWORD | quote }}
PGDATABASE: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}
# API
DJANGO_SECRET_KEY: {{ .Values.osmchaApi.env.DJANGO_SECRET_KEY | quote }}
DJANGO_SETTINGS_MODULE: {{ .Values.osmchaApi.env.DJANGO_SETTINGS_MODULE | quote }}
OSMCHA_FRONTEND_VERSION: {{ .Values.osmchaApi.env.OSMCHA_FRONTEND_VERSION | quote }}
OAUTH_OSM_KEY: {{ .Values.osmchaApi.env.OAUTH_OSM_KEY | quote }}
OAUTH_OSM_SECRET: {{ .Values.osmchaApi.env.OAUTH_OSM_SECRET | quote }}
# OAUTH_OSM_KEY: {{ .Values.osmchaApi.env.OAUTH_OSM_KEY | quote }}
# OAUTH_OSM_SECRET: {{ .Values.osmchaApi.env.OAUTH_OSM_SECRET | quote }}
OAUTH_REDIRECT_URI: {{ .Values.osmchaApi.env.OAUTH_REDIRECT_URI | quote }}
DJANGO_SECURE_SSL_REDIRECT: "False"
DJANGO_DEBUG: "False"
DJANGO_ENV: "production"
OSM_SERVER_URL: {{ .Values.osmchaApi.env.OSM_SERVER_URL | quote }}
DJANGO_DEBUG: "False"
DJANGO_ENV: "production"
REDIS_URL: "redis://localhost:6379"
REDIS_URL: redis://osmcha-redis:6379
OSM_PLANET_BASE_URL: {{ .Values.osmchaApi.env.OSM_PLANET_BASE_URL | quote }}
# frontend
OSMCHA_URL: {{ .Values.osmchaApi.env.OSMCHA_URL | quote }}
OSMCHA_API_URL: {{ .Values.osmchaApi.env.OSMCHA_API_URL | quote }}
REACT_APP_OSM_URL: {{ .Values.osmchaApi.env.REACT_APP_OSM_URL | quote }}
REACT_APP_OSM_API: {{ .Values.osmchaApi.env.REACT_APP_OSM_API | quote }}
REACT_APP_OVERPASS_BASE: {{ .Values.osmchaApi.env.REACT_APP_OVERPASS_BASE | quote }}
REACT_APP_DISABLE_REAL_CHANGESETS: {{ .Values.osmchaApi.env.REACT_APP_DISABLE_REAL_CHANGESETS | quote }}
REACT_APP_MAPBOX_ACCESS_TOKEN: {{ .Values.osmchaApi.env.REACT_APP_MAPBOX_ACCESS_TOKEN | quote }}
OAUTH2_OSM_KEY: {{ quote .Values.osmchaApi.env.OAUTH2_OSM_KEY }}
OAUTH2_OSM_SECRET: {{ quote .Values.osmchaApi.env.OAUTH2_OSM_SECRET }}

---
apiVersion: v1
kind: ConfigMap
Expand Down
15 changes: 6 additions & 9 deletions osm-seed/templates/osmcha-app/cronJob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
environment: {{ .Values.environment }}
release: {{ .Release.Name }}
spec:
schedule: "*/2 * * * *"
schedule: {{ .Values.osmchaApi.fetch_changesets_cronjob | quote }}
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
Expand Down Expand Up @@ -47,7 +47,7 @@ metadata:
environment: {{ .Values.environment }}
release: {{ .Release.Name }}
spec:
schedule: "0 * * * *"
schedule: {{ .Values.osmchaApi.process_changesets_cronjob | quote }}
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
Expand All @@ -60,17 +60,14 @@ spec:
- name: {{ .Release.Name }}-osmcha-process-changesets
image: "{{ .Values.osmchaApi.image.name }}:{{ .Values.osmchaApi.image.tag }}"
imagePullPolicy: IfNotPresent
imagePullPolicy: Always
command:
- /bin/sh
- -c
- |
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
TODAY=$(date +%Y-%m-%d)
python manage.py backfill_changesets "$YESTERDAY" "$TODAY"
EXIT_CODE=$?
exit $EXIT_CODE
set -x
# Note: This is a hack to make sure for ohm
python manage.py backfill_changesets_id --start_id=100000
envFrom:
- configMapRef:
name: {{ .Release.Name }}-osmcha-common-env
Expand Down
Loading

0 comments on commit 49245d2

Please sign in to comment.