From 9a8ae072fdda904ba8459794a9ab9c658bf4ad15 Mon Sep 17 00:00:00 2001 From: Akshatha Nayak Date: Mon, 1 Feb 2021 16:51:26 +0530 Subject: [PATCH 1/2] set up alternative protocol hosting system --- protocol-hosting/protocol-hosting-server.yml | 72 ++++++++++++++++++++ protocol-hosting/pvc.yml | 11 +++ 2 files changed, 83 insertions(+) create mode 100644 protocol-hosting/protocol-hosting-server.yml create mode 100644 protocol-hosting/pvc.yml diff --git a/protocol-hosting/protocol-hosting-server.yml b/protocol-hosting/protocol-hosting-server.yml new file mode 100644 index 0000000..57d80c3 --- /dev/null +++ b/protocol-hosting/protocol-hosting-server.yml @@ -0,0 +1,72 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + name: file-storage + labels: + app: file-storage +spec: + selector: + matchLabels: + app: file-storage + strategy: + type: Recreate + template: + metadata: + labels: + app: file-storage + spec: + containers: + - name: file-storage-container + image: nginx + ports: + - containerPort: 80 + name: file-server + volumeMounts: + - mountPath: "/usr/share/nginx/html" + name: file-storage-volume + imagePullPolicy: Always + resources: {} + volumes: + - name: file-storage-volume + persistentVolumeClaim: + claimName: protocols-storage-pvc +--- + +kind: Service +apiVersion: v1 +metadata: + labels: + app: file-storage + name: file-storage +spec: + ports: + - name: http + port: 80 + selector: + app: file-storage +status: + loadBalancer: {} +--- + +kind: Ingress +apiVersion: extensions/v1beta1 +metadata: + name: nginx-ingress + annotations: + nginx.ingress.kubernetes.io/add-base-url: "true" + nginx.ingress.kubernetes.io/enable-cors: "true" + nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT" + nginx.ingress.kubernetes.io/proxy-body-size: 100m +spec: + tls: + - hosts: + - api.faang.org + secretName: tls-secret + rules: + - host: api.faang.org + http: + paths: + - path: /protocols + backend: + serviceName: file-storage + servicePort: 80 diff --git a/protocol-hosting/pvc.yml b/protocol-hosting/pvc.yml new file mode 100644 index 0000000..c140262 --- /dev/null +++ b/protocol-hosting/pvc.yml @@ -0,0 +1,11 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: protocols-storage-pvc +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 3Gi + storageClassName: nfs-client \ No newline at end of file From a8ec1e664228f58c850301358baf21591259acca Mon Sep 17 00:00:00 2001 From: Akshatha Nayak Date: Fri, 12 Feb 2021 21:23:10 +0530 Subject: [PATCH 2/2] fixed file upload and naming issues --- protocol-hosting/protocol-hosting-server.yml | 90 ++++++++++++++++++-- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/protocol-hosting/protocol-hosting-server.yml b/protocol-hosting/protocol-hosting-server.yml index 57d80c3..b2f6ab0 100644 --- a/protocol-hosting/protocol-hosting-server.yml +++ b/protocol-hosting/protocol-hosting-server.yml @@ -17,19 +17,25 @@ spec: spec: containers: - name: file-storage-container - image: nginx + image: openresty/openresty ports: - containerPort: 80 name: file-server volumeMounts: - - mountPath: "/usr/share/nginx/html" - name: file-storage-volume + - name: file-storage-volume + mountPath: "/usr/share/nginx/html" + - name: nginx-config + mountPath: /etc/nginx/conf.d/default.conf + subPath: nginx.conf imagePullPolicy: Always resources: {} volumes: - name: file-storage-volume persistentVolumeClaim: claimName: protocols-storage-pvc + - name: nginx-config + configMap: + name: nginx-configmap --- kind: Service @@ -53,10 +59,7 @@ apiVersion: extensions/v1beta1 metadata: name: nginx-ingress annotations: - nginx.ingress.kubernetes.io/add-base-url: "true" - nginx.ingress.kubernetes.io/enable-cors: "true" - nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT" - nginx.ingress.kubernetes.io/proxy-body-size: 100m + nginx.ingress.kubernetes.io/ssl-redirect: "false" spec: tls: - hosts: @@ -70,3 +73,76 @@ spec: backend: serviceName: file-storage servicePort: 80 +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: "nginx-configmap" +data: + nginx.conf: | + server { + listen 80; + listen [::]:80; + server_name api.faang.org; + add_header Allow "GET, POST" always; + location /protocols { + root /usr/share/nginx/html; + index index.html; + autoindex on; + } + + location /protocols_upload { + # http_filename (request header) : original filename (eg. "test.pdf") + # http_temploc (proxy header) : temp filename and path (eg. "/usr/share/nginx/html/protocols/samples/00000001") + # http_protocol (proxy header) : protocol type (eg. "samples") + content_by_lua_block { + os.rename(ngx.var.http_temploc, "/usr/share/nginx/html/protocols/" .. ngx.var.http_protocol .. "/" .. ngx.var.http_filename); + } + } + + location /protocols/samples/upload { + limit_except POST { deny all; } + client_body_temp_path /usr/share/nginx/html/protocols/samples; + client_body_in_file_only on; + client_body_buffer_size 128K; + client_max_body_size 50M; + proxy_pass_request_headers on; + proxy_set_header content-type "text/html"; + proxy_set_header temploc $request_body_file; + proxy_set_header protocol "samples"; + proxy_set_body $request_body_file; + proxy_pass http://api.faang.org/protocols_upload; + proxy_redirect off; + } + + location /protocols/experiments/upload { + limit_except POST { deny all; } + client_body_temp_path /usr/share/nginx/html/protocols/experiments; + client_body_in_file_only on; + client_body_buffer_size 128K; + client_max_body_size 50M; + proxy_pass_request_headers on; + proxy_set_header content-type "text/html"; + proxy_set_header temploc $request_body_file; + proxy_set_header protocol "experiments"; + proxy_set_body $request_body_file; + proxy_pass http://api.faang.org/protocols_upload; + proxy_redirect off; + } + + location /protocols/analyses/upload { + limit_except POST { deny all; } + client_body_temp_path /usr/share/nginx/html/protocols/analyses; + client_body_in_file_only on; + client_body_buffer_size 128K; + client_max_body_size 50M; + proxy_pass_request_headers on; + proxy_set_header content-type "text/html"; + proxy_set_header temploc $request_body_file; + proxy_set_header protocol "analyses"; + proxy_set_body $request_body_file; + proxy_pass http://api.faang.org/protocols_upload; + proxy_redirect off; + } + }