From 95644d29eab02f4a8e43b061f334059a5c7c5ed1 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Thu, 21 Dec 2023 16:40:09 -0500 Subject: [PATCH] Update osmcha deployment --- .gitignore | 3 +- compose/osmcha.yml | 56 +++++++++++++------ images/osmcha-web/Dockerfile | 10 +++- osm-seed/templates/osmcha-app/configMap.yaml | 1 + osm-seed/templates/osmcha-app/cronJob.yaml | 32 +++++++++++ osm-seed/templates/osmcha-app/deployment.yaml | 30 +++++----- 6 files changed, 100 insertions(+), 32 deletions(-) create mode 100644 osm-seed/templates/osmcha-app/cronJob.yaml diff --git a/.gitignore b/.gitignore index c2eaf90e..4c32d0b3 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ tiler-server/imposm/ overpass-api-db/ data/*/ !data/README.md -images/changeset-replication-job/config.yaml \ No newline at end of file +images/changeset-replication-job/config.yaml +values_copy.yaml \ No newline at end of file diff --git a/compose/osmcha.yml b/compose/osmcha.yml index 88bd3630..e722a8c5 100644 --- a/compose/osmcha.yml +++ b/compose/osmcha.yml @@ -1,15 +1,15 @@ -version: '3.8' -services: +version: "3.8" +services: web: platform: linux/amd64 - image: developmentseed/osmseed-osmcha-web:v7 + image: developmentseed/osmseed-osmcha-web:v16 build: context: ../images/osmcha-web dockerfile: Dockerfile env_file: - - ../envs/.env.osmcha + - ../envs/.env.osmcha volumes: - - ../data/osmcha/staticfiles:/staticfiles + - ../data/osmcha/staticfiles:/staticfiles db: platform: linux/amd64 image: osmseed-osmcha-db:v1 @@ -17,20 +17,44 @@ services: context: ../images/osmcha-db dockerfile: Dockerfile ports: - - '5432:5432' + - "5432:5432" volumes: - - ../data/osmcha-db-data:/var/lib/postgresql/data + - ../data/osmcha-db-data:/var/lib/postgresql/data env_file: - - ../envs/.env.osmcha - api: + - ../envs/.env.osmcha + init: platform: linux/amd64 image: ghcr.io/willemarcel/osmcha-django:b1f4e6afc90e08707cadc4d74580632ca3b93dd2 - # build: - # context: ../images/osmcha-api - # dockerfile: Dockerfile - ports: - - '5000:5000' + 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 + - ../envs/.env.osmcha volumes: - - ../data/osmcha/staticfiles:/staticfiles + - ../data/osmcha/staticfiles:/staticfiles + # api: + # platform: linux/amd64 + # image: developmentseed/osmseed-osmcha-api:v8 + # 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:3000 --log-file - --access-logfile - config.wsgi + # " + # ports: + # - "3000:3000" + # env_file: + # - ../envs/.env.osmcha + # volumes: + # - ../data/osmcha/staticfiles:/staticfiles diff --git a/images/osmcha-web/Dockerfile b/images/osmcha-web/Dockerfile index 70fe6d95..186e42dc 100644 --- a/images/osmcha-web/Dockerfile +++ b/images/osmcha-web/Dockerfile @@ -3,13 +3,19 @@ FROM node:16-slim as builder ENV DEBIAN_FRONTEND noninteractive ARG BUILD_ENV=prod -ARG OSMCHA_URL=https://osmcha-staging.openhistoricalmap.org -RUN apt-get update && apt-get install -y git +## Necesary env values to deploy +ENV OSMCHA_URL=https://osmcha-staging.openhistoricalmap.org +ENV OSMCHA_API_URL=www.openhistoricalmap.org +ENV REACT_APP_OSM_URL=https://www.openhistoricalmap.org +ENV REACT_APP_OSM_API=https://www.openhistoricalmap.org/api/0.6 +ENV REACT_APP_OVERPASS_BASE=//overpass-api.openhistoricalmap.org/api/interpreter +RUN apt-get update && apt-get install -y git RUN mkdir /app WORKDIR /app RUN git clone https://github.com/sunu/osmcha-frontend.git /app +RUN find /app -type f -exec sed -i 's/www.openstreetmap.org/www.openhistoricalmap.org/g' {} + RUN yarn install ENV REACT_APP_PRODUCTION_API_URL /api/v1 RUN sed -i "s|https://osmcha.org|$OSMCHA_URL|g" package.json diff --git a/osm-seed/templates/osmcha-app/configMap.yaml b/osm-seed/templates/osmcha-app/configMap.yaml index 0b127200..acb311f8 100644 --- a/osm-seed/templates/osmcha-app/configMap.yaml +++ b/osm-seed/templates/osmcha-app/configMap.yaml @@ -28,6 +28,7 @@ data: DJANGO_ENV: "production" # OSM_SERVER_URL: {{ .Values.osmchaApi.env.OSM_SERVER_URL | quote }} REDIS_URL: "redis://{{ .Release.Name }}-osmcha-redis:6379" + OSM_PLANET_BASE_URL: {{ .Values.osmchaApi.env.OSM_PLANET_BASE_URL | quote }} --- apiVersion: v1 kind: ConfigMap diff --git a/osm-seed/templates/osmcha-app/cronJob.yaml b/osm-seed/templates/osmcha-app/cronJob.yaml new file mode 100644 index 00000000..a7dcd675 --- /dev/null +++ b/osm-seed/templates/osmcha-app/cronJob.yaml @@ -0,0 +1,32 @@ +{{- if .Values.osmchaApi.enabled -}} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ .Release.Name }}-osmcha-fetch-changesets-cronjob + labels: + app: {{ template "osm-seed.name" . }} + component: osmcha-app-deployment + environment: {{ .Values.environment }} + release: {{ .Release.Name }} +spec: + schedule: "*/2 * * * *" + concurrencyPolicy: Forbid + successfulJobsHistoryLimit: 2 + failedJobsHistoryLimit: 2 + jobTemplate: + spec: + template: + spec: + containers: + - name: {{ .Release.Name }}-osmcha-fetch-changesets + image: "{{ .Values.osmchaApi.image.name }}:{{ .Values.osmchaApi.image.tag }}" + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - python manage.py fetchchangesets + envFrom: + - configMapRef: + name: {{ .Release.Name }}-osmcha-common-env + restartPolicy: Never +{{- end }} diff --git a/osm-seed/templates/osmcha-app/deployment.yaml b/osm-seed/templates/osmcha-app/deployment.yaml index 5110e66e..8e7d46f1 100644 --- a/osm-seed/templates/osmcha-app/deployment.yaml +++ b/osm-seed/templates/osmcha-app/deployment.yaml @@ -23,37 +23,41 @@ spec: run: {{ .Release.Name }}-osmcha-app spec: initContainers: - - name: osmcha-init + - name: init image: "{{ .Values.osmchaApi.image.name }}:{{ .Values.osmchaApi.image.tag }}" command: - /bin/sh - -c - | set -x - python manage.py collectstatic - python manage.py migrate - mkdir -p /staticfiles/static - cp -r /app/staticfiles/* /staticfiles/static/ + flag=true + while "$flag" = true; do + pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue + flag=false + python manage.py migrate + python manage.py collectstatic + mkdir -p /staticfiles/static + cp -r /app/staticfiles/* /staticfiles/static/ + done envFrom: - configMapRef: name: {{ .Release.Name }}-osmcha-common-env volumeMounts: - name: staticfiles mountPath: /staticfiles - securityContext: - runAsUser: 0 + # securityContext: + # runAsUser: 0 containers: - - name: osmcha-api - securityContext: - runAsUser: 0 + - name: api + # securityContext: + # runAsUser: 0 image: "{{ .Values.osmchaApi.image.name }}:{{ .Values.osmchaApi.image.tag }}" command: - /bin/sh - -c - | set -x - pip install git+https://github.com/OpenHistoricalMap/social-core.git && - sed -i "s|https://api.openhistoricalmap.org/api/0.6/user/details|https://www.openhistoricalmap.org/api/0.6/user/details|g" /usr/local/lib/python3.10/site-packages/social_core/backends/openstreetmap.py + echo "start app...." gunicorn --workers 4 --bind 0.0.0.0:5000 --log-file - --access-logfile - config.wsgi ports: - containerPort: 5000 @@ -79,7 +83,7 @@ spec: cpu: {{ .Values.osmchaApi.resources.limits.cpu }} {{- end }} - - name: osmcha-nginx + - name: nginx image: "{{ .Values.osmchaWeb.image.name }}:{{ .Values.osmchaWeb.image.tag }}" ports: - containerPort: 80