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 b7d14e7b..186e42dc 100644 --- a/images/osmcha-web/Dockerfile +++ b/images/osmcha-web/Dockerfile @@ -3,17 +3,23 @@ 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 RUN yarn build:${BUILD_ENV} FROM nginx:alpine -COPY --from=builder /app/build /assets \ No newline at end of file +COPY --from=builder /app/build /assets diff --git a/images/osmcha-web/start.sh b/images/osmcha-web/start.sh deleted file mode 100755 index 7408f7ff..00000000 --- a/images/osmcha-web/start.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -ex -sed -i "s|https://osmcha.org|$OSMCHA_URL|g" package.json -yarn build:prod -cp -R build/* /staticfiles/ - -# mkdir -p /staticfiles/static/ -# chmod a+rw /staticfiles/static/ \ No newline at end of file diff --git a/images/osmcha-web/supervisord.conf b/images/osmcha-web/supervisord.conf deleted file mode 100644 index 8d520a8c..00000000 --- a/images/osmcha-web/supervisord.conf +++ /dev/null @@ -1,5 +0,0 @@ -[supervisord] -nodaemon=true - -[program:nginx] -command=/usr/sbin/nginx diff --git a/osm-seed/templates/osmcha-app/configMap.yaml b/osm-seed/templates/osmcha-app/configMap.yaml index 567485c4..acb311f8 100644 --- a/osm-seed/templates/osmcha-app/configMap.yaml +++ b/osm-seed/templates/osmcha-app/configMap.yaml @@ -27,7 +27,8 @@ data: DJANGO_DEBUG: "False" DJANGO_ENV: "production" # OSM_SERVER_URL: {{ .Values.osmchaApi.env.OSM_SERVER_URL | quote }} - REDIS_URL: {{ .Release.Name }}-osmcha-redis + REDIS_URL: "redis://{{ .Release.Name }}-osmcha-redis:6379" + OSM_PLANET_BASE_URL: {{ .Values.osmchaApi.env.OSM_PLANET_BASE_URL | quote }} --- apiVersion: v1 kind: ConfigMap @@ -42,6 +43,9 @@ data: } http { + access_log /dev/stdout; + error_log /dev/stderr; + include /etc/nginx/mime.types; default_type application/octet-stream; @@ -49,7 +53,7 @@ data: '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main; + # access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; 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 af1f12f2..8e7d46f1 100644 --- a/osm-seed/templates/osmcha-app/deployment.yaml +++ b/osm-seed/templates/osmcha-app/deployment.yaml @@ -23,34 +23,42 @@ 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 + - name: api + # securityContext: + # runAsUser: 0 image: "{{ .Values.osmchaApi.image.name }}:{{ .Values.osmchaApi.image.tag }}" command: - /bin/sh - -c - | set -x - gunicorn --workers 4 --bind 0.0.0.0:5000 --log-file log-file.log --access-logfile access-logfile.log config.wsgi + echo "start app...." + gunicorn --workers 4 --bind 0.0.0.0:5000 --log-file - --access-logfile - config.wsgi ports: - containerPort: 5000 livenessProbe: @@ -74,8 +82,11 @@ spec: memory: {{ .Values.osmchaApi.resources.limits.memory }} cpu: {{ .Values.osmchaApi.resources.limits.cpu }} {{- end }} - - name: osmcha-nginx + + - name: nginx image: "{{ .Values.osmchaWeb.image.name }}:{{ .Values.osmchaWeb.image.tag }}" + ports: + - containerPort: 80 volumeMounts: - name: osmcha-frontend-nginx-config mountPath: /etc/nginx diff --git a/osm-seed/templates/osmcha-app/service.yaml b/osm-seed/templates/osmcha-app/service.yaml index 268d859e..7b6c1c23 100644 --- a/osm-seed/templates/osmcha-app/service.yaml +++ b/osm-seed/templates/osmcha-app/service.yaml @@ -12,7 +12,7 @@ metadata: {{- if and (eq .Values.serviceType "LoadBalancer") .Values.AWS_SSL_ARN }} service.beta.kubernetes.io/aws-load-balancer-ssl-cert: {{ .Values.AWS_SSL_ARN }} service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http - service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https + service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https {{- end }} {{- if eq .Values.serviceType "ClusterIP" }} kubernetes.io/ingress.class: nginx @@ -32,7 +32,7 @@ spec: name: http {{- if and (eq .Values.serviceType "LoadBalancer") .Values.AWS_SSL_ARN }} - port: 443 - targetPort: http + targetPort: 80 protocol: TCP name: https {{- end }}