From 737b4b2d5c76585a63534ab00a27d95431e975a5 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 17:07:47 +0200 Subject: [PATCH 01/52] Added Helm chart for frontend --- helm/frontend/.helmignore | 23 ++++++++++++++++++ helm/frontend/Chart.yaml | 24 +++++++++++++++++++ helm/frontend/templates/NOTES.txt | 0 .../templates/frontend-deployment.yaml | 21 ++++++++++++++++ .../templates/frontend-namespace.yaml | 6 +++++ helm/frontend/templates/frontend-service.yaml | 14 +++++++++++ helm/frontend/values.yaml | 8 +++++++ 7 files changed, 96 insertions(+) create mode 100644 helm/frontend/.helmignore create mode 100644 helm/frontend/Chart.yaml create mode 100644 helm/frontend/templates/NOTES.txt create mode 100644 helm/frontend/templates/frontend-deployment.yaml create mode 100644 helm/frontend/templates/frontend-namespace.yaml create mode 100644 helm/frontend/templates/frontend-service.yaml create mode 100644 helm/frontend/values.yaml diff --git a/helm/frontend/.helmignore b/helm/frontend/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/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/helm/frontend/Chart.yaml b/helm/frontend/Chart.yaml new file mode 100644 index 0000000..147b26c --- /dev/null +++ b/helm/frontend/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: frontend +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/helm/frontend/templates/NOTES.txt b/helm/frontend/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml new file mode 100644 index 0000000..87b589d --- /dev/null +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Deployment +metadata: + name: {{ .Values.appName }} + labels: + app: {{ .Values.appName }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + appp: {{ .Values.appName }} + template: + metadata: + labels: + app: {{ .Values.appName }} + spec: + containers: + - name: {{ .Values.appName }} + image: {{ .Values.imageName }}:{{ .Values.imageLabel }} + ports: + - containerPort: {{ .Values.port }} \ No newline at end of file diff --git a/helm/frontend/templates/frontend-namespace.yaml b/helm/frontend/templates/frontend-namespace.yaml new file mode 100644 index 0000000..b073657 --- /dev/null +++ b/helm/frontend/templates/frontend-namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.appName }} + labels: + name: {{ .Values.appName }} diff --git a/helm/frontend/templates/frontend-service.yaml b/helm/frontend/templates/frontend-service.yaml new file mode 100644 index 0000000..27d28ac --- /dev/null +++ b/helm/frontend/templates/frontend-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.appName }} + labels: + app: {{ .Values.appName }} +spec: + type: LoadBalancer + selector: + app: {{ .Values.appName }} + ports: + - protocol: TCP + port: {{ .Values.port }} + targetPort: {{ .Values.port }} \ No newline at end of file diff --git a/helm/frontend/values.yaml b/helm/frontend/values.yaml new file mode 100644 index 0000000..8e0dddb --- /dev/null +++ b/helm/frontend/values.yaml @@ -0,0 +1,8 @@ +appName: frontend + +replicas: 1 + +imageName: ghcr.io/austriandatalab/indiegamestream/frontend +imageLabel: latest + +port: 80 \ No newline at end of file From ebcfe5367fae1c518b2b191a460eec1ce8ce4485 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 17:11:48 +0200 Subject: [PATCH 02/52] Fixed apiVersion for frontend deployment manifest --- helm/frontend/templates/frontend-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml index 87b589d..05bd4d6 100644 --- a/helm/frontend/templates/frontend-deployment.yaml +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -1,4 +1,4 @@ -apiVersion: v1 +apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Values.appName }} From 3ad894031638c3ed176a53007d7edeeb88c83b79 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 17:13:12 +0200 Subject: [PATCH 03/52] Fixed typo --- helm/frontend/templates/frontend-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml index 05bd4d6..4a46426 100644 --- a/helm/frontend/templates/frontend-deployment.yaml +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -8,7 +8,7 @@ spec: replicas: {{ .Values.replicas }} selector: matchLabels: - appp: {{ .Values.appName }} + app: {{ .Values.appName }} template: metadata: labels: From 06a8a2ab001254155b087b8b7386e5afd1cb5590 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 17:14:53 +0200 Subject: [PATCH 04/52] Added namesapce --- helm/frontend/templates/frontend-deployment.yaml | 1 + helm/frontend/templates/frontend-service.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml index 4a46426..39a3021 100644 --- a/helm/frontend/templates/frontend-deployment.yaml +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -2,6 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Values.appName }} + namespace: {{ .Values.appName }} labels: app: {{ .Values.appName }} spec: diff --git a/helm/frontend/templates/frontend-service.yaml b/helm/frontend/templates/frontend-service.yaml index 27d28ac..cfd960d 100644 --- a/helm/frontend/templates/frontend-service.yaml +++ b/helm/frontend/templates/frontend-service.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: {{ .Values.appName }} + namespace: {{ .Values.appName }} labels: app: {{ .Values.appName }} spec: From 70381a2f3fe21615df18759c894aadeca213b4ff Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 17:32:49 +0200 Subject: [PATCH 05/52] Small changes --- helm/frontend/values-dev.yaml | 3 +++ helm/frontend/values.yaml | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 helm/frontend/values-dev.yaml diff --git a/helm/frontend/values-dev.yaml b/helm/frontend/values-dev.yaml new file mode 100644 index 0000000..5108aad --- /dev/null +++ b/helm/frontend/values-dev.yaml @@ -0,0 +1,3 @@ +image: + name: frontend + pullPolicy: Never \ No newline at end of file diff --git a/helm/frontend/values.yaml b/helm/frontend/values.yaml index 8e0dddb..830e5bd 100644 --- a/helm/frontend/values.yaml +++ b/helm/frontend/values.yaml @@ -2,7 +2,9 @@ appName: frontend replicas: 1 -imageName: ghcr.io/austriandatalab/indiegamestream/frontend -imageLabel: latest +image: + name: ghcr.io/austriandatalab/indiegamestream/frontend + label: latest + pullPolicy: IfNotPresent port: 80 \ No newline at end of file From 0f7b298fb5632a2d7f6cb18431132bf07f49741f Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 17:39:54 +0200 Subject: [PATCH 06/52] Added imagePullPolicy --- helm/frontend/templates/frontend-deployment.yaml | 3 ++- helm/frontend/values-dev.yaml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml index 39a3021..863c37b 100644 --- a/helm/frontend/templates/frontend-deployment.yaml +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -17,6 +17,7 @@ spec: spec: containers: - name: {{ .Values.appName }} - image: {{ .Values.imageName }}:{{ .Values.imageLabel }} + image: {{ .Values.image.name }}:{{ .Values.image.label }} + imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - containerPort: {{ .Values.port }} \ No newline at end of file diff --git a/helm/frontend/values-dev.yaml b/helm/frontend/values-dev.yaml index 5108aad..fc49b3c 100644 --- a/helm/frontend/values-dev.yaml +++ b/helm/frontend/values-dev.yaml @@ -1,3 +1,4 @@ image: name: frontend + label: latest pullPolicy: Never \ No newline at end of file From 30ad34bd3c6cf722602a7586342f22c3417bec07 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 18:44:17 +0200 Subject: [PATCH 07/52] Added empty Helm chart for api --- helm/api/.helmignore | 23 +++++++++++++++++++++++ helm/api/Chart.yaml | 24 ++++++++++++++++++++++++ helm/api/templates/NOTES.txt | 0 helm/api/values-dev.yaml | 0 helm/api/values.yaml | 0 5 files changed, 47 insertions(+) create mode 100644 helm/api/.helmignore create mode 100644 helm/api/Chart.yaml create mode 100644 helm/api/templates/NOTES.txt create mode 100644 helm/api/values-dev.yaml create mode 100644 helm/api/values.yaml diff --git a/helm/api/.helmignore b/helm/api/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/api/.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/api/Chart.yaml b/helm/api/Chart.yaml new file mode 100644 index 0000000..cc238c0 --- /dev/null +++ b/helm/api/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: api +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/helm/api/templates/NOTES.txt b/helm/api/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/helm/api/values-dev.yaml b/helm/api/values-dev.yaml new file mode 100644 index 0000000..e69de29 diff --git a/helm/api/values.yaml b/helm/api/values.yaml new file mode 100644 index 0000000..e69de29 From fb67dcbef002712d5e5b954177aa68d3c9ad4df8 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 18:44:30 +0200 Subject: [PATCH 08/52] Basic local environment setup --- scripts/localenv/Makefile | 61 +++++++++++++++++++++ scripts/localenv/kind-multinode-config.yaml | 6 ++ 2 files changed, 67 insertions(+) create mode 100644 scripts/localenv/Makefile create mode 100644 scripts/localenv/kind-multinode-config.yaml diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile new file mode 100644 index 0000000..cb87166 --- /dev/null +++ b/scripts/localenv/Makefile @@ -0,0 +1,61 @@ +ROOT_DIRECTORY = ../.. +CLUSTER_NAME = indiegamestream + +FRONTEND_NAME=frontend +FRONTEND_DIRECTORY=frontend +FRONTEND_DOCKERFILE=frontend/Dockerfile + +API_NAME=api +API_DIRECTORY=api +API_DOCKERFILE=api/Dockerfile + +HELM_DIRECTORY=helm +HELM_FRONTEND=frontend +HELM_API=api + +.PHONY: * + +all: build_images load_images create_cluster install + +multi_node: build_images load_images create_multinode_cluster install + +teardown: teardown_cluster delete_images + +build_images: build_frontend build_api + +load_images: load_frontend load_api + +delete_images: delete_frontend delete_api + +install: install_frontend install_api + +uninstall: uninstall_frontend uninstall_api + +create_cluster: + kind create cluster --name $(CLUSTER_NAME) + +create_multinode_cluster: + kind create cluster --name $(CLUSTER_NAME) --config kind-multinode-config.yaml + +teardown_cluster: + kind delete cluster --name $(CLUSTER_NAME) + +build_frontend: + docker build ${ROOT_DIRECTORY}/$(FRONTEND_DIRECTORY) -t $(FRONTEND_NAME) -f ${ROOT_DIRECTORY}/$(FRONTEND_DOCKERFILE) + +build_api: + docker build ${ROOT_DIRECTORY}/$(API_DIRECTORY) -t $(API_NAME) -f ${ROOT_DIRECTORY}/$(FRONTEND_DOCKERFILE) + +load_frontend: + kind load docker-image $(FRONTEND_NAME) + +load_api: + kind load docker_image $(API_NAME) + +install_frontend: + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ + $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) + +install_api: + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ + $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) \ No newline at end of file diff --git a/scripts/localenv/kind-multinode-config.yaml b/scripts/localenv/kind-multinode-config.yaml new file mode 100644 index 0000000..b67d673 --- /dev/null +++ b/scripts/localenv/kind-multinode-config.yaml @@ -0,0 +1,6 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane +- role: worker +- role: worker \ No newline at end of file From 3d89936e5efb612521e992f9ab74e0bdf32f9b1a Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 27 May 2024 18:54:36 +0200 Subject: [PATCH 09/52] Added MetalLB and general improvements to Makefile --- scripts/localenv/Makefile | 29 ++++++++++++++----- scripts/localenv/README.md | 14 +++++++++ scripts/localenv/add_metallb.sh | 28 ++++++++++++++++++ scripts/localenv/metallb-config-template.yaml | 14 +++++++++ 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 scripts/localenv/README.md create mode 100755 scripts/localenv/add_metallb.sh create mode 100644 scripts/localenv/metallb-config-template.yaml diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index cb87166..5f5daaa 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -15,9 +15,9 @@ HELM_API=api .PHONY: * -all: build_images load_images create_cluster install +all: build_images create_cluster load_images add_metallb install -multi_node: build_images load_images create_multinode_cluster install +multi_node: build_images create_multinode_cluster load_images add_metallb install teardown: teardown_cluster delete_images @@ -37,20 +37,23 @@ create_cluster: create_multinode_cluster: kind create cluster --name $(CLUSTER_NAME) --config kind-multinode-config.yaml +add_metallb: + ./add_metallb.sh + teardown_cluster: kind delete cluster --name $(CLUSTER_NAME) build_frontend: - docker build ${ROOT_DIRECTORY}/$(FRONTEND_DIRECTORY) -t $(FRONTEND_NAME) -f ${ROOT_DIRECTORY}/$(FRONTEND_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_NAME) -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) build_api: - docker build ${ROOT_DIRECTORY}/$(API_DIRECTORY) -t $(API_NAME) -f ${ROOT_DIRECTORY}/$(FRONTEND_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_NAME) -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) load_frontend: - kind load docker-image $(FRONTEND_NAME) + kind load docker-image $(FRONTEND_NAME) --name $(CLUSTER_NAME) load_api: - kind load docker_image $(API_NAME) + kind load docker-image $(API_NAME) --name $(CLUSTER_NAME) install_frontend: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ @@ -58,4 +61,16 @@ install_frontend: install_api: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ - $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) \ No newline at end of file + $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) + +uninstall_frontend: + helm uninstall $(FRONTEND_NAME) + +uninstall_api: + helm uninstall $(API_NAME) + +delete_frontend: + docker rmi $(FRONTEND_NAME) + +delete_api: + docker rmi $(API_NAME) \ No newline at end of file diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md new file mode 100644 index 0000000..09ab51b --- /dev/null +++ b/scripts/localenv/README.md @@ -0,0 +1,14 @@ +# Install + +Install helm and kind + +# How to run +## Single-node cluster +```bash +make +``` + +## Multi-node cluster +```bash +make multi-node +``` \ No newline at end of file diff --git a/scripts/localenv/add_metallb.sh b/scripts/localenv/add_metallb.sh new file mode 100755 index 0000000..4f347d7 --- /dev/null +++ b/scripts/localenv/add_metallb.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.4/config/manifests/metallb-native.yaml +{ grep -q "controller"; kill $!; } < <(kubectl get pod -w -n metallb-system) +kubectl wait --namespace metallb-system \ + --for=condition=ready pod \ + --selector=app=metallb \ + --timeout=90s +lb_subnet=$(docker network inspect kind --format '{{json .}}' | jq -r '.IPAM.Config[0].Subnet') + +# Extract the base IP and calculate the range start and end +# This example assumes the subnet is in CIDR notation e.g., 172.20.0.0/16 +IFS='/' read -r base_ip cidr <<< "$lb_subnet" +IFS='.' read -r ip1 ip2 ip3 ip4 <<< "$base_ip" + +# Example calculation: Use the .10.1 for start and .10.50 for the end of the range +# This is a simplistic calculation that might not suit all subnets or requirements +range_start="${ip1}.${ip2}.10.1" +range_end="${ip1}.${ip2}.10.50" + +# Combine them into the range string expected by MetalLB +RANGE="${range_start}-${range_end}" +export RANGE + +# Prepare your YAML file with the ${RANGE} placeholder and use envsubst, apply the YAML file +envsubst < ./metallb-config-template.yaml | kubectl apply -f - diff --git a/scripts/localenv/metallb-config-template.yaml b/scripts/localenv/metallb-config-template.yaml new file mode 100644 index 0000000..97dd9b8 --- /dev/null +++ b/scripts/localenv/metallb-config-template.yaml @@ -0,0 +1,14 @@ +apiVersion: metallb.io/v1beta1 +kind: IPAddressPool +metadata: + name: example + namespace: metallb-system +spec: + addresses: + - ${RANGE} +--- +apiVersion: metallb.io/v1beta1 +kind: L2Advertisement +metadata: + name: empty + namespace: metallb-system \ No newline at end of file From 00d3d707343f4368820bd92ad890cfee02438ac0 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Tue, 28 May 2024 14:24:25 +0200 Subject: [PATCH 10/52] Added README --- scripts/localenv/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index 09ab51b..be7aeea 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -1,5 +1,4 @@ # Install - Install helm and kind # How to run From c368b03d27b413f0d8dae1285e382631ee05bda2 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 15:55:43 +0200 Subject: [PATCH 11/52] Removed pacman folders --- helm/pacman/.gitkeep | 0 scripts/pacman/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 helm/pacman/.gitkeep delete mode 100644 scripts/pacman/.gitkeep diff --git a/helm/pacman/.gitkeep b/helm/pacman/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/pacman/.gitkeep b/scripts/pacman/.gitkeep deleted file mode 100644 index e69de29..0000000 From 500ef9e02d99dc99b9916ae3e7e857b5bcd22ab7 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 16:30:05 +0200 Subject: [PATCH 12/52] Improvements to Makefile --- scripts/localenv/Makefile | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 5f5daaa..56f1f0a 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -1,11 +1,22 @@ +define HEADER + ___ _ _ ____ ____ _ +|_ _|_ __ __| (_) ___ / ___| __ _ _ __ ___ ___/ ___|| |_ _ __ ___ __ _ _ __ ___ + | || '_ \ / _` | |/ _ \ | _ / _` | '_ ` _ \ / _ \___ \| __| '__/ _ \/ _` | '_ ` _ \ + | || | | | (_| | | __/ |_| | (_| | | | | | | __/___) | |_| | | __/ (_| | | | | | | +|___|_| |_|\__,_|_|\___|\____|\__,_|_| |_| |_|\___|____/ \__|_| \___|\__,_|_| |_| |_| +endef + ROOT_DIRECTORY = ../.. CLUSTER_NAME = indiegamestream +IMAGE_NAMESPACE = indiegamestream FRONTEND_NAME=frontend +FRONTEND_IMAGE=$(IMAGE_NAMESPACE)/$(FRONTEND_NAME) FRONTEND_DIRECTORY=frontend FRONTEND_DOCKERFILE=frontend/Dockerfile API_NAME=api +API_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME) API_DIRECTORY=api API_DOCKERFILE=api/Dockerfile @@ -15,11 +26,11 @@ HELM_API=api .PHONY: * -all: build_images create_cluster load_images add_metallb install - -multi_node: build_images create_multinode_cluster load_images add_metallb install +all: build_images create_cluster load_images add_metallb install output + +multi_node: build_images create_multinode_cluster load_images add_metallb install output -teardown: teardown_cluster delete_images +destroy: teardown_cluster delete_images build_images: build_frontend build_api @@ -44,33 +55,43 @@ teardown_cluster: kind delete cluster --name $(CLUSTER_NAME) build_frontend: - docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_NAME) -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_IMAGE) -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) build_api: - docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_NAME) -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_IMAGE) -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) load_frontend: - kind load docker-image $(FRONTEND_NAME) --name $(CLUSTER_NAME) + kind load docker-image $(FRONTEND_IMAGE) --name $(CLUSTER_NAME) load_api: - kind load docker-image $(API_NAME) --name $(CLUSTER_NAME) + kind load docker-image $(API_IMAGE) --name $(CLUSTER_NAME) install_frontend: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_api: - helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ - $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ + $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) uninstall_frontend: - helm uninstall $(FRONTEND_NAME) + helm uninstall $(FRONTEND_NAME) --wait uninstall_api: - helm uninstall $(API_NAME) + helm uninstall $(API_NAME) --wait delete_frontend: - docker rmi $(FRONTEND_NAME) + docker rmi $(FRONTEND_IMAGE) delete_api: - docker rmi $(API_NAME) \ No newline at end of file + docker rmi $(API_IMAGE) + +redeploy_frontend: uninstall_frontend build_frontend load_frontend install_frontend + +redeploy_api: uninstall_api build_api load_api install_api + +output: + $(info $(HEADER)) + @echo "Type 'make destroy' to delete the cluster and locally build images" + @echo "Type 'make teardown_cluster' to only delete the cluster" + @echo "Type 'make redeploy_api/frontend/operator' to rebuild and redeploy the given component to the cluster" \ No newline at end of file From dffc224f8f8b3b1d3a6627c4923bb05b14528920 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 18:27:47 +0200 Subject: [PATCH 13/52] Added API Helm chart --- helm/api/Chart.yaml | 5 +++++ helm/api/templates/api-deployment.yaml | 26 ++++++++++++++++++++++++++ helm/api/templates/api-namespace.yaml | 6 ++++++ helm/api/templates/api-service.yaml | 15 +++++++++++++++ helm/api/values-dev.yaml | 12 ++++++++++++ helm/api/values.yaml | 17 +++++++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 helm/api/templates/api-deployment.yaml create mode 100644 helm/api/templates/api-namespace.yaml create mode 100644 helm/api/templates/api-service.yaml diff --git a/helm/api/Chart.yaml b/helm/api/Chart.yaml index cc238c0..a32237b 100644 --- a/helm/api/Chart.yaml +++ b/helm/api/Chart.yaml @@ -22,3 +22,8 @@ version: 0.1.0 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "1.16.0" + +dependencies: +- name: mysql + version: "8.4.0" + repository: "oci://registry-1.docker.io/bitnamicharts" \ No newline at end of file diff --git a/helm/api/templates/api-deployment.yaml b/helm/api/templates/api-deployment.yaml new file mode 100644 index 0000000..fb88bb6 --- /dev/null +++ b/helm/api/templates/api-deployment.yaml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.appName }} + namespace: {{ .Values.appName }} + labels: + app: {{ .Values.appName }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + app: {{ .Values.appName }} + template: + metadata: + labels: + app: {{ .Values.appName }} + spec: + containers: + - name: {{ .Values.appName }} + image: {{ .Values.image.name }}:{{ .Values.image.label }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.port }} + env: + - name: GIN_MODE + value: {{ .Values.ginMode }} \ No newline at end of file diff --git a/helm/api/templates/api-namespace.yaml b/helm/api/templates/api-namespace.yaml new file mode 100644 index 0000000..b073657 --- /dev/null +++ b/helm/api/templates/api-namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.appName }} + labels: + name: {{ .Values.appName }} diff --git a/helm/api/templates/api-service.yaml b/helm/api/templates/api-service.yaml new file mode 100644 index 0000000..cfd960d --- /dev/null +++ b/helm/api/templates/api-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.appName }} + namespace: {{ .Values.appName }} + labels: + app: {{ .Values.appName }} +spec: + type: LoadBalancer + selector: + app: {{ .Values.appName }} + ports: + - protocol: TCP + port: {{ .Values.port }} + targetPort: {{ .Values.port }} \ No newline at end of file diff --git a/helm/api/values-dev.yaml b/helm/api/values-dev.yaml index e69de29..ba280ff 100644 --- a/helm/api/values-dev.yaml +++ b/helm/api/values-dev.yaml @@ -0,0 +1,12 @@ +image: + name: indiegamestream/api + label: latest + pullPolicy: Never + +ginMode: debug + +mysql: + image: + debug: true + auth: + rootPassword: root \ No newline at end of file diff --git a/helm/api/values.yaml b/helm/api/values.yaml index e69de29..a03fd12 100644 --- a/helm/api/values.yaml +++ b/helm/api/values.yaml @@ -0,0 +1,17 @@ +appName: api +replicas: 1 +port: 8080 + +ginMode: release + +image: + name: ghcr.io/austriandatalab/indiegamestream/api + label: latest # Change to proper version tag + pullPolicy: IfNotPresent + +mysql: + auth: + database: api + existingSecret: mysql-secret # Find proper way of handling authentication in production + primary: + containerPorts: 3306 \ No newline at end of file From 51cea8b58fdb2fdab11572ec1b245b80806c4b54 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 18:31:41 +0200 Subject: [PATCH 14/52] Changed frontend image name --- helm/frontend/values-dev.yaml | 2 +- helm/frontend/values.yaml | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/helm/frontend/values-dev.yaml b/helm/frontend/values-dev.yaml index fc49b3c..098908a 100644 --- a/helm/frontend/values-dev.yaml +++ b/helm/frontend/values-dev.yaml @@ -1,4 +1,4 @@ image: - name: frontend + name: indiegamestream/frontend label: latest pullPolicy: Never \ No newline at end of file diff --git a/helm/frontend/values.yaml b/helm/frontend/values.yaml index 830e5bd..a9d7eaf 100644 --- a/helm/frontend/values.yaml +++ b/helm/frontend/values.yaml @@ -1,10 +1,8 @@ appName: frontend - replicas: 1 +port: 80 image: name: ghcr.io/austriandatalab/indiegamestream/frontend - label: latest - pullPolicy: IfNotPresent - -port: 80 \ No newline at end of file + label: latest # Change to proper version tag + pullPolicy: IfNotPresent \ No newline at end of file From f0a3b340ba511b78cc321af5fa59290165ffab01 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 19:06:02 +0200 Subject: [PATCH 15/52] Added empty operator helm chart --- helm/operator/.helmignore | 23 +++++++++++++++++++++++ helm/operator/Chart.yaml | 24 ++++++++++++++++++++++++ helm/operator/values.yaml | 0 3 files changed, 47 insertions(+) create mode 100644 helm/operator/.helmignore create mode 100644 helm/operator/Chart.yaml create mode 100644 helm/operator/values.yaml diff --git a/helm/operator/.helmignore b/helm/operator/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/operator/.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/operator/Chart.yaml b/helm/operator/Chart.yaml new file mode 100644 index 0000000..b9c7cc6 --- /dev/null +++ b/helm/operator/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: operator +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/helm/operator/values.yaml b/helm/operator/values.yaml new file mode 100644 index 0000000..e69de29 From 4507c6748110a51f433e59da1ea38506338e7cdc Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 19:07:22 +0200 Subject: [PATCH 16/52] Moved MySQL dependency to own chart --- helm/api/Chart.yaml | 5 ----- helm/api/values-dev.yaml | 10 ++------- helm/api/values.yaml | 7 ------- helm/mysql/values-dev.yaml | 5 +++++ helm/mysql/values.yaml | 6 ++++++ scripts/localenv/Makefile | 42 +++++++++++++++++++++++++++++++++----- 6 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 helm/mysql/values-dev.yaml create mode 100644 helm/mysql/values.yaml diff --git a/helm/api/Chart.yaml b/helm/api/Chart.yaml index a32237b..cc238c0 100644 --- a/helm/api/Chart.yaml +++ b/helm/api/Chart.yaml @@ -22,8 +22,3 @@ version: 0.1.0 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "1.16.0" - -dependencies: -- name: mysql - version: "8.4.0" - repository: "oci://registry-1.docker.io/bitnamicharts" \ No newline at end of file diff --git a/helm/api/values-dev.yaml b/helm/api/values-dev.yaml index ba280ff..41cebec 100644 --- a/helm/api/values-dev.yaml +++ b/helm/api/values-dev.yaml @@ -1,12 +1,6 @@ +ginMode: debug + image: name: indiegamestream/api label: latest pullPolicy: Never - -ginMode: debug - -mysql: - image: - debug: true - auth: - rootPassword: root \ No newline at end of file diff --git a/helm/api/values.yaml b/helm/api/values.yaml index a03fd12..64c6524 100644 --- a/helm/api/values.yaml +++ b/helm/api/values.yaml @@ -8,10 +8,3 @@ image: name: ghcr.io/austriandatalab/indiegamestream/api label: latest # Change to proper version tag pullPolicy: IfNotPresent - -mysql: - auth: - database: api - existingSecret: mysql-secret # Find proper way of handling authentication in production - primary: - containerPorts: 3306 \ No newline at end of file diff --git a/helm/mysql/values-dev.yaml b/helm/mysql/values-dev.yaml new file mode 100644 index 0000000..5755138 --- /dev/null +++ b/helm/mysql/values-dev.yaml @@ -0,0 +1,5 @@ +mysql: + image: + debug: true + auth: + rootPassword: root diff --git a/helm/mysql/values.yaml b/helm/mysql/values.yaml new file mode 100644 index 0000000..b4763ac --- /dev/null +++ b/helm/mysql/values.yaml @@ -0,0 +1,6 @@ +mysql: + auth: + database: api + existingSecret: mysql-secret # Find proper way of handling authentication in production + primary: + containerPorts: 3306 \ No newline at end of file diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 56f1f0a..a9c43f4 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -20,9 +20,16 @@ API_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME) API_DIRECTORY=api API_DOCKERFILE=api/Dockerfile +OPERATOR_NAME=operator +OPERATOR_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME) +OPERATOR_DIRECTORY=operator +OPERATOR_DOCKERFILE=operator/Dockerfile + HELM_DIRECTORY=helm HELM_FRONTEND=frontend HELM_API=api +HELM_OPERATOR=operator +HELM_MYSQL=mysql .PHONY: * @@ -32,15 +39,15 @@ multi_node: build_images create_multinode_cluster load_images add_metallb instal destroy: teardown_cluster delete_images -build_images: build_frontend build_api +build_images: build_frontend build_api build_operator -load_images: load_frontend load_api +load_images: load_frontend load_api load_operator -delete_images: delete_frontend delete_api +delete_images: delete_frontend delete_api delete_operator -install: install_frontend install_api +install: install_frontend install_mysql install_api install_operator -uninstall: uninstall_frontend uninstall_api +uninstall: uninstall_frontend uninstall_api uninstall_mysql uninstall_operator create_cluster: kind create cluster --name $(CLUSTER_NAME) @@ -60,36 +67,61 @@ build_frontend: build_api: docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_IMAGE) -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) +build_operator: + docker build $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) -t $(OPERATOR_IMAGE) -f $(ROOT_DIRECTORY)/$(OPERATOR_DOCKERFILE) + load_frontend: kind load docker-image $(FRONTEND_IMAGE) --name $(CLUSTER_NAME) load_api: kind load docker-image $(API_IMAGE) --name $(CLUSTER_NAME) +load_operator: + kind load docker-image $(OPERATOR_IMAGE) --name $(CLUSTER_NAME) + install_frontend: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) +install_mysql: + helm install mysql oci://registry-1.docker.io/bitnamicharts/mysql --version "11.1.0" --wait \ + --create-namespace --namespace=api + install_api: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) +install_operator: + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR)/values-dev.yaml \ + $(OPERATOR_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR) + uninstall_frontend: helm uninstall $(FRONTEND_NAME) --wait uninstall_api: helm uninstall $(API_NAME) --wait +uninstall_operator: + helm uninstall $(OPERATOR_NAME) --wait + +uninstall_mysql: + helm uninstall mysql + delete_frontend: docker rmi $(FRONTEND_IMAGE) delete_api: docker rmi $(API_IMAGE) +delete_operator: + docker rmi $(OPERATOR_IMAGE) + redeploy_frontend: uninstall_frontend build_frontend load_frontend install_frontend redeploy_api: uninstall_api build_api load_api install_api +redeploy_operator: uninstall_operator build_operator load_operator install_operator + output: $(info $(HEADER)) @echo "Type 'make destroy' to delete the cluster and locally build images" From de62cb60c423ae84c8eb21b3cba615e4fe6194dc Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 19:07:40 +0200 Subject: [PATCH 17/52] Ignore helm /charts directories --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f304278..9532c1b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ api/.idea/ api/internal/ .idea/ + +helm/*/charts \ No newline at end of file From b9d030c8556937076ad374ee3e1833eabcf42524 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 19:15:13 +0200 Subject: [PATCH 18/52] Improvements to MySQL deployment --- helm/mysql/values-dev.yaml | 1 + scripts/localenv/Makefile | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/helm/mysql/values-dev.yaml b/helm/mysql/values-dev.yaml index 5755138..53c1c6f 100644 --- a/helm/mysql/values-dev.yaml +++ b/helm/mysql/values-dev.yaml @@ -3,3 +3,4 @@ mysql: debug: true auth: rootPassword: root + existingSecret: "" diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index a9c43f4..6e5f49a 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -25,6 +25,8 @@ OPERATOR_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME) OPERATOR_DIRECTORY=operator OPERATOR_DOCKERFILE=operator/Dockerfile +MYSQL_NAME=mysql + HELM_DIRECTORY=helm HELM_FRONTEND=frontend HELM_API=api @@ -84,8 +86,9 @@ install_frontend: $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: - helm install mysql oci://registry-1.docker.io/bitnamicharts/mysql --version "11.1.0" --wait \ - --create-namespace --namespace=api + helm install $(MYSQL_NAME) oci://registry-1.docker.io/bitnamicharts/mysql --version "11.1.0" --wait \ + --create-namespace --namespace=mysql -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values.yaml \ + -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values-dev.yaml install_api: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ @@ -105,16 +108,16 @@ uninstall_operator: helm uninstall $(OPERATOR_NAME) --wait uninstall_mysql: - helm uninstall mysql + helm uninstall $(MYSQL_NAME) --wait delete_frontend: - docker rmi $(FRONTEND_IMAGE) + - docker rmi $(FRONTEND_IMAGE) delete_api: - docker rmi $(API_IMAGE) + - docker rmi $(API_IMAGE) delete_operator: - docker rmi $(OPERATOR_IMAGE) + - docker rmi $(OPERATOR_IMAGE) redeploy_frontend: uninstall_frontend build_frontend load_frontend install_frontend From f32f9b372b13696d95bccfebe156acc0b2760b5c Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Wed, 29 May 2024 19:46:41 +0200 Subject: [PATCH 19/52] Added dev values file for operator --- helm/operator/values-dev.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 helm/operator/values-dev.yaml diff --git a/helm/operator/values-dev.yaml b/helm/operator/values-dev.yaml new file mode 100644 index 0000000..e69de29 From 28909560631c84c07616c41915c0084a0f9da765 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Thu, 30 May 2024 11:08:01 +0200 Subject: [PATCH 20/52] Added environment variables to api --- helm/api/values.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/helm/api/values.yaml b/helm/api/values.yaml index 64c6524..8caf976 100644 --- a/helm/api/values.yaml +++ b/helm/api/values.yaml @@ -2,9 +2,15 @@ appName: api replicas: 1 port: 8080 -ginMode: release - image: name: ghcr.io/austriandatalab/indiegamestream/api label: latest # Change to proper version tag pullPolicy: IfNotPresent + +env: + ginMode: release + mysqlDatabase: api + mysqlRootUser: root + mysqlRootPassword: root + mysqlHost: mysql.mysql.svc.cluster.local + mysqlPort: 3306 \ No newline at end of file From 0368ee0d40d21485a97f0e3242c74efc11c3b1d9 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Thu, 30 May 2024 11:29:38 +0200 Subject: [PATCH 21/52] Added MySQL using Helm chart --- helm/api/templates/api-deployment.yaml | 14 +++++++++++++- helm/mysql/values-dev.yaml | 10 ++++------ helm/mysql/values.yaml | 13 +++++++------ scripts/localenv/Makefile | 9 ++++++--- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/helm/api/templates/api-deployment.yaml b/helm/api/templates/api-deployment.yaml index fb88bb6..2e12126 100644 --- a/helm/api/templates/api-deployment.yaml +++ b/helm/api/templates/api-deployment.yaml @@ -22,5 +22,17 @@ spec: ports: - containerPort: {{ .Values.port }} env: + - name: PORT + value: {{ .Values.port | quote }} - name: GIN_MODE - value: {{ .Values.ginMode }} \ No newline at end of file + value: {{ .Values.env.ginMode | quote }} + - name: MYSQL_DATABASE + value: {{ .Values.env.mysqlDatabase | quote }} + - name: MYSQL_ROOT_USER + value: {{ .Values.env.mysqlRootUser | quote }} + - name: MYSQL_ROOT_PASSWORD + value: {{ .Values.env.mysqlRootPassword | quote }} + - name: MYSQL_HOST + value: {{ .Values.env.mysqlHost | quote }} + - name: MYSQL_PORT + value: {{ .Values.env.mysqlPort | quote }} \ No newline at end of file diff --git a/helm/mysql/values-dev.yaml b/helm/mysql/values-dev.yaml index 53c1c6f..6d8ffb1 100644 --- a/helm/mysql/values-dev.yaml +++ b/helm/mysql/values-dev.yaml @@ -1,6 +1,4 @@ -mysql: - image: - debug: true - auth: - rootPassword: root - existingSecret: "" +image: + debug: true +auth: + rootPassword: root diff --git a/helm/mysql/values.yaml b/helm/mysql/values.yaml index b4763ac..961073f 100644 --- a/helm/mysql/values.yaml +++ b/helm/mysql/values.yaml @@ -1,6 +1,7 @@ -mysql: - auth: - database: api - existingSecret: mysql-secret # Find proper way of handling authentication in production - primary: - containerPorts: 3306 \ No newline at end of file +auth: + database: api +primary: + startupProbe: + enabled: false + containerPorts: + mysql: 3306 \ No newline at end of file diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 6e5f49a..a27f7c2 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -82,7 +82,8 @@ load_operator: kind load docker-image $(OPERATOR_IMAGE) --name $(CLUSTER_NAME) install_frontend: - helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values.yaml \ + -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: @@ -91,11 +92,13 @@ install_mysql: -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values-dev.yaml install_api: - helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values.yaml \ + -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) install_operator: - helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR)/values-dev.yaml \ + helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR)/values.yaml \ + -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR)/values-dev.yaml \ $(OPERATOR_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR) uninstall_frontend: From 8623752cdddd0007c453b496124d4593836706e6 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 12:28:30 +0200 Subject: [PATCH 22/52] Added Oracle MySQL operator and InnoDB cluster --- helm/api/values-dev.yaml | 6 ++++-- helm/api/values.yaml | 1 - helm/mysql/values-dev.yaml | 12 ++++++++---- helm/mysql/values.yaml | 7 ------- scripts/localenv/Makefile | 12 +++++++++--- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/helm/api/values-dev.yaml b/helm/api/values-dev.yaml index 41cebec..f145bcf 100644 --- a/helm/api/values-dev.yaml +++ b/helm/api/values-dev.yaml @@ -1,6 +1,8 @@ -ginMode: debug - image: name: indiegamestream/api label: latest pullPolicy: Never + +env: + ginMode: debug + mysqlRootPassword: root \ No newline at end of file diff --git a/helm/api/values.yaml b/helm/api/values.yaml index 8caf976..929f7f1 100644 --- a/helm/api/values.yaml +++ b/helm/api/values.yaml @@ -11,6 +11,5 @@ env: ginMode: release mysqlDatabase: api mysqlRootUser: root - mysqlRootPassword: root mysqlHost: mysql.mysql.svc.cluster.local mysqlPort: 3306 \ No newline at end of file diff --git a/helm/mysql/values-dev.yaml b/helm/mysql/values-dev.yaml index 6d8ffb1..acd25b2 100644 --- a/helm/mysql/values-dev.yaml +++ b/helm/mysql/values-dev.yaml @@ -1,4 +1,8 @@ -image: - debug: true -auth: - rootPassword: root +credentials: + root: + password: root + +serverInstances: 1 + +tls: + useSelfSigned: true \ No newline at end of file diff --git a/helm/mysql/values.yaml b/helm/mysql/values.yaml index 961073f..e69de29 100644 --- a/helm/mysql/values.yaml +++ b/helm/mysql/values.yaml @@ -1,7 +0,0 @@ -auth: - database: api -primary: - startupProbe: - enabled: false - containerPorts: - mysql: 3306 \ No newline at end of file diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index a27f7c2..3db004e 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -87,8 +87,13 @@ install_frontend: $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: - helm install $(MYSQL_NAME) oci://registry-1.docker.io/bitnamicharts/mysql --version "11.1.0" --wait \ - --create-namespace --namespace=mysql -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values.yaml \ + helm repo add mysql-operator https://mysql.github.io/mysql-operator/ + helm repo update + helm install $(MYSQL_NAME)-operator mysql-operator/mysql-operator --version "2.1.3" --wait \ + --create-namespace --namespace=$(MYSQL_NAME)-operator + helm install $(MYSQL_NAME) mysql-operator/mysql-innodbcluster --version "2.1.3" --wait \ + --create-namespace --namespace=$(MYSQL_NAME) \ + -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values-dev.yaml install_api: @@ -111,7 +116,8 @@ uninstall_operator: helm uninstall $(OPERATOR_NAME) --wait uninstall_mysql: - helm uninstall $(MYSQL_NAME) --wait + helm uninstall $(MYSQL_NAME) -n $(MYSQL_NAME)-cluster --wait + helm uninstall $(MYSQL_NAME)-operator -n $(MYSQL_NAME)-operator --wait delete_frontend: - docker rmi $(FRONTEND_IMAGE) From 48413b19cbd22ab19fb0cf8dae819ebc6636a639 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 15:10:48 +0200 Subject: [PATCH 23/52] Added STUNner to local deployment --- helm/stunner/.helmignore | 23 ++++++++++++++ helm/stunner/Chart.lock | 6 ++++ helm/stunner/Chart.yaml | 29 +++++++++++++++++ helm/stunner/templates/gateway_config.yml | 38 +++++++++++++++++++++++ helm/stunner/{.gitkeep => values.yaml} | 0 scripts/localenv/Makefile | 20 ++++++++---- scripts/localenv/README.md | 8 +++-- 7 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 helm/stunner/.helmignore create mode 100644 helm/stunner/Chart.lock create mode 100644 helm/stunner/Chart.yaml create mode 100644 helm/stunner/templates/gateway_config.yml rename helm/stunner/{.gitkeep => values.yaml} (100%) diff --git a/helm/stunner/.helmignore b/helm/stunner/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/stunner/.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/stunner/Chart.lock b/helm/stunner/Chart.lock new file mode 100644 index 0000000..1299847 --- /dev/null +++ b/helm/stunner/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: stunner-gateway-operator + repository: https://l7mp.io/stunner + version: 0.19.0 +digest: sha256:cf52ea4f76441055d528344c69288940ae54166fcf6d0e22143c8820e693b5a3 +generated: "2024-06-02T15:46:17.23111941+02:00" diff --git a/helm/stunner/Chart.yaml b/helm/stunner/Chart.yaml new file mode 100644 index 0000000..da026e0 --- /dev/null +++ b/helm/stunner/Chart.yaml @@ -0,0 +1,29 @@ +apiVersion: v2 +name: stunner +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" + +dependencies: +- name: stunner-gateway-operator + version: 0.19.0 + repository: "https://l7mp.io/stunner" \ No newline at end of file diff --git a/helm/stunner/templates/gateway_config.yml b/helm/stunner/templates/gateway_config.yml new file mode 100644 index 0000000..7233f6c --- /dev/null +++ b/helm/stunner/templates/gateway_config.yml @@ -0,0 +1,38 @@ +apiVersion: gateway.networking.k8s.io/v1 +kind: GatewayClass +metadata: + name: stunner-gatewayclass +spec: + controllerName: "stunner.l7mp.io/gateway-operator" + parametersRef: + group: "stunner.l7mp.io" + kind: GatewayConfig + name: stunner-gatewayconfig + namespace: stunner + description: "STUNner is a WebRTC ingress gateway for Kubernetes" +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: Gateway +metadata: + name: udp-gateway + namespace: stunner +spec: + gatewayClassName: stunner-gatewayclass + listeners: + - name: udp-listener + port: 3478 + allowedRoutes: + namespaces: + from: All + protocol: UDP +--- +apiVersion: stunner.l7mp.io/v1 +kind: GatewayConfig +metadata: + name: stunner-gatewayconfig + namespace: stunner +spec: + realm: stunner.l7mp.io + authType: static + userName: "user-1" + password: "pass-1" \ No newline at end of file diff --git a/helm/stunner/.gitkeep b/helm/stunner/values.yaml similarity index 100% rename from helm/stunner/.gitkeep rename to helm/stunner/values.yaml diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 3db004e..56f9c6a 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -26,12 +26,14 @@ OPERATOR_DIRECTORY=operator OPERATOR_DOCKERFILE=operator/Dockerfile MYSQL_NAME=mysql +STUNNER_NAME=stunner HELM_DIRECTORY=helm HELM_FRONTEND=frontend HELM_API=api HELM_OPERATOR=operator HELM_MYSQL=mysql +HELM_STUNNER=stunner .PHONY: * @@ -47,9 +49,9 @@ load_images: load_frontend load_api load_operator delete_images: delete_frontend delete_api delete_operator -install: install_frontend install_mysql install_api install_operator +install: install_frontend install_mysql install_api install_stunner install_operator -uninstall: uninstall_frontend uninstall_api uninstall_mysql uninstall_operator +uninstall: uninstall_frontend uninstall_api uninstall_mysql uninstall_stunner uninstall_operator create_cluster: kind create cluster --name $(CLUSTER_NAME) @@ -102,9 +104,12 @@ install_api: $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) install_operator: - helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR)/values.yaml \ - -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR)/values-dev.yaml \ - $(OPERATOR_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_OPERATOR) + $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) deploy IMG=$(OPERATOR_IMAGE) + +install_stunner: + helm dependency build $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_STUNNER) --skip-refresh + helm install $(STUNNER_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_STUNNER) \ + --create-namespace --namespace=$(STUNNER_NAME) uninstall_frontend: helm uninstall $(FRONTEND_NAME) --wait @@ -113,12 +118,15 @@ uninstall_api: helm uninstall $(API_NAME) --wait uninstall_operator: - helm uninstall $(OPERATOR_NAME) --wait + $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) undeploy uninstall_mysql: helm uninstall $(MYSQL_NAME) -n $(MYSQL_NAME)-cluster --wait helm uninstall $(MYSQL_NAME)-operator -n $(MYSQL_NAME)-operator --wait +uninstall_stunner: + helm uninstall $(STUNNER_NAME) --namespace=$(STUNNER_NAME) + delete_frontend: - docker rmi $(FRONTEND_IMAGE) diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index be7aeea..b5e3352 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -1,5 +1,9 @@ -# Install -Install helm and kind +# Prerequisites +- docker +- kubectl +- kind +- helm v3.15.0+ +- go v1.20.0+ # How to run ## Single-node cluster From 4b465a0adca34877ae752fd64e494c1a03c72c97 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 15:51:32 +0200 Subject: [PATCH 24/52] Small bug fix --- scripts/localenv/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 56f9c6a..6509d33 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -21,7 +21,7 @@ API_DIRECTORY=api API_DOCKERFILE=api/Dockerfile OPERATOR_NAME=operator -OPERATOR_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME) +OPERATOR_IMAGE=$(IMAGE_NAMESPACE)/$(OPERATOR_NAME) OPERATOR_DIRECTORY=operator OPERATOR_DOCKERFILE=operator/Dockerfile From d903fef61d08c0049abe8f335fca50b0bf41211a Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 16:29:49 +0200 Subject: [PATCH 25/52] Add latest tag to all image builds --- scripts/localenv/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 6509d33..1a35560 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -66,13 +66,13 @@ teardown_cluster: kind delete cluster --name $(CLUSTER_NAME) build_frontend: - docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_IMAGE) -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_IMAGE):latest -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) build_api: - docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_IMAGE) -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_IMAGE):latest -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) build_operator: - docker build $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) -t $(OPERATOR_IMAGE) -f $(ROOT_DIRECTORY)/$(OPERATOR_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) -t $(OPERATOR_IMAGE):latest -f $(ROOT_DIRECTORY)/$(OPERATOR_DOCKERFILE) load_frontend: kind load docker-image $(FRONTEND_IMAGE) --name $(CLUSTER_NAME) @@ -104,7 +104,7 @@ install_api: $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) install_operator: - $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) deploy IMG=$(OPERATOR_IMAGE) + $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) deploy IMG=$(OPERATOR_IMAGE):latest install_stunner: helm dependency build $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_STUNNER) --skip-refresh From 85297f551a400713440bc2a614e0961883a516ac Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 16:48:27 +0200 Subject: [PATCH 26/52] Fixed label mess --- helm/api/values-dev.yaml | 2 +- helm/api/values.yaml | 2 +- helm/frontend/values-dev.yaml | 2 +- helm/frontend/values.yaml | 2 +- scripts/localenv/Makefile | 15 ++++++++------- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/helm/api/values-dev.yaml b/helm/api/values-dev.yaml index f145bcf..955540b 100644 --- a/helm/api/values-dev.yaml +++ b/helm/api/values-dev.yaml @@ -1,6 +1,6 @@ image: name: indiegamestream/api - label: latest + label: localenv pullPolicy: Never env: diff --git a/helm/api/values.yaml b/helm/api/values.yaml index 929f7f1..fe4a44a 100644 --- a/helm/api/values.yaml +++ b/helm/api/values.yaml @@ -4,7 +4,7 @@ port: 8080 image: name: ghcr.io/austriandatalab/indiegamestream/api - label: latest # Change to proper version tag + label: v1.0.0 # Change to proper version tag pullPolicy: IfNotPresent env: diff --git a/helm/frontend/values-dev.yaml b/helm/frontend/values-dev.yaml index 098908a..fa29e29 100644 --- a/helm/frontend/values-dev.yaml +++ b/helm/frontend/values-dev.yaml @@ -1,4 +1,4 @@ image: name: indiegamestream/frontend - label: latest + label: localenv pullPolicy: Never \ No newline at end of file diff --git a/helm/frontend/values.yaml b/helm/frontend/values.yaml index a9d7eaf..8764c69 100644 --- a/helm/frontend/values.yaml +++ b/helm/frontend/values.yaml @@ -4,5 +4,5 @@ port: 80 image: name: ghcr.io/austriandatalab/indiegamestream/frontend - label: latest # Change to proper version tag + label: v1.0.0 # Change to proper version tag pullPolicy: IfNotPresent \ No newline at end of file diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 1a35560..24e71df 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -9,19 +9,20 @@ endef ROOT_DIRECTORY = ../.. CLUSTER_NAME = indiegamestream IMAGE_NAMESPACE = indiegamestream +IMAGE_LABEL = localenv FRONTEND_NAME=frontend -FRONTEND_IMAGE=$(IMAGE_NAMESPACE)/$(FRONTEND_NAME) +FRONTEND_IMAGE=$(IMAGE_NAMESPACE)/$(FRONTEND_NAME):$(IMAGE_LABEL) FRONTEND_DIRECTORY=frontend FRONTEND_DOCKERFILE=frontend/Dockerfile API_NAME=api -API_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME) +API_IMAGE=$(IMAGE_NAMESPACE)/$(API_NAME):$(IMAGE_LABEL) API_DIRECTORY=api API_DOCKERFILE=api/Dockerfile OPERATOR_NAME=operator -OPERATOR_IMAGE=$(IMAGE_NAMESPACE)/$(OPERATOR_NAME) +OPERATOR_IMAGE=$(IMAGE_NAMESPACE)/$(OPERATOR_NAME):$(IMAGE_LABEL) OPERATOR_DIRECTORY=operator OPERATOR_DOCKERFILE=operator/Dockerfile @@ -66,13 +67,13 @@ teardown_cluster: kind delete cluster --name $(CLUSTER_NAME) build_frontend: - docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_IMAGE):latest -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(FRONTEND_DIRECTORY) -t $(FRONTEND_IMAGE) -f $(ROOT_DIRECTORY)/$(FRONTEND_DOCKERFILE) build_api: - docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_IMAGE):latest -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(API_DIRECTORY) -t $(API_IMAGE) -f $(ROOT_DIRECTORY)/$(API_DOCKERFILE) build_operator: - docker build $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) -t $(OPERATOR_IMAGE):latest -f $(ROOT_DIRECTORY)/$(OPERATOR_DOCKERFILE) + docker build $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) -t $(OPERATOR_IMAGE) -f $(ROOT_DIRECTORY)/$(OPERATOR_DOCKERFILE) load_frontend: kind load docker-image $(FRONTEND_IMAGE) --name $(CLUSTER_NAME) @@ -104,7 +105,7 @@ install_api: $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) install_operator: - $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) deploy IMG=$(OPERATOR_IMAGE):latest + $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) deploy IMG=$(OPERATOR_IMAGE) install_stunner: helm dependency build $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_STUNNER) --skip-refresh From fe8fe1d21d9a3153721066639b87495e33a616d4 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 18:08:07 +0200 Subject: [PATCH 27/52] Updated README --- scripts/localenv/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index b5e3352..6fed7e3 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -1,4 +1,5 @@ # Prerequisites +- Debian-based system - docker - kubectl - kind From 65d333cf9e1963517858c3f64378144e53340f43 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 20:44:30 +0200 Subject: [PATCH 28/52] Added runtime configuration for frontend --- frontend/indiestream/src/app/app.config.ts | 20 +++++++++-- .../src/app/services/app-config.service.ts | 36 +++++++++++++++++++ .../src/app/services/games.service.ts | 8 +++-- .../indiestream/src/assets/app.config.json | 4 +++ .../templates/frontend-configmap.yaml | 8 +++++ .../templates/frontend-deployment.yaml | 11 +++++- helm/frontend/values-dev.yaml | 5 ++- helm/frontend/values.yaml | 7 +++- scripts/localenv/Makefile | 3 +- 9 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 frontend/indiestream/src/app/services/app-config.service.ts create mode 100644 frontend/indiestream/src/assets/app.config.json create mode 100644 helm/frontend/templates/frontend-configmap.yaml diff --git a/frontend/indiestream/src/app/app.config.ts b/frontend/indiestream/src/app/app.config.ts index 9e293ec..71d5611 100644 --- a/frontend/indiestream/src/app/app.config.ts +++ b/frontend/indiestream/src/app/app.config.ts @@ -1,11 +1,27 @@ -import {ApplicationConfig, importProvidersFrom} from '@angular/core'; +import {APP_INITIALIZER, ApplicationConfig, importProvidersFrom} from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; import { provideHttpClient } from "@angular/common/http"; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import {provideAnimations} from "@angular/platform-browser/animations"; +import { AppConfigService } from './services/app-config.service'; + +export function initConfig(appConfig: AppConfigService) { + return () => appConfig.loadConfig(); +} export const appConfig: ApplicationConfig = { - providers: [provideRouter(routes), provideHttpClient(), provideAnimationsAsync(), provideAnimations()] + providers: [ + provideRouter(routes), + provideHttpClient(), + provideAnimationsAsync(), + provideAnimations(), + { + provide: APP_INITIALIZER, + useFactory: initConfig, + deps: [AppConfigService], + multi: true + } + ] }; diff --git a/frontend/indiestream/src/app/services/app-config.service.ts b/frontend/indiestream/src/app/services/app-config.service.ts new file mode 100644 index 0000000..6eea574 --- /dev/null +++ b/frontend/indiestream/src/app/services/app-config.service.ts @@ -0,0 +1,36 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { firstValueFrom, lastValueFrom } from 'rxjs'; + +export interface AppConfig { + production: boolean; + apiUrl: string; +} + +@Injectable({ + providedIn: 'root' +}) +export class AppConfigService { + private config: AppConfig = { + production: false, + apiUrl: "http://localhost:8080" + }; + + constructor(private http: HttpClient) {} + + loadConfig(): Promise { + return firstValueFrom( + this.http.get('/assets/app.config.json') + ).then( data => { + console.log("Config file loaded successfully", data) + this.config = data; + }).catch( err => { + console.error(err); + return Promise.reject(err) + }); + } + + getConfig(): AppConfig { + return this.config; + } +} diff --git a/frontend/indiestream/src/app/services/games.service.ts b/frontend/indiestream/src/app/services/games.service.ts index ef3f400..447e222 100644 --- a/frontend/indiestream/src/app/services/games.service.ts +++ b/frontend/indiestream/src/app/services/games.service.ts @@ -2,14 +2,16 @@ import { Injectable } from "@angular/core"; import {HttpClient, HttpEvent} from '@angular/common/http'; import { Games, Game } from '../modules/games'; import { Observable } from "rxjs"; -import { environment } from "../environment"; +import { AppConfigService } from "./app-config.service"; @Injectable({ providedIn: 'root' }) export class GamesService { - private apiUrl = environment.apiUrl - constructor(private http: HttpClient) { } + private apiUrl = this.configService.getConfig().apiUrl; + constructor(private http: HttpClient, private configService: AppConfigService) { + console.log(this.configService.getConfig()) + } getGames(): Observable { return this.http.get(this.apiUrl + "/games/"); diff --git a/frontend/indiestream/src/assets/app.config.json b/frontend/indiestream/src/assets/app.config.json new file mode 100644 index 0000000..7aab492 --- /dev/null +++ b/frontend/indiestream/src/assets/app.config.json @@ -0,0 +1,4 @@ +{ + "production": false, + "apiUrl": "http://localhost:8080" +} \ No newline at end of file diff --git a/helm/frontend/templates/frontend-configmap.yaml b/helm/frontend/templates/frontend-configmap.yaml new file mode 100644 index 0000000..56f95b4 --- /dev/null +++ b/helm/frontend/templates/frontend-configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Values.appName }}-config + namespace: {{ .Values.appName }} +data: + app.config.json: |- +{{ toJson .Values.appConfig | indent 4 }} \ No newline at end of file diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml index 863c37b..2fc0ec0 100644 --- a/helm/frontend/templates/frontend-deployment.yaml +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -20,4 +20,13 @@ spec: image: {{ .Values.image.name }}:{{ .Values.image.label }} imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - - containerPort: {{ .Values.port }} \ No newline at end of file + - containerPort: {{ .Values.port }} + volumeMounts: + - name: "{{ .Values.appName }}-config" + mountPath: "{{ .Values.webRootDirectory }}/assets/app.config.json" + subPath: app.config.json + readOnly: true + volumes: + - name: "{{ .Values.appName }}-config" + configMap: + name: "{{ .Values.appName }}-config" \ No newline at end of file diff --git a/helm/frontend/values-dev.yaml b/helm/frontend/values-dev.yaml index fa29e29..0965df8 100644 --- a/helm/frontend/values-dev.yaml +++ b/helm/frontend/values-dev.yaml @@ -1,4 +1,7 @@ image: name: indiegamestream/frontend label: localenv - pullPolicy: Never \ No newline at end of file + pullPolicy: Never + +appConfig: + production: false \ No newline at end of file diff --git a/helm/frontend/values.yaml b/helm/frontend/values.yaml index 8764c69..ca3a07a 100644 --- a/helm/frontend/values.yaml +++ b/helm/frontend/values.yaml @@ -5,4 +5,9 @@ port: 80 image: name: ghcr.io/austriandatalab/indiegamestream/frontend label: v1.0.0 # Change to proper version tag - pullPolicy: IfNotPresent \ No newline at end of file + pullPolicy: IfNotPresent + +webRootDirecotry: /usr/share/nginx/html + +appConfig: + production: true \ No newline at end of file diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 24e71df..c9d1bf2 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -50,7 +50,7 @@ load_images: load_frontend load_api load_operator delete_images: delete_frontend delete_api delete_operator -install: install_frontend install_mysql install_api install_stunner install_operator +install: install_mysql install_api install_frontend install_stunner install_operator uninstall: uninstall_frontend uninstall_api uninstall_mysql uninstall_stunner uninstall_operator @@ -87,6 +87,7 @@ load_operator: install_frontend: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ + --set-string appConfig.apiUrl $(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') \ $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: From c4ee9d611bdf6ff5f6887ec61780fb85845e9795 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Sun, 2 Jun 2024 23:38:40 +0200 Subject: [PATCH 29/52] Output and set API url properly --- scripts/localenv/Makefile | 8 ++++++-- scripts/localenv/README.md | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index c9d1bf2..fd8e6c2 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -87,7 +87,7 @@ load_operator: install_frontend: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ - --set-string appConfig.apiUrl $(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') \ + --set-string appConfig.apiUrl $$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') \ $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: @@ -146,6 +146,10 @@ redeploy_operator: uninstall_operator build_operator load_operator install_opera output: $(info $(HEADER)) + @echo "----------------------------------------------------------------------" @echo "Type 'make destroy' to delete the cluster and locally build images" @echo "Type 'make teardown_cluster' to only delete the cluster" - @echo "Type 'make redeploy_api/frontend/operator' to rebuild and redeploy the given component to the cluster" \ No newline at end of file + @echo "Type 'make redeploy_api/frontend/operator' to rebuild and redeploy the given component to the cluster" + @echo "----------------------------------------------------------------------" + @echo "The frontend is reachable under http://$$(kubectl get svc frontend -n frontend -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" + @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" \ No newline at end of file diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index 6fed7e3..aa89bdf 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -6,6 +6,16 @@ - helm v3.15.0+ - go v1.20.0+ +You need to disable IPV6 in Docker. This can be achieved by adding adding `"ipv6": false` to the Docker daemon config. +If no file exists, this can be achieved by (**overwrites existing config file**): +```bash +echo '{"ipv6": false}' > /etc/docker/daemon.json +``` +Restart the Docker daemon for the configuration to apply: +```bash +sudo systemctl restart docker +``` + # How to run ## Single-node cluster ```bash From d4bc2c6a9683fe347d1cb4ffc2fbaaf88c0fc769 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:03:47 +0200 Subject: [PATCH 30/52] Add API port to README --- scripts/localenv/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index fd8e6c2..9808aa4 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -152,4 +152,4 @@ output: @echo "Type 'make redeploy_api/frontend/operator' to rebuild and redeploy the given component to the cluster" @echo "----------------------------------------------------------------------" @echo "The frontend is reachable under http://$$(kubectl get svc frontend -n frontend -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" - @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" \ No newline at end of file + @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):8080" \ No newline at end of file From 6b2369f9624f955e56b40deaa2d09ac06d68bc62 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:06:44 +0200 Subject: [PATCH 31/52] Properly set API url in frontend --- scripts/localenv/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 9808aa4..0601e47 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -85,10 +85,12 @@ load_operator: kind load docker-image $(OPERATOR_IMAGE) --name $(CLUSTER_NAME) install_frontend: + set -e ;\ + API_IP=$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ;\ helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ - --set-string appConfig.apiUrl $$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') \ - $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) + --set-string appConfig.apiUrl=$$API_IP \ + $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) ;\ install_mysql: helm repo add mysql-operator https://mysql.github.io/mysql-operator/ From 41727299da131b859cd49f2fa9908c517920c3c3 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:28:52 +0200 Subject: [PATCH 32/52] Redeploying frontend after API was redeployed --- scripts/localenv/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 0601e47..16b4c4d 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -142,7 +142,7 @@ delete_operator: redeploy_frontend: uninstall_frontend build_frontend load_frontend install_frontend -redeploy_api: uninstall_api build_api load_api install_api +redeploy_api: uninstall_api build_api load_api install_api redeploy_frontend redeploy_operator: uninstall_operator build_operator load_operator install_operator From 691f3bea62307782ffde2a914d908c50d13d2593 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:29:12 +0200 Subject: [PATCH 33/52] db_state table now has primary key --- api/migrations/0_init.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/migrations/0_init.sql b/api/migrations/0_init.sql index bb816f5..c66b6b6 100644 --- a/api/migrations/0_init.sql +++ b/api/migrations/0_init.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS db_state ( - migrations int + migrations int NOT NULL primary key ); CREATE TABLE IF NOT EXISTS games ( From 933179d35eaebe03b7dc6146eb779bd13bab7460 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:43:10 +0200 Subject: [PATCH 34/52] Added comments to Makefile --- scripts/localenv/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 16b4c4d..7882c18 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -38,20 +38,28 @@ HELM_STUNNER=stunner .PHONY: * +# Creates a single-node cluster and installs all components on it all: build_images create_cluster load_images add_metallb install output - + +# Creates a cluster with three nodes and installs all components on it multi_node: build_images create_multinode_cluster load_images add_metallb install output +# Removes the cluster and all local images destroy: teardown_cluster delete_images +# Builds images build_images: build_frontend build_api build_operator +# Loads images into the cluster load_images: load_frontend load_api load_operator +# Deletes built images locally delete_images: delete_frontend delete_api delete_operator +# Creates all our components install: install_mysql install_api install_frontend install_stunner install_operator +# Cleans up the cluster, removing all components uninstall: uninstall_frontend uninstall_api uninstall_mysql uninstall_stunner uninstall_operator create_cluster: @@ -152,6 +160,7 @@ output: @echo "Type 'make destroy' to delete the cluster and locally build images" @echo "Type 'make teardown_cluster' to only delete the cluster" @echo "Type 'make redeploy_api/frontend/operator' to rebuild and redeploy the given component to the cluster" + @echo "Other useful targets can be found in the Makefile" @echo "----------------------------------------------------------------------" @echo "The frontend is reachable under http://$$(kubectl get svc frontend -n frontend -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):8080" \ No newline at end of file From 2224fc4ee6f4afbb469089055c923fa61109452e Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:47:41 +0200 Subject: [PATCH 35/52] Adding STUNner repo --- scripts/localenv/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 7882c18..bcc2980 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -119,6 +119,8 @@ install_operator: $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) deploy IMG=$(OPERATOR_IMAGE) install_stunner: + helm repo add stunner https://l7mp.io/stunner + helm repo update helm dependency build $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_STUNNER) --skip-refresh helm install $(STUNNER_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_STUNNER) \ --create-namespace --namespace=$(STUNNER_NAME) From fb93aee8996335e889b9c8ca17337928adc8d253 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 00:59:31 +0200 Subject: [PATCH 36/52] Improved help --- scripts/localenv/Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index bcc2980..8ffaf6b 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -39,10 +39,10 @@ HELM_STUNNER=stunner .PHONY: * # Creates a single-node cluster and installs all components on it -all: build_images create_cluster load_images add_metallb install output +all: build_images create_cluster load_images add_metallb install help # Creates a cluster with three nodes and installs all components on it -multi_node: build_images create_multinode_cluster load_images add_metallb install output +multi_node: build_images create_multinode_cluster load_images add_metallb install help # Removes the cluster and all local images destroy: teardown_cluster delete_images @@ -156,13 +156,15 @@ redeploy_api: uninstall_api build_api load_api install_api redeploy_frontend redeploy_operator: uninstall_operator build_operator load_operator install_operator -output: +help: $(info $(HEADER)) @echo "----------------------------------------------------------------------" @echo "Type 'make destroy' to delete the cluster and locally build images" @echo "Type 'make teardown_cluster' to only delete the cluster" @echo "Type 'make redeploy_api/frontend/operator' to rebuild and redeploy the given component to the cluster" + @echo "Type 'make help' to get this information" @echo "Other useful targets can be found in the Makefile" @echo "----------------------------------------------------------------------" @echo "The frontend is reachable under http://$$(kubectl get svc frontend -n frontend -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" - @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):8080" \ No newline at end of file + @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):8080" + @echo "----------------------------------------------------------------------" \ No newline at end of file From 3812b9dc9e7bde521ec005e59035fbb67c97a290 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 01:21:44 +0200 Subject: [PATCH 37/52] Small bug fixes --- scripts/localenv/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 8ffaf6b..c001bfe 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -93,12 +93,10 @@ load_operator: kind load docker-image $(OPERATOR_IMAGE) --name $(CLUSTER_NAME) install_frontend: - set -e ;\ - API_IP=$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ;\ helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ - --set-string appConfig.apiUrl=$$API_IP \ - $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) ;\ + --set-string appConfig.apiUrl=$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') \ + $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: helm repo add mysql-operator https://mysql.github.io/mysql-operator/ @@ -111,6 +109,7 @@ install_mysql: -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values-dev.yaml install_api: + kubectl wait --for=condition=Ready pod/$(MYSQL_NAME)-0 -n $(MYSQL_NAME) --timeout 600s helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) From effdfb289aa380f1b488ff8973e10c8d60320f9d Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 01:36:51 +0200 Subject: [PATCH 38/52] Properly wait for MySQL to be ready --- scripts/localenv/Makefile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index c001bfe..a9a7e57 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -108,8 +108,7 @@ install_mysql: -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_MYSQL)/values-dev.yaml -install_api: - kubectl wait --for=condition=Ready pod/$(MYSQL_NAME)-0 -n $(MYSQL_NAME) --timeout 600s +install_api: wait_for_mysql helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API)/values-dev.yaml \ $(API_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_API) @@ -155,6 +154,19 @@ redeploy_api: uninstall_api build_api load_api install_api redeploy_frontend redeploy_operator: uninstall_operator build_operator load_operator install_operator +wait_for_mysql: + @while true; do \ + POD_STATUS=$$(kubectl get pod $(MYSQL_NAME)-0 -n $(MYSQL_NAME) --no-headers -o custom-columns=":status.phase" 2>/dev/null); \ + if [ "$$POD_STATUS" ]; then \ + echo "Pod $(MYSQL_NAME)-0 is created with status: $$POD_STATUS"; \ + break; \ + else \ + echo "Waiting for pod $(MYSQL_NAME)-0 to be created..."; \ + sleep 2; \ + fi \ + done + kubectl wait --for=condition=Ready pod/$(MYSQL_NAME)-0 -n $(MYSQL_NAME) --timeout 600s + help: $(info $(HEADER)) @echo "----------------------------------------------------------------------" From a5966180f90f43e005e7c38f6293a33caf1c701b Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 01:57:53 +0200 Subject: [PATCH 39/52] Fix proper handling of app config in frontend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Small bug fix§ Small bug fix§ Small bug fix Small bug fix --- frontend/indiestream/src/assets/app.config.json | 4 ---- helm/frontend/templates/frontend-deployment.yaml | 12 +++++++----- helm/frontend/values.yaml | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 frontend/indiestream/src/assets/app.config.json diff --git a/frontend/indiestream/src/assets/app.config.json b/frontend/indiestream/src/assets/app.config.json deleted file mode 100644 index 7aab492..0000000 --- a/frontend/indiestream/src/assets/app.config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "production": false, - "apiUrl": "http://localhost:8080" -} \ No newline at end of file diff --git a/helm/frontend/templates/frontend-deployment.yaml b/helm/frontend/templates/frontend-deployment.yaml index 2fc0ec0..d008ee4 100644 --- a/helm/frontend/templates/frontend-deployment.yaml +++ b/helm/frontend/templates/frontend-deployment.yaml @@ -22,11 +22,13 @@ spec: ports: - containerPort: {{ .Values.port }} volumeMounts: - - name: "{{ .Values.appName }}-config" - mountPath: "{{ .Values.webRootDirectory }}/assets/app.config.json" - subPath: app.config.json + - name: "{{ .Values.appName }}-config-volume" + mountPath: "{{ .Values.webRootDirectory }}/assets" readOnly: true volumes: - - name: "{{ .Values.appName }}-config" + - name: "{{ .Values.appName }}-config-volume" configMap: - name: "{{ .Values.appName }}-config" \ No newline at end of file + name: "{{ .Values.appName }}-config" + items: + - key: app.config.json + path: app.config.json \ No newline at end of file diff --git a/helm/frontend/values.yaml b/helm/frontend/values.yaml index ca3a07a..a6bc86a 100644 --- a/helm/frontend/values.yaml +++ b/helm/frontend/values.yaml @@ -7,7 +7,7 @@ image: label: v1.0.0 # Change to proper version tag pullPolicy: IfNotPresent -webRootDirecotry: /usr/share/nginx/html +webRootDirectory: /usr/share/nginx/html appConfig: production: true \ No newline at end of file From 9d12fb639b23019c4e882188f43ba8029c5e1567 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 02:47:00 +0200 Subject: [PATCH 40/52] Reading in port using kubectl status --- scripts/localenv/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index a9a7e57..e7ebc79 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -95,7 +95,7 @@ load_operator: install_frontend: helm install -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values.yaml \ -f $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND)/values-dev.yaml \ - --set-string appConfig.apiUrl=$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}') \ + --set-string appConfig.apiUrl=http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):$$(kubectl get svc api -n api -o jsonpath='{.spec.ports[0].port}') \ $(FRONTEND_NAME) $(ROOT_DIRECTORY)/$(HELM_DIRECTORY)/$(HELM_FRONTEND) install_mysql: @@ -177,5 +177,5 @@ help: @echo "Other useful targets can be found in the Makefile" @echo "----------------------------------------------------------------------" @echo "The frontend is reachable under http://$$(kubectl get svc frontend -n frontend -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" - @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):8080" + @echo "The API is reachable under http://$$(kubectl get svc api -n api -o jsonpath='{.status.loadBalancer.ingress[0].ip}'):$$(kubectl get svc api -n api -o jsonpath='{.spec.ports[0].port}')" @echo "----------------------------------------------------------------------" \ No newline at end of file From 46cdb7f229f2426e3aef159433fe2ea211658c34 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 03:09:37 +0200 Subject: [PATCH 41/52] Increase wait timeout for metallb wait --- scripts/localenv/add_metallb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/add_metallb.sh b/scripts/localenv/add_metallb.sh index 4f347d7..782c1e2 100755 --- a/scripts/localenv/add_metallb.sh +++ b/scripts/localenv/add_metallb.sh @@ -7,7 +7,7 @@ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.4/confi kubectl wait --namespace metallb-system \ --for=condition=ready pod \ --selector=app=metallb \ - --timeout=90s + --timeout=600s lb_subnet=$(docker network inspect kind --format '{{json .}}' | jq -r '.IPAM.Config[0].Subnet') # Extract the base IP and calculate the range start and end From 79e0a79ae4ac273c68556b38267e151e378ebbc2 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 12:23:03 +0200 Subject: [PATCH 42/52] Added Note to README --- scripts/localenv/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index aa89bdf..db343ab 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -25,4 +25,9 @@ make ## Multi-node cluster ```bash make multi-node -``` \ No newline at end of file +``` + +## Note +The API pod may restart a couple of times (for me its 3 times) before it is actually up and running. This is because +the MySQL pod even though it is ready still doesn't accept incoming connections. I thought that the easier solution right now is just +to keep it like this and let the API pod restart a couple of times. \ No newline at end of file From db981bd979b98157bf32dd249d1e6467fa39cfce Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 12:35:47 +0200 Subject: [PATCH 43/52] Changed install order --- scripts/localenv/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index e7ebc79..70c9723 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -57,7 +57,7 @@ load_images: load_frontend load_api load_operator delete_images: delete_frontend delete_api delete_operator # Creates all our components -install: install_mysql install_api install_frontend install_stunner install_operator +install: install_mysql install_stunner install_operator install_api install_frontend # Cleans up the cluster, removing all components uninstall: uninstall_frontend uninstall_api uninstall_mysql uninstall_stunner uninstall_operator From 912ecdeae7ba6416106c1fb2b193e49925191cc7 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 12:42:24 +0200 Subject: [PATCH 44/52] Fixed mistake in MySQL uninstall --- scripts/localenv/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index 70c9723..ef54b13 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -133,7 +133,7 @@ uninstall_operator: $(MAKE) -C $(ROOT_DIRECTORY)/$(OPERATOR_DIRECTORY) undeploy uninstall_mysql: - helm uninstall $(MYSQL_NAME) -n $(MYSQL_NAME)-cluster --wait + helm uninstall $(MYSQL_NAME) -n $(MYSQL_NAME) --wait helm uninstall $(MYSQL_NAME)-operator -n $(MYSQL_NAME)-operator --wait uninstall_stunner: From 862b7dffb6e33702fb4163408072a169c896936e Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 12:46:05 +0200 Subject: [PATCH 45/52] Waiting for MySQL router to be ready instead of pod --- scripts/localenv/Makefile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index ef54b13..f20b5cb 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -155,17 +155,7 @@ redeploy_api: uninstall_api build_api load_api install_api redeploy_frontend redeploy_operator: uninstall_operator build_operator load_operator install_operator wait_for_mysql: - @while true; do \ - POD_STATUS=$$(kubectl get pod $(MYSQL_NAME)-0 -n $(MYSQL_NAME) --no-headers -o custom-columns=":status.phase" 2>/dev/null); \ - if [ "$$POD_STATUS" ]; then \ - echo "Pod $(MYSQL_NAME)-0 is created with status: $$POD_STATUS"; \ - break; \ - else \ - echo "Waiting for pod $(MYSQL_NAME)-0 to be created..."; \ - sleep 2; \ - fi \ - done - kubectl wait --for=condition=Ready pod/$(MYSQL_NAME)-0 -n $(MYSQL_NAME) --timeout 600s + kubectl wait --for=condition=ready pod -l app.kubernetes.io/component=router --timeout=600s help: $(info $(HEADER)) From 7ad839c58bf6a86fc199457ce3ca9cbbc6e5078b Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 12:52:15 +0200 Subject: [PATCH 46/52] Potential fix for waiting for the MySQL router --- scripts/localenv/Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index f20b5cb..c49a667 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -155,7 +155,17 @@ redeploy_api: uninstall_api build_api load_api install_api redeploy_frontend redeploy_operator: uninstall_operator build_operator load_operator install_operator wait_for_mysql: - kubectl wait --for=condition=ready pod -l app.kubernetes.io/component=router --timeout=600s + @while true; do \ + POD_STATUS=$$(kubectl get pod -l app.kubernetes.io/component=router -n $(MYSQL_NAME) --no-headers -o custom-columns=":status.phase" 2>/dev/null); \ + if [ "$$POD_STATUS" ]; then \ + echo "MySQL router is created with status: $$POD_STATUS"; \ + break; \ + else \ + echo "Waiting for MySQL router to be created..."; \ + sleep 2; \ + fi \ + done + kubectl wait --for=condition=ready pod -l app.kubernetes.io/component=router -n $(MYSQL_NAME) --timeout=600s help: $(info $(HEADER)) From 05f4eb141cd18f51cc7ccbbdea6b350f9aced76a Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 13:01:15 +0200 Subject: [PATCH 47/52] Improve waiting for MySQL even further --- scripts/localenv/Makefile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/localenv/Makefile b/scripts/localenv/Makefile index c49a667..8f02a11 100644 --- a/scripts/localenv/Makefile +++ b/scripts/localenv/Makefile @@ -154,7 +154,20 @@ redeploy_api: uninstall_api build_api load_api install_api redeploy_frontend redeploy_operator: uninstall_operator build_operator load_operator install_operator +# waiting for MySQL pod to be created and then wait until router is ready wait_for_mysql: + @while true; do \ + POD_STATUS=$$(kubectl get pod $(MYSQL_NAME)-0 -n $(MYSQL_NAME) --no-headers -o custom-columns=":status.phase" 2>/dev/null); \ + if [ "$$POD_STATUS" ]; then \ + echo "Pod $(MYSQL_NAME)-0 is created with status: $$POD_STATUS"; \ + break; \ + else \ + echo "Waiting for pod $(MYSQL_NAME)-0 to be created..."; \ + sleep 2; \ + fi \ + done + kubectl wait --for=condition=Ready pod/$(MYSQL_NAME)-0 -n $(MYSQL_NAME) --timeout 600s + @while true; do \ POD_STATUS=$$(kubectl get pod -l app.kubernetes.io/component=router -n $(MYSQL_NAME) --no-headers -o custom-columns=":status.phase" 2>/dev/null); \ if [ "$$POD_STATUS" ]; then \ @@ -162,7 +175,7 @@ wait_for_mysql: break; \ else \ echo "Waiting for MySQL router to be created..."; \ - sleep 2; \ + sleep 5; \ fi \ done kubectl wait --for=condition=ready pod -l app.kubernetes.io/component=router -n $(MYSQL_NAME) --timeout=600s From 2593b5aa17bf1404f8ccfd6a7ebe40ada71cbe48 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 13:12:09 +0200 Subject: [PATCH 48/52] Removed Note in README --- scripts/localenv/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index db343ab..80d84a2 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -26,8 +26,3 @@ make ```bash make multi-node ``` - -## Note -The API pod may restart a couple of times (for me its 3 times) before it is actually up and running. This is because -the MySQL pod even though it is ready still doesn't accept incoming connections. I thought that the easier solution right now is just -to keep it like this and let the API pod restart a couple of times. \ No newline at end of file From 291ed525a796cbca0e21d65529239ebb3ef3588f Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 13:46:11 +0200 Subject: [PATCH 49/52] Fixed typo in README --- scripts/localenv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/localenv/README.md b/scripts/localenv/README.md index 80d84a2..1615f0d 100644 --- a/scripts/localenv/README.md +++ b/scripts/localenv/README.md @@ -24,5 +24,5 @@ make ## Multi-node cluster ```bash -make multi-node +make multi_node ``` From b745da7973f5dd10b52d9aadb5aa35f89a2d75ce Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 14:04:16 +0200 Subject: [PATCH 50/52] Frontend defaults to development config if no external config provided --- frontend/indiestream/src/app/services/app-config.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/indiestream/src/app/services/app-config.service.ts b/frontend/indiestream/src/app/services/app-config.service.ts index 6eea574..5bf5270 100644 --- a/frontend/indiestream/src/app/services/app-config.service.ts +++ b/frontend/indiestream/src/app/services/app-config.service.ts @@ -26,7 +26,7 @@ export class AppConfigService { this.config = data; }).catch( err => { console.error(err); - return Promise.reject(err) + console.log("Defaulting to development config", this.config) }); } From 939347c99a747885ad5c5d7b95531061ed48a22a Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 14:11:47 +0200 Subject: [PATCH 51/52] Removed environment.ts --- frontend/indiestream/src/app/environment.ts | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 frontend/indiestream/src/app/environment.ts diff --git a/frontend/indiestream/src/app/environment.ts b/frontend/indiestream/src/app/environment.ts deleted file mode 100644 index 126cf4c..0000000 --- a/frontend/indiestream/src/app/environment.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const environment = { - production: false, - apiUrl: 'http://localhost:8080', -}; From b1021e1542d37a9a51713c8ac75211738b3bf1d7 Mon Sep 17 00:00:00 2001 From: Thomas Riegler Date: Mon, 3 Jun 2024 19:05:00 +0200 Subject: [PATCH 52/52] Remove unneeded folders --- helm/control-server/.gitkeep | 0 helm/operator/.helmignore | 23 ----------------------- helm/operator/Chart.yaml | 24 ------------------------ helm/operator/values-dev.yaml | 0 helm/operator/values.yaml | 0 scripts/control-server/.gitkeep | 0 scripts/stunner/.gitkeep | 0 7 files changed, 47 deletions(-) delete mode 100644 helm/control-server/.gitkeep delete mode 100644 helm/operator/.helmignore delete mode 100644 helm/operator/Chart.yaml delete mode 100644 helm/operator/values-dev.yaml delete mode 100644 helm/operator/values.yaml delete mode 100644 scripts/control-server/.gitkeep delete mode 100644 scripts/stunner/.gitkeep diff --git a/helm/control-server/.gitkeep b/helm/control-server/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/helm/operator/.helmignore b/helm/operator/.helmignore deleted file mode 100644 index 0e8a0eb..0000000 --- a/helm/operator/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# 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/operator/Chart.yaml b/helm/operator/Chart.yaml deleted file mode 100644 index b9c7cc6..0000000 --- a/helm/operator/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: operator -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/helm/operator/values-dev.yaml b/helm/operator/values-dev.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/helm/operator/values.yaml b/helm/operator/values.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/control-server/.gitkeep b/scripts/control-server/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/stunner/.gitkeep b/scripts/stunner/.gitkeep deleted file mode 100644 index e69de29..0000000