From 8b790a21df9c17150fbf5ff6a6a97727e7b38ca2 Mon Sep 17 00:00:00 2001 From: Sebastian <sebastian.karius@informatik.uni-halle.de> Date: Mon, 28 Oct 2024 16:47:44 +0100 Subject: [PATCH] add nginx-cors --- .gitlab-ci.yml | 3 ++ docker-compose.yml | 10 +++++- docker/nginx-cors/Dockerfile | 4 +++ docker/nginx-cors/nginx.conf.template | 32 ++++++++++++++++++ helm/nginx-cors/.helmignore | 23 +++++++++++++ helm/nginx-cors/Chart.yaml | 24 ++++++++++++++ helm/nginx-cors/templates/NOTES.txt | 3 ++ helm/nginx-cors/templates/deployment.yaml | 40 +++++++++++++++++++++++ helm/nginx-cors/templates/ingress.yaml | 22 +++++++++++++ helm/nginx-cors/templates/service.yaml | 14 ++++++++ helm/nginx-cors/values.yaml | 3 ++ 11 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 docker/nginx-cors/Dockerfile create mode 100644 docker/nginx-cors/nginx.conf.template create mode 100644 helm/nginx-cors/.helmignore create mode 100644 helm/nginx-cors/Chart.yaml create mode 100644 helm/nginx-cors/templates/NOTES.txt create mode 100644 helm/nginx-cors/templates/deployment.yaml create mode 100644 helm/nginx-cors/templates/ingress.yaml create mode 100644 helm/nginx-cors/templates/service.yaml create mode 100644 helm/nginx-cors/values.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6d63849..98434c9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,11 +39,13 @@ helm-package: - helm dep build helm/ti-coder - helm package helm/ti-coder - helm package helm/ti-lamp + - helm package helm/nginx-cors artifacts: paths: - vdo-ninja-0.1.2.tgz - ti-coder-0.2.6.tgz - ti-lamp-0.1.2.tgz + - nginx-cors-0.1.0.tgz expire_in: 1 hour helm-publish: @@ -60,6 +62,7 @@ helm-publish: - 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@vdo-ninja-0.1.2.tgz" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts"' - 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@ti-coder-0.2.6.tgz" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts"' - 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@ti-lamp-0.1.2.tgz" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts"' + - 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@nginx-cors-0.1.0.tgz" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts"' stages: - build diff --git a/docker-compose.yml b/docker-compose.yml index af7cee3..84b0244 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,4 +37,12 @@ services: dockerfile: Dockerfile context: ./docker/php-fpm_83 cache_from: - - ${CI_REGISTRY}/studio-r215/containerize/php-fpm:83 \ No newline at end of file + - ${CI_REGISTRY}/studio-r215/containerize/php-fpm:83 + + nginx-cors: + image: ${CI_REGISTRY}/studio-r215/containerize/nginx-cors:1.0.0 + build: + dockerfile: Dockerfile + context: ./docker/nginx-cors + cache_from: + - ${CI_REGISTRY}/studio-r215/containerize/nginx-cors:1.0.0 \ No newline at end of file diff --git a/docker/nginx-cors/Dockerfile b/docker/nginx-cors/Dockerfile new file mode 100644 index 0000000..7b8954a --- /dev/null +++ b/docker/nginx-cors/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:alpine + +COPY nginx.conf.template nginx.conf.template +CMD [ "/bin/sh" , "-c" , "envsubst < /nginx.conf.template > /etc/nginx/nginx.conf && exec nginx -g 'daemon off;'" ] \ No newline at end of file diff --git a/docker/nginx-cors/nginx.conf.template b/docker/nginx-cors/nginx.conf.template new file mode 100644 index 0000000..e69340d --- /dev/null +++ b/docker/nginx-cors/nginx.conf.template @@ -0,0 +1,32 @@ +upstream api { + # Could be host.docker.internal - Docker for Mac/Windows - the host itself + # Could be your API in a appropriate domain + # Could be other container in the same network, like container_name:port + server ${API_URL}; +} + +server { + listen 80; + server_name localhost; + + location / { + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent, + X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; + add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; + add_header 'Content-Type' 'application/json'; + add_header 'Content-Length' 0; + return 204; + } + + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent, + X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; + add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; + + proxy_pass http://api/; + } +} \ No newline at end of file diff --git a/helm/nginx-cors/.helmignore b/helm/nginx-cors/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/nginx-cors/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/nginx-cors/Chart.yaml b/helm/nginx-cors/Chart.yaml new file mode 100644 index 0000000..b3bf7cc --- /dev/null +++ b/helm/nginx-cors/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: nginx-cors +description: Nginx reverse proxy with cors set to * + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/helm/nginx-cors/templates/NOTES.txt b/helm/nginx-cors/templates/NOTES.txt new file mode 100644 index 0000000..04b928e --- /dev/null +++ b/helm/nginx-cors/templates/NOTES.txt @@ -0,0 +1,3 @@ +Installed nginx cors * reverse proxy. + +https://{{ .Values.url }} \ No newline at end of file diff --git a/helm/nginx-cors/templates/deployment.yaml b/helm/nginx-cors/templates/deployment.yaml new file mode 100644 index 0000000..2037ab5 --- /dev/null +++ b/helm/nginx-cors/templates/deployment.yaml @@ -0,0 +1,40 @@ +apiVersion: apps/v1 +kind: Deployment + +metadata: + name: nginx-cors + labels: + app: nginx-cors + +spec: + replicas: 1 + selector: + matchLabels: + app: nginx-cors + template: + metadata: + name: nginx-cors + labels: + app: nginx-cors + spec: + containers: + - name: nginx-cors + image: "mcr.informatik.uni-halle.de/studio-r215/containerize/nginx-cors:{{ .Chart.AppVersion }}" + resources: + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "128Mi" + cpu: "100m" + env: + - name: API_URL + value: {{ .Values.api }} + ports: + - containerPort: 80 + readinessProbe: + httpGet: + port: 80 + initialDelaySeconds: 10 + periodSeconds: 20 + restartPolicy: Always \ No newline at end of file diff --git a/helm/nginx-cors/templates/ingress.yaml b/helm/nginx-cors/templates/ingress.yaml new file mode 100644 index 0000000..d634c1b --- /dev/null +++ b/helm/nginx-cors/templates/ingress.yaml @@ -0,0 +1,22 @@ +{{- if .Values.url }} +apiVersion: networking.k8s.io/v1 +kind: Ingress + +metadata: + name: nginx-cors-ingress + labels: + app: nginx-cors + +spec: + rules: + - host: "{{ .Values.url }}.tikube.informatik.uni-halle.de" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: nginx-cors-service + port: + number: 80 +{{- end }} \ No newline at end of file diff --git a/helm/nginx-cors/templates/service.yaml b/helm/nginx-cors/templates/service.yaml new file mode 100644 index 0000000..f6a97d9 --- /dev/null +++ b/helm/nginx-cors/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-cors-service + labels: + app: nginx-cors +spec: + selector: + app: nginx-cors + ports: + - protocol: TCP + port: 80 + targetPort: 80 + type: ClusterIP \ No newline at end of file diff --git a/helm/nginx-cors/values.yaml b/helm/nginx-cors/values.yaml new file mode 100644 index 0000000..9d44236 --- /dev/null +++ b/helm/nginx-cors/values.yaml @@ -0,0 +1,3 @@ +# url definiert den URL Prefix für die Anwendung. Wenn url nicht definiert ist, wird der Ingress nicht erstellt. +url: ~ +api: ~ \ No newline at end of file -- GitLab