Skip to content

Commit

Permalink
Update Helm chart to simplify deployment (#45)
Browse files Browse the repository at this point in the history
* Remove nginx config from helm chart
* Simplify static file collector
* Rename Postgres config env vars to match libpq
* Remove gunicorn CLI params (no longer needed)
* Tell nginx reverse proxy how to connect to django backend
* Bump to new versions of osmcha-frontend and osmcha-django
* Update backend health endpoint
  • Loading branch information
jake-low authored Nov 7, 2024
1 parent bf7225c commit 8a58e49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 159 deletions.
85 changes: 14 additions & 71 deletions helm/osmcha/templates/app.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: osmcha-frontend-nginx-config
data:
{{- toYaml .Values.app.ui.nginxConfig | nindent 2 }}

---

apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -24,83 +15,36 @@ spec:
metadata:
labels:
app: osmcha-app
annotations:
nginx-configmap-hash: {{ .Values.app.ui.nginxConfig | toJson | sha256sum | trunc 8 }}
spec:
initContainers:
- name: osmcha-init
image: {{ .Values.app.api.image.repository }}:{{ .Values.app.api.image.tag }}
command:
- /bin/sh
- -c
- |
python manage.py collectstatic --noinput
mkdir -p /staticfiles/static
cp -r /app/staticfiles/* /staticfiles/static/
command: ["python", "manage.py", "collectstatic", "--noinput"]

env:
- name: POSTGRES_HOST
value: {{ .Values.app.api.postgres_host}}
- name: PGHOST
value: {{ .Values.app.api.postgres_host}}
- name: POSTGRES_PORT
value: "5432"
- name: POSTGRES_USER
value: {{ .Values.app.api.postgres_user}}
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: osmcha-db-credentials
key: password
- name: POSTGRES_DATABASE
value: {{ .Values.app.api.postgres_database}}
- name: DJANGO_SECRET_KEY
valueFrom:
secretKeyRef:
name: django-secret-key
key: django_secret_key
- name: DJANGO_SETTINGS_MODULE
value: "config.settings.production"
- name: REDIS_URL
value: {{ .Values.app.api.redis_url }}
volumeMounts:
- name: staticfiles
mountPath: /staticfiles
mountPath: /app/staticfiles
containers:
- name: osmcha-api
image: {{ .Values.app.api.image.repository }}:{{ .Values.app.api.image.tag }}
command:
- gunicorn
- "--timeout"
- "120"
- "--keep-alive"
- "2"
- "--workers"
- "5"
- "--bind"
- 0.0.0.0:5000
- --log-file
- "-"
- --access-logfile
- "-"
- config.wsgi
resources:
{{- toYaml .Values.app.api.resources | nindent 10 }}
env:
- name: POSTGRES_HOST
value: {{ .Values.app.api.postgres_host}}
- name: PGHOST
value: {{ .Values.app.api.postgres_host}}
- name: POSTGRES_PORT
- name: PGPORT
value: "5432"
- name: POSTGRES_USER
- name: PGUSER
value: {{ .Values.app.api.postgres_user}}
- name: POSTGRES_PASSWORD
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: osmcha-db-credentials
key: password
- name: POSTGRES_DATABASE
- name: PGDATABASE
value: {{ .Values.app.api.postgres_database}}
- name: DJANGO_SECRET_KEY
valueFrom:
Expand All @@ -127,35 +71,34 @@ spec:
value: "False"
- name: DJANGO_ENABLE_CHANGESET_COMMENTS
value: "True"
- name: WEB_CONCURRENCY
value: "5"
ports:
- containerPort: 5000
volumeMounts:
- name: staticfiles
mountPath: /staticfiles
livenessProbe:
httpGet:
path: /health
path: /api/v1/health
port: 5000
scheme: HTTP
# initialDelaySeconds: 60
timeoutSeconds: 60
- name: frontend-nginx
image: "{{ .Values.app.ui.image.repository }}:{{ .Values.app.ui.image.tag }}"
env:
- name: BACKEND_URL
value: http://localhost:5000
ports:
- containerPort: 80
volumeMounts:
- name: osmcha-frontend-nginx-config
mountPath: /etc/nginx
readOnly: true
- name: staticfiles
mountPath: /staticfiles
mountPath: /srv/www/static/django
readOnly: true
volumes:
- name: staticfiles
emptyDir: {}
- name: osmcha-frontend-nginx-config
configMap:
name: osmcha-frontend-nginx-config
defaultMode: 0777
{{- if .Values.app.nodeSelector }}
nodeSelector:
{{- toYaml .Values.app.nodeSelector | nindent 8 }}
Expand Down
90 changes: 2 additions & 88 deletions helm/osmcha/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app:
api:
image:
repository: ghcr.io/osmcha/osmcha-django
tag: 59281c7cb1796bcd7406559d1186a70660adec10
tag: v4.26.0
resources:
requests:
memory: "2G"
Expand All @@ -35,93 +35,7 @@ app:
nodeSelector: {}
image:
repository: ghcr.io/osmcha/osmcha-frontend
tag: 646874a3739a03b6c91c131f652f4e727e5aa408

# Nginx config - templates/config-map.yaml
nginxConfig:
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;
}
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: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 $uri/ =404;
}
location /api {
try_files $uri $uri/ @django;
}
location /admin {
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;
fastcgi_connect_timeout 130;
fastcgi_send_timeout 130;
fastcgi_read_timeout 130;
}
location / {
root /assets;
try_files $uri $uri/ /index.html;
}
}
}
tag: v1.1.0

# OSMCha adiff service
adiff_service:
Expand Down

0 comments on commit 8a58e49

Please sign in to comment.