about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2024-05-25 13:31:29 +0200
committerBaitinq <manuelpalenzuelamerino@gmail.com>2024-05-25 14:06:15 +0200
commit95d0076060f945f9096f00d60c192cdbdcb611ca (patch)
tree3a8f83de5c5ac3c2a6d1dc33d9398a7761964028
parentrest-api: deploy with bazel (diff)
downloadfs-tracer-backend-95d0076060f945f9096f00d60c192cdbdcb611ca.tar.gz
fs-tracer-backend-95d0076060f945f9096f00d60c192cdbdcb611ca.tar.bz2
fs-tracer-backend-95d0076060f945f9096f00d60c192cdbdcb611ca.zip
payload-processor: deploy with bazel
-rw-r--r--.bazelrc5
-rw-r--r--README.md2
-rwxr-xr-xdeploy.sh4
-rw-r--r--k8s/payload-processor/BUILD.bazel14
-rw-r--r--k8s/payload-processor/templates/deployment.yaml5
-rw-r--r--k8s/payload-processor/templates/serviceaccount.yaml12
-rw-r--r--k8s/payload-processor/values.yaml47
-rw-r--r--k8s/rest-api/README.md1
-rw-r--r--src/payload-processor/cmd/BUILD.bazel21
9 files changed, 42 insertions, 69 deletions
diff --git a/.bazelrc b/.bazelrc
index 00dcbce..df36b17 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1,3 +1,6 @@
 common --experimental_enable_bzlmod
 
-build --workspace_status_command="echo STABLE_GIT_SHA $(git rev-parse --short HEAD)"
+build --workspace_status_command='sh -c "\
+echo STABLE_GIT_SHA $(git rev-parse --short HEAD); \
+echo DB_PASSWORD $DB_PASSWORD \
+"'
diff --git a/README.md b/README.md
index 69d8278..022a219 100644
--- a/README.md
+++ b/README.md
@@ -3,4 +3,4 @@ install helmsman
 
 COMMIT_SHA=$(git rev-parse --short HEAD) helmsman --apply -f k8s/helmsman.yml
 
-to deploy, execute the ./deploy.sh script
+to deploy, execute the ./deploy.sh script (and have the correct env variables)
diff --git a/deploy.sh b/deploy.sh
index bd4b573..58fce0e 100755
--- a/deploy.sh
+++ b/deploy.sh
@@ -1,6 +1,4 @@
 #!/bin/sh
 
 bazel run //k8s/rest-api:chart.upgrade
-
-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)" --set db.password=$DB_PASSWORD k8s/payload-processor
+bazel run //k8s/payload-processor:chart.upgrade
diff --git a/k8s/payload-processor/BUILD.bazel b/k8s/payload-processor/BUILD.bazel
new file mode 100644
index 0000000..a2f1fbb
--- /dev/null
+++ b/k8s/payload-processor/BUILD.bazel
@@ -0,0 +1,14 @@
+load("@rules_helm//helm:defs.bzl", "helm_chart")
+
+helm_chart(
+    name = "chart",
+    chart = "Chart.yaml",
+    images = ["//src/payload-processor/cmd:push"],
+    install_name = "payload-processor",
+    stamp = 1,
+    substitutions = {
+        "IMAGE_TAG": "payload-processor-{STABLE_GIT_SHA}",
+        "DB_PASSWORD": "{DB_PASSWORD}"
+    },
+    values = "values.yaml",
+)
diff --git a/k8s/payload-processor/templates/deployment.yaml b/k8s/payload-processor/templates/deployment.yaml
index 6ab4c90..2ffd225 100644
--- a/k8s/payload-processor/templates/deployment.yaml
+++ b/k8s/payload-processor/templates/deployment.yaml
@@ -5,9 +5,7 @@ metadata:
   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 }}
@@ -24,12 +22,11 @@ spec:
       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 }}"
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
           imagePullPolicy: {{ .Values.image.pullPolicy }}
           resources:
             {{- toYaml .Values.resources | nindent 12 }}
diff --git a/k8s/payload-processor/templates/serviceaccount.yaml b/k8s/payload-processor/templates/serviceaccount.yaml
deleted file mode 100644
index 55e048e..0000000
--- a/k8s/payload-processor/templates/serviceaccount.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-{{- 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
index a245901..77355e5 100644
--- a/k8s/payload-processor/values.yaml
+++ b/k8s/payload-processor/values.yaml
@@ -2,53 +2,16 @@
 # This is a YAML-formatted file.
 # Declare variables to be passed into your templates.
 
+# NOTE: This string "@@//src/payload-processor/cmd:push" needs to be present
+# in order to limtations of the helm_rules bazel package
+
 replicaCount: 1
 
 db:
-  password: ""
+  password: "{DB_PASSWORD}"
 
 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: {}
+  tag: "{IMAGE_TAG}"
diff --git a/k8s/rest-api/README.md b/k8s/rest-api/README.md
deleted file mode 100644
index 4381b6f..0000000
--- a/k8s/rest-api/README.md
+++ /dev/null
@@ -1 +0,0 @@
-helm upgrade rest-api --set image.tag=$(git rev-parse --short HEAD) .
diff --git a/src/payload-processor/cmd/BUILD.bazel b/src/payload-processor/cmd/BUILD.bazel
index 7c89231..9a5fdb7 100644
--- a/src/payload-processor/cmd/BUILD.bazel
+++ b/src/payload-processor/cmd/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
 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")
@@ -16,6 +17,12 @@ go_library(
     ],
 )
 
+go_binary(
+    name = "cmd",
+    embed = [":cmd_lib"],
+    visibility = ["//visibility:public"],
+)
+
 go_cross_binary(
     name = "cmd_arm64",
     platform = "@io_bazel_rules_go//go/toolchain:linux_arm64",
@@ -43,14 +50,18 @@ oci_tarball(
     repo_tags = [],
 )
 
+expand_template(
+    name = "stamped",
+    out = "_stamped.tags.txt",
+    stamp = 1,
+    stamp_substitutions = {"tag": "payload-processor-{{STABLE_GIT_SHA}}"},
+    template = ["tag"],
+)
+
 oci_push(
     name = "push",
     image = ":image",
+    remote_tags = ":stamped",
     repository = "docker.io/baitinq/fs-tracer",
-)
-
-go_binary(
-    name = "cmd",
-    embed = [":cmd_lib"],
     visibility = ["//visibility:public"],
 )