From 565c2f658567be724561818b587fc4449f2eb88b Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Sat, 23 Nov 2024 15:14:23 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=91=B7=20Added=20Helm-Chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helm/.helmignore | 23 +++ helm/Chart.yaml | 6 + helm/templates/deployment.yaml | 27 ++++ .../templates/ingress.yaml | 136 +++++++----------- helm/templates/namespace.yaml | 4 + helm/templates/service.yaml | 12 ++ helm/values.yaml | 4 + 7 files changed, 130 insertions(+), 82 deletions(-) create mode 100644 helm/.helmignore create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/deployment.yaml rename "deployment/Fachinformatiker-Pr\303\274fungsvorbereitung.yaml" => helm/templates/ingress.yaml (77%) create mode 100644 helm/templates/namespace.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/values.yaml diff --git a/helm/.helmignore b/helm/.helmignore new file mode 100644 index 00000000..691fa13d --- /dev/null +++ b/helm/.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/ \ No newline at end of file diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 00000000..2eeb92de --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: fi-vorbereitung +description: A Helm chart for Kubernetes +type: application +version: 0.0.1 +appVersion: 0.0.1 \ No newline at end of file diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 00000000..c414fcf1 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fi-pv-deployment + namespace: {{ .Values.namespace }} +spec: + selector: + matchLabels: + app: fi-pv + template: + metadata: + labels: + app: fi-pv + spec: + containers: + - name: fi-pv + image: lnadev/fi-pv:{{ .Values.runNumber }} + imagePullPolicy: Always + resources: + requests: + memory: "128Mi" + cpu: "50m" + limits: + memory: "128Mi" + ports: + - containerPort: 80 + name: port-http \ No newline at end of file diff --git "a/deployment/Fachinformatiker-Pr\303\274fungsvorbereitung.yaml" b/helm/templates/ingress.yaml similarity index 77% rename from "deployment/Fachinformatiker-Pr\303\274fungsvorbereitung.yaml" rename to helm/templates/ingress.yaml index 64ff538e..41f1046b 100644 --- "a/deployment/Fachinformatiker-Pr\303\274fungsvorbereitung.yaml" +++ b/helm/templates/ingress.yaml @@ -1,46 +1,8 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: fi-pv-deployment -spec: - selector: - matchLabels: - app: fi-pv - template: - metadata: - labels: - app: fi-pv - spec: - containers: - - name: fi-pv - image: lnadev/fi-pv:{{RUN_NUMBER}} - imagePullPolicy: Always - resources: - limits: - memory: "128Mi" - cpu: "500m" - ports: - - containerPort: 80 - name: port-http - ---- -apiVersion: v1 -kind: Service -metadata: - name: fi-pv-service -spec: - selector: - app: fi-pv - ports: - - port: 80 - targetPort: port-http - name: http - ---- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: fi-pv-ingress + namespace: {{ .Values.namespace }} annotations: cert-manager.io/cluster-issuer: letsencrypt traefik.ingress.kubernetes.io/router.entrypoints: websecure @@ -48,11 +10,11 @@ metadata: spec: tls: - hosts: - - "fachinformatikerpruefungsvorbereitung.de" - - "www.fachinformatikerpruefungsvorbereitung.de" + - "{{ .Values.domain }}" + - "www.{{ .Values.domain }}" secretName: fi-pv-cert rules: - - host: fachinformatikerpruefungsvorbereitung.de + - host: "{{ .Values.domain }}" http: paths: - path: / @@ -62,7 +24,7 @@ spec: name: fi-pv-service port: number: 80 - - host: www.fachinformatikerpruefungsvorbereitung.de + - host: www.{{ .Values.domain }} http: paths: - path: / @@ -74,22 +36,18 @@ spec: number: 80 --- +# Needed because of HTTP to HTTPS redirecting apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: fi-pv-redirection-ingress + name: fi-pv-ingress-http + namespace: {{ .Values.namespace }} annotations: - cert-manager.io/cluster-issuer: letsencrypt - traefik.ingress.kubernetes.io/router.entrypoints: websecure - traefik.ingress.kubernetes.io/router.middlewares: default-redirectschemefipv@kubernetescrd + traefik.ingress.kubernetes.io/router.entrypoints: web + traefik.ingress.kubernetes.io/router.middlewares: default-redirectscheme@kubernetescrd spec: - tls: - - hosts: - - "xn--fachinformatiker-prfungsvorbereitung-w0d.de" - - "fi.lna-dev.net" - secretName: fi-pv-cert-fipv rules: - - host: xn--fachinformatiker-prfungsvorbereitung-w0d.de + - host: "{{ .Values.domain }}" http: paths: - path: / @@ -99,7 +57,7 @@ spec: name: fi-pv-service port: number: 80 - - host: fi.lna-dev.net + - host: www.{{ .Values.domain }} http: paths: - path: / @@ -110,15 +68,49 @@ spec: port: number: 80 +--- +apiVersion: traefik.containo.us/v1alpha1 +kind: Middleware +metadata: + name: redirectscheme + namespace: {{ .Values.namespace }} +spec: + redirectRegex: + regex: '^https?://(?:www\.)?(.+)' + replacement: "https://${1}" + permanent: true + +--- +apiVersion: traefik.containo.us/v1alpha1 +kind: Middleware +metadata: + name: redirectschemefipv + namespace: {{ .Values.namespace }} +spec: + redirectRegex: + regex: '.*' + replacement: "https://{{ .Values.domain }}" + permanent: true + + + +{{- if .Values.production }} --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: fi-pv-redirection-ingress-http + name: fi-pv-redirection-ingress + namespace: {{ .Values.namespace }} annotations: - traefik.ingress.kubernetes.io/router.entrypoints: web + cert-manager.io/cluster-issuer: letsencrypt + traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.middlewares: default-redirectschemefipv@kubernetescrd spec: + tls: + - hosts: + - "xn--fachinformatiker-prfungsvorbereitung-w0d.de" + - "fi.lna-dev.net" + secretName: fi-pv-cert-fipv rules: - host: xn--fachinformatiker-prfungsvorbereitung-w0d.de http: @@ -142,17 +134,17 @@ spec: number: 80 --- -# Needed because of HTTP to HTTPS redirecting apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: fi-pv-ingress-http + name: fi-pv-redirection-ingress-http + namespace: {{ .Values.namespace }} annotations: traefik.ingress.kubernetes.io/router.entrypoints: web - traefik.ingress.kubernetes.io/router.middlewares: default-redirectscheme@kubernetescrd + traefik.ingress.kubernetes.io/router.middlewares: default-redirectschemefipv@kubernetescrd spec: rules: - - host: fachinformatikerpruefungsvorbereitung.de + - host: xn--fachinformatiker-prfungsvorbereitung-w0d.de http: paths: - path: / @@ -162,7 +154,7 @@ spec: name: fi-pv-service port: number: 80 - - host: www.fachinformatikerpruefungsvorbereitung.de + - host: fi.lna-dev.net http: paths: - path: / @@ -173,24 +165,4 @@ spec: port: number: 80 ---- -apiVersion: traefik.containo.us/v1alpha1 -kind: Middleware -metadata: - name: redirectscheme -spec: - redirectRegex: - regex: '^https?://(?:www\.)?(.+)' - replacement: "https://${1}" - permanent: true - ---- -apiVersion: traefik.containo.us/v1alpha1 -kind: Middleware -metadata: - name: redirectschemefipv -spec: - redirectRegex: - regex: '.*' - replacement: "https://fachinformatikerpruefungsvorbereitung.de" - permanent: true +{{- end }} \ No newline at end of file diff --git a/helm/templates/namespace.yaml b/helm/templates/namespace.yaml new file mode 100644 index 00000000..59f79447 --- /dev/null +++ b/helm/templates/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.namespace }} \ No newline at end of file diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 00000000..78a81e92 --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: fi-pv-service + namespace: {{ .Values.namespace }} +spec: + selector: + app: fi-pv + ports: + - port: 80 + targetPort: port-http + name: http \ No newline at end of file diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 00000000..ed625b6c --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,4 @@ +runNumber: 0 +domain: fachinformatikerpruefungsvorbereitung.de +namespace: fi-pv +production: true \ No newline at end of file From 071b973862bc19c70abb3dd27f57c1cab213fe24 Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Sat, 23 Nov 2024 15:49:52 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=B7=20Prepared=20dev=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/HugoBuildDev.yaml | 19 +++++++++++++++++++ helm/templates/ingress.yaml | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/HugoBuildDev.yaml b/.github/workflows/HugoBuildDev.yaml index f190d4f1..3ea6d808 100644 --- a/.github/workflows/HugoBuildDev.yaml +++ b/.github/workflows/HugoBuildDev.yaml @@ -56,3 +56,22 @@ jobs: - name: Push the image to dockerhub run: docker push lnadev/${{ env.CONTAINER-NAME }}:dev + + DeployContainer: + needs: ReleaseDEV + runs-on: ubuntu-latest + + steps: + # Download Secure-File + - name: base64-to-file + id: write_file + uses: timheuer/base64-to-file@v1.1 + with: + fileName: "custom-config" + encodedString: ${{ secrets.KUBECTL_CONFIG }} + + # Checkout the repository + - uses: actions/checkout@v3 + + # Deploy Kubernetes YAML + - run: helm upgrade --install fi-pv-dev ./helm --kubeconfig ${{ steps.write_file.outputs.filePath }} --set runNumber=dev,domain=dev.fachinformatikerpruefungsvorbereitung.de,namespace=fi-pv-dev,production=false diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml index 41f1046b..9a330c10 100644 --- a/helm/templates/ingress.yaml +++ b/helm/templates/ingress.yaml @@ -6,7 +6,7 @@ metadata: annotations: cert-manager.io/cluster-issuer: letsencrypt traefik.ingress.kubernetes.io/router.entrypoints: websecure - traefik.ingress.kubernetes.io/router.middlewares: default-redirectscheme@kubernetescrd + traefik.ingress.kubernetes.io/router.middlewares: {{ .Values.namespace }}-redirectscheme@kubernetescrd spec: tls: - hosts: @@ -69,7 +69,7 @@ spec: number: 80 --- -apiVersion: traefik.containo.us/v1alpha1 +apiVersion: traefik.io/v1alpha1 kind: Middleware metadata: name: redirectscheme @@ -81,7 +81,7 @@ spec: permanent: true --- -apiVersion: traefik.containo.us/v1alpha1 +apiVersion: traefik.io/v1alpha1 kind: Middleware metadata: name: redirectschemefipv From dd353bd9a04c4431dc5b02ed3c9a7db33780f960 Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Sat, 23 Nov 2024 15:54:29 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=91=B7=20Updated=20release=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/HugoBuildAndDeploy.yaml | 9 +-------- .github/workflows/HugoBuildDev.yaml | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/HugoBuildAndDeploy.yaml b/.github/workflows/HugoBuildAndDeploy.yaml index 4fb03010..5ed4798f 100644 --- a/.github/workflows/HugoBuildAndDeploy.yaml +++ b/.github/workflows/HugoBuildAndDeploy.yaml @@ -85,12 +85,5 @@ jobs: # Checkout the repository - uses: actions/checkout@v3 - - name: Find and Replace - uses: jacobtomlinson/gha-find-replace@v3 - with: - find: "{{RUN_NUMBER}}" - replace: ${{ github.run_number }} - regex: false - # Deploy Kubernetes YAML - - run: kubectl apply -f ./deployment/Fachinformatiker-Prüfungsvorbereitung.yaml --kubeconfig ${{ steps.write_file.outputs.filePath }} + - run: helm upgrade --install fi-pv ./helm --kubeconfig ${{ steps.write_file.outputs.filePath }} --set runNumber=${{ github.run_number }} diff --git a/.github/workflows/HugoBuildDev.yaml b/.github/workflows/HugoBuildDev.yaml index 3ea6d808..f18b70d7 100644 --- a/.github/workflows/HugoBuildDev.yaml +++ b/.github/workflows/HugoBuildDev.yaml @@ -25,7 +25,7 @@ jobs: extended: true # Build the hugo repository - - run: hugo + - run: hugo -e development --baseURL "https://dev.fachinformatikerpruefungsvorbereitung.de" working-directory: ./${{ env.NAME }}/ # Zip the Artifact for GitHubPages deployment