From e8c75ec9678459f2a938a4471729526c4d73808c Mon Sep 17 00:00:00 2001 From: Baitinq Date: Thu, 2 May 2024 17:35:56 +0200 Subject: payload-processor: add stub --- README.md | 3 + k8s/payload-processor/.helmignore | 23 ++++++ k8s/payload-processor/Chart.yaml | 24 +++++++ k8s/payload-processor/templates/_helpers.tpl | 62 ++++++++++++++++ k8s/payload-processor/templates/deployment.yaml | 53 ++++++++++++++ .../templates/serviceaccount.yaml | 12 ++++ k8s/payload-processor/values.yaml | 51 ++++++++++++++ k8s/payloads-processor/.helmignore | 23 ------ k8s/payloads-processor/Chart.yaml | 24 ------- k8s/payloads-processor/templates/NOTES.txt | 22 ------ k8s/payloads-processor/templates/_helpers.tpl | 62 ---------------- k8s/payloads-processor/templates/deployment.yaml | 61 ---------------- k8s/payloads-processor/templates/hpa.yaml | 28 -------- k8s/payloads-processor/templates/ingress.yaml | 61 ---------------- k8s/payloads-processor/templates/service.yaml | 15 ---- .../templates/serviceaccount.yaml | 12 ---- .../templates/tests/test-connection.yaml | 15 ---- k8s/payloads-processor/values.yaml | 82 ---------------------- src/payload-processor/cmd/BUILD.bazel | 53 ++++++++++++++ src/payload-processor/cmd/main.go | 43 ++++++++++++ src/payload-processor/processor/BUILD.bazel | 9 +++ src/payload-processor/processor/processor.go | 39 ++++++++++ src/rest-api/cmd/main.go | 8 +-- src/rest-api/handler/handler.go | 2 +- 24 files changed, 377 insertions(+), 410 deletions(-) create mode 100644 k8s/payload-processor/.helmignore create mode 100644 k8s/payload-processor/Chart.yaml create mode 100644 k8s/payload-processor/templates/_helpers.tpl create mode 100644 k8s/payload-processor/templates/deployment.yaml create mode 100644 k8s/payload-processor/templates/serviceaccount.yaml create mode 100644 k8s/payload-processor/values.yaml delete mode 100644 k8s/payloads-processor/.helmignore delete mode 100644 k8s/payloads-processor/Chart.yaml delete mode 100644 k8s/payloads-processor/templates/NOTES.txt delete mode 100644 k8s/payloads-processor/templates/_helpers.tpl delete mode 100644 k8s/payloads-processor/templates/deployment.yaml delete mode 100644 k8s/payloads-processor/templates/hpa.yaml delete mode 100644 k8s/payloads-processor/templates/ingress.yaml delete mode 100644 k8s/payloads-processor/templates/service.yaml delete mode 100644 k8s/payloads-processor/templates/serviceaccount.yaml delete mode 100644 k8s/payloads-processor/templates/tests/test-connection.yaml delete mode 100644 k8s/payloads-processor/values.yaml create mode 100644 src/payload-processor/cmd/BUILD.bazel create mode 100644 src/payload-processor/cmd/main.go create mode 100644 src/payload-processor/processor/BUILD.bazel create mode 100644 src/payload-processor/processor/processor.go diff --git a/README.md b/README.md index 8f24a31..89b3a2a 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,6 @@ helm install rabbitmq oci://registry-1.docker.io/bitnamicharts/rabbitmq bazel run //src/rest-api/cmd:push -- --tag "rest-api-$(git rev-parse --short HEAD)" helm upgrade rest-api --set image.tag="rest-api-$(git rev-parse --short HEAD)" k8s/rest-api + +bazel run //src/payload-processor/cmd:push -- --tag "payload-processor-$(git rev-parse --short HEAD)" +helm upgrade payload-processor --set image.tag="payload-processor-$(git rev-parse --short HEAD)" k8s/payload-processor diff --git a/k8s/payload-processor/.helmignore b/k8s/payload-processor/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/k8s/payload-processor/.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/k8s/payload-processor/Chart.yaml b/k8s/payload-processor/Chart.yaml new file mode 100644 index 0000000..a845876 --- /dev/null +++ b/k8s/payload-processor/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: payload-processor +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/k8s/payload-processor/templates/_helpers.tpl b/k8s/payload-processor/templates/_helpers.tpl new file mode 100644 index 0000000..0f89fcc --- /dev/null +++ b/k8s/payload-processor/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "payload-processor.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "payload-processor.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "payload-processor.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "payload-processor.labels" -}} +helm.sh/chart: {{ include "payload-processor.chart" . }} +{{ include "payload-processor.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "payload-processor.selectorLabels" -}} +app.kubernetes.io/name: {{ include "payload-processor.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "payload-processor.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "payload-processor.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/k8s/payload-processor/templates/deployment.yaml b/k8s/payload-processor/templates/deployment.yaml new file mode 100644 index 0000000..c86398d --- /dev/null +++ b/k8s/payload-processor/templates/deployment.yaml @@ -0,0 +1,53 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "payload-processor.fullname" . }} + labels: + {{- include "payload-processor.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "payload-processor.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "payload-processor.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "payload-processor.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + - name: RABBITMQ_PASSWORD + valueFrom: + secretKeyRef: + name: rabbitmq + key: rabbitmq-password + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/k8s/payload-processor/templates/serviceaccount.yaml b/k8s/payload-processor/templates/serviceaccount.yaml new file mode 100644 index 0000000..55e048e --- /dev/null +++ b/k8s/payload-processor/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "payload-processor.serviceAccountName" . }} + labels: + {{- include "payload-processor.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/k8s/payload-processor/values.yaml b/k8s/payload-processor/values.yaml new file mode 100644 index 0000000..b6c065b --- /dev/null +++ b/k8s/payload-processor/values.yaml @@ -0,0 +1,51 @@ +# Default values for payload-processor. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: docker.io/baitinq/fs-tracer + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/k8s/payloads-processor/.helmignore b/k8s/payloads-processor/.helmignore deleted file mode 100644 index 0e8a0eb..0000000 --- a/k8s/payloads-processor/.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/k8s/payloads-processor/Chart.yaml b/k8s/payloads-processor/Chart.yaml deleted file mode 100644 index f07f67a..0000000 --- a/k8s/payloads-processor/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: payloads-processor -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/k8s/payloads-processor/templates/NOTES.txt b/k8s/payloads-processor/templates/NOTES.txt deleted file mode 100644 index 75b1008..0000000 --- a/k8s/payloads-processor/templates/NOTES.txt +++ /dev/null @@ -1,22 +0,0 @@ -1. Get the application URL by running these commands: -{{- if .Values.ingress.enabled }} -{{- range $host := .Values.ingress.hosts }} - {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} - {{- end }} -{{- end }} -{{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "payloads-processor.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT -{{- else if contains "LoadBalancer" .Values.service.type }} - NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "payloads-processor.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "payloads-processor.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} -{{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "payloads-processor.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Visit http://127.0.0.1:8080 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT -{{- end }} diff --git a/k8s/payloads-processor/templates/_helpers.tpl b/k8s/payloads-processor/templates/_helpers.tpl deleted file mode 100644 index 5afe85a..0000000 --- a/k8s/payloads-processor/templates/_helpers.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "payloads-processor.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "payloads-processor.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "payloads-processor.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "payloads-processor.labels" -}} -helm.sh/chart: {{ include "payloads-processor.chart" . }} -{{ include "payloads-processor.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "payloads-processor.selectorLabels" -}} -app.kubernetes.io/name: {{ include "payloads-processor.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "payloads-processor.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "payloads-processor.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} diff --git a/k8s/payloads-processor/templates/deployment.yaml b/k8s/payloads-processor/templates/deployment.yaml deleted file mode 100644 index 585c443..0000000 --- a/k8s/payloads-processor/templates/deployment.yaml +++ /dev/null @@ -1,61 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "payloads-processor.fullname" . }} - labels: - {{- include "payloads-processor.labels" . | nindent 4 }} -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "payloads-processor.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "payloads-processor.selectorLabels" . | nindent 8 }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ include "payloads-processor.serviceAccountName" . }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - livenessProbe: - httpGet: - path: / - port: http - readinessProbe: - httpGet: - path: / - port: http - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/k8s/payloads-processor/templates/hpa.yaml b/k8s/payloads-processor/templates/hpa.yaml deleted file mode 100644 index 65025c9..0000000 --- a/k8s/payloads-processor/templates/hpa.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2beta1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ include "payloads-processor.fullname" . }} - labels: - {{- include "payloads-processor.labels" . | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ include "payloads-processor.fullname" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: - {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} - {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} -{{- end }} diff --git a/k8s/payloads-processor/templates/ingress.yaml b/k8s/payloads-processor/templates/ingress.yaml deleted file mode 100644 index 44dff68..0000000 --- a/k8s/payloads-processor/templates/ingress.yaml +++ /dev/null @@ -1,61 +0,0 @@ -{{- if .Values.ingress.enabled -}} -{{- $fullName := include "payloads-processor.fullname" . -}} -{{- $svcPort := .Values.service.port -}} -{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} - {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} - {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} - {{- end }} -{{- end }} -{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1 -{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 -{{- end }} -kind: Ingress -metadata: - name: {{ $fullName }} - labels: - {{- include "payloads-processor.labels" . | nindent 4 }} - {{- with .Values.ingress.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} - ingressClassName: {{ .Values.ingress.className }} - {{- end }} - {{- if .Values.ingress.tls }} - tls: - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . | quote }} - {{- end }} - secretName: {{ .secretName }} - {{- end }} - {{- end }} - rules: - {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} - pathType: {{ .pathType }} - {{- end }} - backend: - {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} - service: - name: {{ $fullName }} - port: - number: {{ $svcPort }} - {{- else }} - serviceName: {{ $fullName }} - servicePort: {{ $svcPort }} - {{- end }} - {{- end }} - {{- end }} -{{- end }} diff --git a/k8s/payloads-processor/templates/service.yaml b/k8s/payloads-processor/templates/service.yaml deleted file mode 100644 index ac0708e..0000000 --- a/k8s/payloads-processor/templates/service.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "payloads-processor.fullname" . }} - labels: - {{- include "payloads-processor.labels" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "payloads-processor.selectorLabels" . | nindent 4 }} diff --git a/k8s/payloads-processor/templates/serviceaccount.yaml b/k8s/payloads-processor/templates/serviceaccount.yaml deleted file mode 100644 index 5bc090b..0000000 --- a/k8s/payloads-processor/templates/serviceaccount.yaml +++ /dev/null @@ -1,12 +0,0 @@ -{{- if .Values.serviceAccount.create -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "payloads-processor.serviceAccountName" . }} - labels: - {{- include "payloads-processor.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -{{- end }} diff --git a/k8s/payloads-processor/templates/tests/test-connection.yaml b/k8s/payloads-processor/templates/tests/test-connection.yaml deleted file mode 100644 index 279e613..0000000 --- a/k8s/payloads-processor/templates/tests/test-connection.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "payloads-processor.fullname" . }}-test-connection" - labels: - {{- include "payloads-processor.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test -spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "payloads-processor.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never diff --git a/k8s/payloads-processor/values.yaml b/k8s/payloads-processor/values.yaml deleted file mode 100644 index 9ea2cd9..0000000 --- a/k8s/payloads-processor/values.yaml +++ /dev/null @@ -1,82 +0,0 @@ -# Default values for payloads-processor. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -replicaCount: 1 - -image: - repository: nginx - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "" - -imagePullSecrets: [] -nameOverride: "" -fullnameOverride: "" - -serviceAccount: - # Specifies whether a service account should be created - create: true - # Annotations to add to the service account - annotations: {} - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - -podAnnotations: {} - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - port: 80 - -ingress: - enabled: false - className: "" - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: - - path: / - pathType: ImplementationSpecific - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - # limits: - # cpu: 100m - # memory: 128Mi - # requests: - # cpu: 100m - # memory: 128Mi - -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - -nodeSelector: {} - -tolerations: [] - -affinity: {} diff --git a/src/payload-processor/cmd/BUILD.bazel b/src/payload-processor/cmd/BUILD.bazel new file mode 100644 index 0000000..515c17e --- /dev/null +++ b/src/payload-processor/cmd/BUILD.bazel @@ -0,0 +1,53 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library") +load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push", "oci_tarball") +load("@rules_pkg//:pkg.bzl", "pkg_tar") + +go_library( + name = "cmd_lib", + srcs = ["main.go"], + importpath = "github.com/Baitinq/fs-tracer-backend/src/payload-processor/cmd", + visibility = ["//visibility:private"], + deps = [ + "//src/payload-processor/processor", + "@com_github_rabbitmq_amqp091_go//:amqp091-go", + ], +) + +go_cross_binary( + name = "cmd_arm64", + platform = "@io_bazel_rules_go//go/toolchain:linux_arm64", + target = ":cmd", + visibility = ["//visibility:public"], +) + +pkg_tar( + name = "tar", + srcs = [":cmd_arm64"], +) + +oci_image( + name = "image", + base = "@distroless_base", + entrypoint = ["/cmd_arm64"], + # architecture = "arm64", + # os = "linux", + tars = [":tar"], +) + +oci_tarball( + name = "tarball", + image = ":image", + repo_tags = [], +) + +oci_push( + name = "push", + image = ":image", + repository = "docker.io/baitinq/fs-tracer", +) + +go_binary( + name = "cmd", + embed = [":cmd_lib"], + visibility = ["//visibility:public"], +) diff --git a/src/payload-processor/cmd/main.go b/src/payload-processor/cmd/main.go new file mode 100644 index 0000000..1c9bfcb --- /dev/null +++ b/src/payload-processor/cmd/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/Baitinq/fs-tracer-backend/src/payload-processor/processor" + amqp "github.com/rabbitmq/amqp091-go" +) + +func main() { + rabbitmq_password, ok := os.LookupEnv("RABBITMQ_PASSWORD") + if !ok { + log.Fatal("RABBITMQ_PASSWORD not set") + } + log.Println("RabbitMQ password", rabbitmq_password) + conn, err := amqp.Dial(fmt.Sprintf("amqp://user:%s@rabbitmq:5672/", rabbitmq_password)) + if err != nil { + log.Fatal(err) + } + defer conn.Close() + + ch, err := conn.Channel() + if err != nil { + log.Fatal(err) + } + defer ch.Close() + + q, err := ch.QueueDeclare( + "hello", // name + false, // durable + false, // delete when unused + false, // exclusive + false, // no-wait + nil, // arguments + ) + if err != nil { + log.Fatal(err) + } + processor := processor.NewProcessor(ch, q.Name) + processor.ProcessMessages() +} diff --git a/src/payload-processor/processor/BUILD.bazel b/src/payload-processor/processor/BUILD.bazel new file mode 100644 index 0000000..64e3ac2 --- /dev/null +++ b/src/payload-processor/processor/BUILD.bazel @@ -0,0 +1,9 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "processor", + srcs = ["processor.go"], + importpath = "github.com/Baitinq/fs-tracer-backend/src/payload-processor/processor", + visibility = ["//visibility:public"], + deps = ["@com_github_rabbitmq_amqp091_go//:amqp091-go"], +) diff --git a/src/payload-processor/processor/processor.go b/src/payload-processor/processor/processor.go new file mode 100644 index 0000000..9cd83f9 --- /dev/null +++ b/src/payload-processor/processor/processor.go @@ -0,0 +1,39 @@ +package processor + +import ( + "log" + + amqp "github.com/rabbitmq/amqp091-go" +) + +type Processor struct { + ch *amqp.Channel + queueName string +} + +func NewProcessor(ch *amqp.Channel, queueName string) *Processor { + log.Println("Created processor") + return &Processor{ + ch: ch, + queueName: queueName, + } +} + +func (p *Processor) ProcessMessages() { + msgs, err := p.ch.Consume( + p.queueName, // queue + "", // consumer + true, // auto-ack + false, // exclusive + false, // no-local + false, // no-wait + nil, // args + ) + if err != nil { + log.Fatal("Failed to register a consumer:", err) + } + + for msg := range msgs { + log.Printf("Received a message: %s", msg.Body) + } +} diff --git a/src/rest-api/cmd/main.go b/src/rest-api/cmd/main.go index 6740bea..f6d34e0 100644 --- a/src/rest-api/cmd/main.go +++ b/src/rest-api/cmd/main.go @@ -13,18 +13,18 @@ import ( func main() { rabbitmq_password, ok := os.LookupEnv("RABBITMQ_PASSWORD") if !ok { - panic("RABBITMQ_PASSWORD not set") + log.Fatal("RABBITMQ_PASSWORD not set") } log.Println("RabbitMQ password", rabbitmq_password) conn, err := amqp.Dial(fmt.Sprintf("amqp://user:%s@rabbitmq:5672/", rabbitmq_password)) if err != nil { - panic(err) + log.Fatal(err) } defer conn.Close() ch, err := conn.Channel() if err != nil { - panic(err) + log.Fatal(err) } defer ch.Close() @@ -37,7 +37,7 @@ func main() { nil, // arguments ) if err != nil { - panic(err) + log.Fatal(err) } handler := handler.NewHandler(ch, q.Name) diff --git a/src/rest-api/handler/handler.go b/src/rest-api/handler/handler.go index b5c3ae2..c904ff4 100644 --- a/src/rest-api/handler/handler.go +++ b/src/rest-api/handler/handler.go @@ -26,7 +26,7 @@ func NewHandler(ch *amqp.Channel, queueName string) *Handler { func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { bytes, err := io.ReadAll(io.Reader(r.Body)) if err != nil { - panic(err) + log.Fatal(err) } body := fmt.Sprint("Hello World!", r.RemoteAddr, string(bytes)) -- cgit 1.4.1