From 134a76e27be66d8c395c3e51dbabb18c48cd3f11 Mon Sep 17 00:00:00 2001 From: e542445 Date: Sun, 17 Nov 2024 15:24:27 +0100 Subject: [PATCH] split frontend and backend --- .github/workflows/connect-to-wireguard.yml | 13 ++++ .github/workflows/publish-backend-feature.yml | 10 +-- .github/workflows/publish-backend.yml | 10 +-- .github/workflows/publish-frontend.yml | 12 +--- deploy/frontend/.gitignore | 1 + deploy/frontend/.helmignore | 23 +++++++ deploy/frontend/Chart.yaml | 24 +++++++ deploy/frontend/templates/_helpers.tpl | 62 +++++++++++++++++++ .../templates/application}/deployment.yaml | 2 +- .../templates/application}/ingress.yaml | 4 +- .../templates/application}/service.yaml | 0 deploy/frontend/values.example.yaml | 4 ++ 12 files changed, 137 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/connect-to-wireguard.yml create mode 100644 deploy/frontend/.gitignore create mode 100644 deploy/frontend/.helmignore create mode 100644 deploy/frontend/Chart.yaml create mode 100644 deploy/frontend/templates/_helpers.tpl rename deploy/{backend/templates/application/frontend => frontend/templates/application}/deployment.yaml (89%) rename deploy/{backend/templates/application/frontend => frontend/templates/application}/ingress.yaml (85%) rename deploy/{backend/templates/application/frontend => frontend/templates/application}/service.yaml (100%) create mode 100644 deploy/frontend/values.example.yaml diff --git a/.github/workflows/connect-to-wireguard.yml b/.github/workflows/connect-to-wireguard.yml new file mode 100644 index 00000000..a0ab9147 --- /dev/null +++ b/.github/workflows/connect-to-wireguard.yml @@ -0,0 +1,13 @@ +name: Connect to wireguard +# Schema: https://json.schemastore.org/github-action.json + +runs: + using: 'composite' + steps: + - run: sudo apt install wireguard + - run: echo "${{ secrets.WIREGUARD_CLIENT_PRIVATE_KEY }}" > privatekey + - run: sudo ip link add dev wg0 type wireguard + - run: sudo ip address add dev wg0 ${{ secrets.WIREGUARD_CLIENT_IP }} peer ${{ secrets.WIREGUARD_ALLOWED_IPS }} + - run: sudo wg set wg0 private-key privatekey peer ${{ secrets.WIREGUARD_SERVER_PUBLIC_KEY }} allowed-ips ${{ secrets.WIREGUARD_ALLOWED_IPS }} endpoint ${{ secrets.WIREGUARD_ENDPOINT }} + - run: sudo ip link set up dev wg0 + diff --git a/.github/workflows/publish-backend-feature.yml b/.github/workflows/publish-backend-feature.yml index a3f202d9..d3b5c366 100644 --- a/.github/workflows/publish-backend-feature.yml +++ b/.github/workflows/publish-backend-feature.yml @@ -55,17 +55,11 @@ jobs: runs-on: ubuntu-latest needs: publish steps: - - run: sudo apt install wireguard - - run: echo "${{ secrets.WIREGUARD_CLIENT_PRIVATE_KEY }}" > privatekey - - run: sudo ip link add dev wg0 type wireguard - - run: sudo ip address add dev wg0 ${{ secrets.WIREGUARD_CLIENT_IP }} peer ${{ secrets.WIREGUARD_ALLOWED_IPS }} - - run: sudo wg set wg0 private-key privatekey peer ${{ secrets.WIREGUARD_SERVER_PUBLIC_KEY }} allowed-ips ${{ secrets.WIREGUARD_ALLOWED_IPS }} endpoint ${{ secrets.WIREGUARD_ENDPOINT }} - - run: sudo ip link set up dev wg0 - - uses: actions/checkout@v3 + - uses: ./.github/workflows/connect-to-wireguard.yml - name: Deploy uses: WyriHaximus/github-action-helm3@v3 with: - exec: echo '${{ secrets.VALUES_YAML_HOME_SYSTEM_FEATURE }}' | helm upgrade akops-home ./deploy/backend --install --wait --atomic --values - + exec: echo '${{ secrets.VALUES_YAML_HOME_SYSTEM_FEATURE }}' | helm upgrade akops-home-backend ./deploy/backend --install --wait --atomic --values - kubeconfig: '${{ secrets.K8S_CONF_AKOP_ONLINE }}' diff --git a/.github/workflows/publish-backend.yml b/.github/workflows/publish-backend.yml index 1dce18d5..92e6e2c9 100644 --- a/.github/workflows/publish-backend.yml +++ b/.github/workflows/publish-backend.yml @@ -54,17 +54,11 @@ jobs: runs-on: ubuntu-latest needs: publish steps: - - run: sudo apt install wireguard - - run: echo "${{ secrets.WIREGUARD_CLIENT_PRIVATE_KEY }}" > privatekey - - run: sudo ip link add dev wg0 type wireguard - - run: sudo ip address add dev wg0 ${{ secrets.WIREGUARD_CLIENT_IP }} peer ${{ secrets.WIREGUARD_ALLOWED_IPS }} - - run: sudo wg set wg0 private-key privatekey peer ${{ secrets.WIREGUARD_SERVER_PUBLIC_KEY }} allowed-ips ${{ secrets.WIREGUARD_ALLOWED_IPS }} endpoint ${{ secrets.WIREGUARD_ENDPOINT }} - - run: sudo ip link set up dev wg0 - - uses: actions/checkout@v3 + - uses: ./.github/workflows/connect-to-wireguard.yml - name: Deploy uses: WyriHaximus/github-action-helm3@v3 with: - exec: echo '${{ secrets.VALUES_YAML_HOME_SYSTEM }}' | helm upgrade akops-home ./deploy/backend --install --wait --atomic --values - + exec: echo '${{ secrets.VALUES_YAML_HOME_SYSTEM }}' | helm upgrade akops-home-backend ./deploy/backend --install --wait --atomic --values - kubeconfig: '${{ secrets.K8S_CONF_AKOP_ONLINE }}' diff --git a/.github/workflows/publish-frontend.yml b/.github/workflows/publish-frontend.yml index 241f6a37..1ad0d462 100644 --- a/.github/workflows/publish-frontend.yml +++ b/.github/workflows/publish-frontend.yml @@ -1,4 +1,4 @@ -name: Publish backend to DockerHub +name: Publish frontend on: push: branches: [ master, feature/* ] @@ -34,17 +34,11 @@ jobs: runs-on: ubuntu-latest needs: publish steps: - - run: sudo apt install wireguard - - run: echo "${{ secrets.WIREGUARD_CLIENT_PRIVATE_KEY }}" > privatekey - - run: sudo ip link add dev wg0 type wireguard - - run: sudo ip address add dev wg0 ${{ secrets.WIREGUARD_CLIENT_IP }} peer ${{ secrets.WIREGUARD_ALLOWED_IPS }} - - run: sudo wg set wg0 private-key privatekey peer ${{ secrets.WIREGUARD_SERVER_PUBLIC_KEY }} allowed-ips ${{ secrets.WIREGUARD_ALLOWED_IPS }} endpoint ${{ secrets.WIREGUARD_ENDPOINT }} - - run: sudo ip link set up dev wg0 - - uses: actions/checkout@v3 + - uses: ./.github/workflows/connect-to-wireguard.yml - name: Deploy uses: WyriHaximus/github-action-helm3@v3 with: - exec: echo '${{ secrets.VALUES_YAML_HOME_SYSTEM }}' | helm upgrade akops-home ./deploy/backend --install --wait --atomic --values - + exec: echo '${{ secrets.VALUES_YAML_HOME_SYSTEM_FRONTEND }}' | helm upgrade akops-home-frontend ./deploy/frontend --install --wait --atomic --values - kubeconfig: '${{ secrets.K8S_CONF_AKOP_ONLINE }}' diff --git a/deploy/frontend/.gitignore b/deploy/frontend/.gitignore new file mode 100644 index 00000000..7d101009 --- /dev/null +++ b/deploy/frontend/.gitignore @@ -0,0 +1 @@ +values.yaml \ No newline at end of file diff --git a/deploy/frontend/.helmignore b/deploy/frontend/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/deploy/frontend/.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/deploy/frontend/Chart.yaml b/deploy/frontend/Chart.yaml new file mode 100644 index 00000000..74b0bc96 --- /dev/null +++ b/deploy/frontend/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: home-system +description: A Helm chart for Kubernetes + +# 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.16.0" diff --git a/deploy/frontend/templates/_helpers.tpl b/deploy/frontend/templates/_helpers.tpl new file mode 100644 index 00000000..2fcd9c94 --- /dev/null +++ b/deploy/frontend/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "home-system.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "home-system.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "home-system.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "home-system.labels" -}} +helm.sh/chart: {{ include "home-system.chart" . }} +{{ include "home-system.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "home-system.selectorLabels" -}} +app.kubernetes.io/name: {{ include "home-system.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "home-system.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "home-system.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deploy/backend/templates/application/frontend/deployment.yaml b/deploy/frontend/templates/application/deployment.yaml similarity index 89% rename from deploy/backend/templates/application/frontend/deployment.yaml rename to deploy/frontend/templates/application/deployment.yaml index 76a81206..818278ad 100644 --- a/deploy/backend/templates/application/frontend/deployment.yaml +++ b/deploy/frontend/templates/application/deployment.yaml @@ -30,7 +30,7 @@ spec: automountServiceAccountToken: false containers: - name: backend - image: {{ .Values.frontend.image.base }}:{{ .Values.frontend.image.tag }} + image: {{ .Values.image.base }}:{{ .Values.image.tag }} imagePullPolicy: Always ports: - containerPort: 4000 diff --git a/deploy/backend/templates/application/frontend/ingress.yaml b/deploy/frontend/templates/application/ingress.yaml similarity index 85% rename from deploy/backend/templates/application/frontend/ingress.yaml rename to deploy/frontend/templates/application/ingress.yaml index 3bd26755..0fcf07f6 100644 --- a/deploy/backend/templates/application/frontend/ingress.yaml +++ b/deploy/frontend/templates/application/ingress.yaml @@ -8,7 +8,7 @@ metadata: spec: rules: - - host: {{ .Values.frontend.host }} + - host: {{ .Values.host }} http: paths: - path: / @@ -21,5 +21,5 @@ spec: tls: - hosts: - - {{ .Values.frontend.host }} + - {{ .Values.host }} secretName: home-system-frontend diff --git a/deploy/backend/templates/application/frontend/service.yaml b/deploy/frontend/templates/application/service.yaml similarity index 100% rename from deploy/backend/templates/application/frontend/service.yaml rename to deploy/frontend/templates/application/service.yaml diff --git a/deploy/frontend/values.example.yaml b/deploy/frontend/values.example.yaml new file mode 100644 index 00000000..460222a4 --- /dev/null +++ b/deploy/frontend/values.example.yaml @@ -0,0 +1,4 @@ +image: + base: akop/home-system-frontend + tag: latest +host: host-which-will-be-used-for-frontend.webhook.com