Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nginx with uswgi #280

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions charts/substra-backend/templates/configmap-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,56 @@ data:
}

---

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "substra.fullname" . }}-server-uwsgi
data:
uwsgi.ini: |
[uwsgi]
# chdir = /usr/src/app
module = backend.wsgi
env = DJANGO_SETTINGS_MODULE=backend.settings.server.{{ .Values.backend.settings }}
static-map = /static=/usr/src/app/backend/statics

master = true
processes = {{ .Values.backend.uwsgiProcesses }}
threads = {{ .Values.backend.uwsgiThreads }}
http = :{{ .Values.backend.service.port }}
# socket = /tmp/substra-backend.sock
# chmod-socket = 664
socket = /var/substra/socket/uswgi.sock
chmod-socket = 666
vacuum = true

need-app = true
http-timeout = 300
socket-timeout = 300
harakiri = 300

---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "substra.fullname" . }}-server-nginx
data:
nginx.conf: |
worker_processes auto;

events {
# worker_connections 4096; ## Default: 1024
}
http {

upstream django {
server unix:///var/substra/socket/uswgi.sock;
}

server {
listen {{ .Values.backend.service.port }};
client_max_body_size 0;
location /static {
alias /usr/src/app/backend/statics;
}
location / {
include uwsgi_params;
uwsgi_pass unix:///var/substra/socket/uswgi.sock;
}
}
}
41 changes: 37 additions & 4 deletions charts/substra-backend/templates/deployment-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ spec:
{{- with .Values.extraEnv }}
{{ toYaml . | indent 10 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.backend.service.port }}
protocol: TCP
volumeMounts:
{{- range .Values.persistence.volumes }}
- name: data-{{ .name }}
Expand All @@ -99,6 +95,8 @@ spec:
mountPath: /var/substra/servermedias
- name: statics
mountPath: /usr/src/app/backend/statics
- name: uwsgi-socket
mountPath: /var/substra/socket
- name: config
mountPath: /conf/{{ .Values.organization.name }}/substra-backend
readOnly: true
Expand All @@ -120,6 +118,36 @@ spec:
- mountPath: /etc/ssl/certs
name: ssl-certs
{{- end }}
resources:
{{- toYaml .Values.backend.resources | nindent 12 }}
- name: {{ template "substra.name" . }}-nginx
image: nginx:1.19.0
{{- if .Values.backend.image.pullPolicy }}
imagePullPolicy: "{{ .Values.backend.image.pullPolicy }}"
{{- end }}
env:
{{- if .Values.privateCa.enabled }}
- name: REQUESTS_CA_BUNDLE
value: /etc/ssl/certs/ca-certificates.crt
{{- end }}
ports:
- name: http
containerPort: {{ .Values.backend.service.port }}
protocol: TCP
volumeMounts:
- name: statics
mountPath: /usr/src/app/backend/statics
readOnly: true
- name: uwsgi-socket
mountPath: /var/substra/socket
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
{{- if .Values.privateCa.enabled }}
- mountPath: /etc/ssl/certs
name: ssl-certs
{{- end }}
livenessProbe:
httpGet:
path: /liveness
Expand Down Expand Up @@ -229,12 +257,17 @@ spec:
claimName: {{ include "substra.fullname" $ }}-servermedias
- name: statics
emptyDir: {}
- name: uwsgi-socket
emptyDir: {}
- name: config
configMap:
name: {{ include "substra.fullname" . }}-server
- name: uwsgi
configMap:
name: {{ include "substra.fullname" . }}-server-uwsgi
- name: nginx-config
configMap:
name: {{ include "substra.fullname" . }}-server-nginx
- name: user-cert
secret:
secretName: {{ $.Values.secrets.user.cert }}
Expand Down