diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6d63849b9c6208bcc943c104eb1cb926212ea0f0..98434c9c29f1905c6fb7691d266e7e4b650ba813 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 af7cee3790c3b1697e54d15a29d0f4aac67488d2..84b0244801081caf4c68d641c4faf4a3717f69d9 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 0000000000000000000000000000000000000000..7b8954a7d5a3f3bd0e90f7468870a1d2f1256949 --- /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 0000000000000000000000000000000000000000..e69340db5bb4c765ccc4b50c610b84dd580ff17b --- /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 0000000000000000000000000000000000000000..0e8a0eb36f4ca2c939201c0d54b5d82a1ea34778 --- /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 0000000000000000000000000000000000000000..b3bf7cc2daf711d5ca47d1304d48b5fafb62365c --- /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 0000000000000000000000000000000000000000..04b928e7102d2f327a6e3ff4811cc759c3986982 --- /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 0000000000000000000000000000000000000000..2037ab521c0d36e87f1243d3c8bff9f0b74041c3 --- /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 0000000000000000000000000000000000000000..d634c1bd13e897b6aacc7049dee1f8cb182ba23c --- /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 0000000000000000000000000000000000000000..f6a97d973836c0a02781df321406664b4fa358ba --- /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 0000000000000000000000000000000000000000..9d44236e7b0ae03ee6e6ac7de2d465a27ee63e5b --- /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