Skip to content

Commit

Permalink
Refactoring osmcha
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Dec 15, 2023
1 parent 4389cf9 commit 1c243bd
Show file tree
Hide file tree
Showing 15 changed files with 749 additions and 426 deletions.
40 changes: 34 additions & 6 deletions compose/osmcha.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
version: '3'
services:
osmcha-db:
services:
web:
platform: linux/amd64
image: developmentseed/osmseed-osmcha-web:v6
build:
context: ../images/osmcha-web
dockerfile: Dockerfile
# command: >
# /bin/bash -c "
# ./start.sh
# "
env_file:
- ../envs/.env.osmcha
volumes:
- ../data/osmcha/staticfiles:/staticfiles
db:
platform: linux/amd64
image: osmseed-osmcha-db:v1
build:
Expand All @@ -12,13 +26,27 @@ services:
- ../data/osmcha-db-data:/var/lib/postgresql/data
env_file:
- ../envs/.env.osmcha
osmcha-web:
api:
platform: linux/amd64
image: osmseed-osmcha-web:v1
image: developmentseed/osmseed-osmcha-api:v3
build:
context: ../images/osmcha-web
context: ../images/osmcha-api
dockerfile: Dockerfile
ports:
- '8000:8000'
- '3000:3000'
env_file:
- ../envs/.env.osmcha
volumes:
- ../data/osmcha/staticfiles:/staticfiles
nginx:
platform: linux/amd64
image: developmentseed/osmseed-osmcha-nginx:v1
build:
context: ../images/osmcha-nginx
dockerfile: Dockerfile
ports:
- '80:80'
env_file:
- ../envs/.env.osmcha
volumes:
- ../data/osmcha/staticfiles:/staticfiles
5 changes: 5 additions & 0 deletions images/osmcha-nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:alpine
COPY config/mime.types /etc/nginx/
COPY config/nginx.conf /etc/nginx/

# COPY --from=builder /app/build /assets
16 changes: 16 additions & 0 deletions images/osmcha-nginx/config/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/x-icon ico;
image/x-jng jng;
application/font-woff woff;
application/json json;
application/zip zip;
}
55 changes: 55 additions & 0 deletions images/osmcha-nginx/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
worker_processes 4;

events {
worker_connections 1024;
}

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

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

upstream app {
server host.docker.internal:5000;
}

server {
listen 80;
charset utf-8;

location ~ ^/static.* {
root /staticfiles;
try_files $uri @proxy_to_frontend;
}

location @proxy_to_frontend {
root /assets;
try_files $uri @django;
}

location / {
root /assets;
# checks for static file, if not found proxy to app
try_files $uri $uri/ @django;
}

location @django {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
}
8 changes: 2 additions & 6 deletions images/osmcha-web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ RUN yarn install

ENV REACT_APP_PRODUCTION_API_URL /api/v1
RUN yarn build:${BUILD_ENV}

FROM nginx:alpine
# COPY config/nginx.conf /etc/nginx/
# COPY config/mime.types /etc/nginx/
# RUN nginx -t
COPY --from=builder /app/build /assets
COPY start.sh .
CMD [ "./start.sh" ]
17 changes: 5 additions & 12 deletions images/osmcha-web/start.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#!/usr/bin/env bash
set -ex
sed -i "s|https://osmcha.org|$OSMCHA_URL|g" package.json
yarn build:prod
cp -R build/* /staticfiles/

# Build frontend
cd /osmcha-frontend
REACT_APP_VERSION=ohm REACT_APP_STACK=PRODUCTION PUBLIC_URL=$OSMCHA_URL npx react-scripts build
cp -R build/*.html /app/osmchadjango/frontend/templates/frontend/
cp -R build/* /app/osmchadjango/static/
cp -R build/static/* /app/osmchadjango/static/

# Start service
cd /app
python3 manage.py collectstatic --noinput
python3 manage.py migrate
supervisord -c /etc/supervisor/supervisord.conf
# mkdir -p /staticfiles/static/
# chmod a+rw /staticfiles/static/
114 changes: 114 additions & 0 deletions osm-seed/templates/osmcha-app/configMap-works.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{{- if .Values.osmchaApi.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-osmcha-common-env
data:
POSTGRES_HOST: {{ .Release.Name }}-osmcha-db
PGHOST: {{ .Release.Name }}-osmcha-db
POSTGRES_PORT: {{ .Values.osmchaDb.env.POSTGRES_PORT | quote }}
POSTGRES_USER: {{ .Values.osmchaDb.env.POSTGRES_USER | quote }}
POSTGRES_PASSWORD: {{ .Values.osmchaDb.env.POSTGRES_PASSWORD | quote }}
POSTGRES_DATABASE: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}
POSTGRES_DB: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}

# POSTGRES_HOST: {{ .Release.Name }}-osmcha-db
# POSTGRES_PORT: "5432"
# POSTGRES_USER: {{ .Values.osmchaDb.env.POSTGRES_USER | quote }}
# POSTGRES_PASSWORD: {{ .Values.osmchaDb.env.POSTGRES_PASSWORD | quote }}
# POSTGRES_DATABASE: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}

REDIS_URL: {{ .Release.Name }}-osmcha-redis

DJANGO_SETTINGS_MODULE: "config.settings.production"
OSMCHA_FRONTEND_VERSION: "v0.86.0-production"


OSM_SERVER_URL: {{ .Values.osmchaDb.env.OSM_SERVER_URL | quote }}
POSTGRES_DB: {{ .Values.osmchaDb.env.POSTGRES_DB | quote }}
PGHOST: {{ .Release.Name }}-osmcha-db
DJANGO_SECRET_KEY: {{ .Values.osmchaApi.env.DJANGO_SECRET_KEY | quote }}
C_FORCE_ROOT: {{ .Values.osmchaApi.env.C_FORCE_ROOT | quote }}
OSMCHA_URL: {{ .Values.osmchaApi.env.OSMCHA_URL | quote }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-osmcha-nginx-config
data:
nginx.conf: |
worker_processes 4;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream app {
server localhost:3000;
}
server {
listen 80;
charset utf-8;
location ~ ^/static.* {
root /staticfiles;
try_files $uri @proxy_to_frontend;
}
location @proxy_to_frontend {
root /assets;
try_files $uri @django;
}
location / {
root /assets;
# checks for static file, if not found proxy to app
try_files $uri $uri/ @django;
}
# cookiecutter-django app
location @django {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
}
mime.types: |
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/x-icon ico;
image/x-jng jng;
application/font-woff woff;
application/json json;
application/zip zip;
}
{{- end }}
Loading

0 comments on commit 1c243bd

Please sign in to comment.