Skip to content

Commit

Permalink
Make NGINX serve static content directly (#331)
Browse files Browse the repository at this point in the history
* Add init container to copy static contents

* Add config to serve static directly

* Parametrize location within NGINX pod

* Add mime.types explicitly in nginx conf
  • Loading branch information
almahmoud authored Sep 30, 2021
1 parent 96026d5 commit 353021b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ current default values can be found in `values.yaml` file.
| `nginx.image.tag` | The Nginx version to pull. |
| `nginx.image.repository` | Where to obtain the Nginx container. |
| `nginx.image.pullPolicy` | When Kubernetes will [pull](https://kubernetes.io/docs/concepts/containers/images/#updating-images) the Nginx image from the repository. |
| `nginx.galaxyStaticDir` | Location at which to copy Galaxy static content in the NGINX pod init container, for direct serving. Defaults to `/galaxy/server/static` |


# Handlers

Expand Down
6 changes: 6 additions & 0 deletions galaxy/templates/configmap-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data:
http {
default_type application/octet-stream;
include /etc/nginx/mime.types;
sendfile on;
keepalive_timeout 65;
index index.html index.php index.htm;
Expand All @@ -37,6 +38,11 @@ data:
listen 80;
server_name galaxy;
location {{ template "galaxy.add_trailing_slash" .Values.ingress.path }}static {
alias {{ .Values.nginx.galaxyStaticDir }};
expires 24h;
}
location {{ template "galaxy.add_trailing_slash" .Values.ingress.path }} {
uwsgi_pass {{ template "galaxy.fullname" . }}-uwsgi:4001;
uwsgi_param UWSGI_SCHEME $scheme;
Expand Down
13 changes: 13 additions & 0 deletions galaxy/templates/deployment-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ spec:
{{- if .Values.webHandlers.podSpecExtra -}}
{{- tpl (toYaml .Values.webHandlers.podSpecExtra) . | nindent 6 }}
{{- end }}
initContainers:
- name: {{ .Chart.Name }}-init-static
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.nginx.image.pullPolicy }}
volumeMounts:
- name: static-dir
mountPath: /tmp/galaxy
command: ['/bin/sh', '-c', 'cp -r /galaxy/server/static /tmp/galaxy/static;']
containers:
- name: {{ .Chart.Name }}-nginx
image: "{{ .Values.nginx.image.repository }}:{{ .Values.nginx.image.tag }}"
Expand All @@ -44,6 +52,9 @@ spec:
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: static-dir
mountPath: {{ .Values.nginx.galaxyStaticDir }}
subPath: static
- name: galaxy-data
mountPath: {{ .Values.persistence.mountPath }}
- name: galaxy-data
Expand Down Expand Up @@ -73,6 +84,8 @@ spec:
- name: nginx-conf
configMap:
name: {{ template "galaxy.fullname" $ }}-nginx-conf
- name: static-dir
emptyDir: {}
- name: galaxy-data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
Expand Down
1 change: 1 addition & 0 deletions galaxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,5 @@ nginx:
pullPolicy: IfNotPresent
conf:
client_max_body_size: 100g
galaxyStaticDir: "/galaxy/server/static"

0 comments on commit 353021b

Please sign in to comment.