Skip to content

Commit

Permalink
Serve static files with nginx, not gunicorn
Browse files Browse the repository at this point in the history
Ref #78
  • Loading branch information
yuvipanda committed Sep 27, 2024
1 parent b8f41db commit 0664fd2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions helm-chart/templates/configmap-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ data:
tcp_nopush on;
}
location /static/ {
alias /opt/state/static/;
# Options for optimal local static content serving
# From https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/
sendfile on;
tcp_nopush on;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Expand Down
21 changes: 21 additions & 0 deletions helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ spec:
- name: django-yamlconf
mountPath: /opt/unnamed-thingity-thing/comptest/comptest.yaml
subPath: comptest.yaml
- name: collect-static
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
workingDir: /opt/unnamed-thingity-thing/comptest
command:
- python
- manage.py
- collectstatic
securityContext:
runAsUser: 0
volumeMounts:
- name: django-yamlconf
mountPath: /opt/unnamed-thingity-thing/comptest/comptest.yaml
subPath: comptest.yaml
- name: staticfiles
mountPath: /opt/staticfiles
- name: admin-add
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
Expand Down Expand Up @@ -85,6 +101,9 @@ spec:
- name: nginx-config
mountPath: /etc/nginx/conf.d/default.conf
subPath: default.conf
- name: staticfiles
mountPath: /opt/staticfiles
readOnly: true
ports:
- name: http
containerPort: {{ .Values.service.port }}
Expand All @@ -93,6 +112,8 @@ spec:
- name: storage
persistentVolumeClaim:
claimName: {{ include "unnamed.fullname" . }}
- name: staticfiles
emptyDir: {}
- name: django-yamlconf
configMap:
name: {{ include "unnamed.fullname" . }}-django-yamlconf
Expand Down

0 comments on commit 0664fd2

Please sign in to comment.