Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add quick helm deploy command #223

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ VERSION ?= 0.0.0
SERVICE_PORT ?= 3000
DOCKER_REGISTRY ?= docker.io/tosone
DOCKER_PLATFORMS ?= linux/amd64,linux/arm64

APPNAME ?= sigma
NAMESPACE ?= sigma
KUBECONFIG ?= ~/.kube/config
REPOSITORY ?= ghcr.io/go-sigma/sigma
TAG ?= nightly-alpine
MIGRATION_NAME ?=
RANDOM_PASSWORD := $(shell openssl rand -base64 6 | tr -d '/+' | tr '[:upper:]' '[:lower:]' | head -c 8)

SHELL := /bin/bash

Expand Down Expand Up @@ -110,6 +115,24 @@ addlicense: ## Add license to all go files
@find web/src -type f -name "*.ts" | xargs addlicense -l apache -y 2023 -c "sigma"
@find web/src -type f -name "*.css" | xargs addlicense -l apache -y 2023 -c "sigma"

## Kube:
kube_deploy: ## Deploy sigma on k8s using helm
@if [ -z $(KUBECONFIG) ]; then \
KUBECONFIG=$$HOME/.kube/config; \
fi;
@helm upgrade --install $(APPNAME) ./deploy/sigma --create-namespace --namespace $(NAMESPACE) \
--set image.repository=$(REPOSITORY) \
--set image.tag=$(TAG) \
--set mysql.auth.rootPassword=$(RANDOM_PASSWORD) \
--set mysql.auth.password=$(RANDOM_PASSWORD) \
--set redis.auth.password=$(RANDOM_PASSWORD) \
--set minio.secretKey=$(RANDOM_PASSWORD) \
--kubeconfig $(KUBECONFIG)

kube_undeploy: ## Uninstall sigma on k8s using helm
@KUBECONFIG=$(KUBECONFIG)
@helm uninstall $(APPNAME) -n$(NAMESPACE)

## Help:
help: ## Show this help.
@echo ''
Expand All @@ -120,4 +143,4 @@ help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-30s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)
}' $(MAKEFILE_LIST)
29 changes: 29 additions & 0 deletions deploy/sigma/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Create chart name and version as used by the chart label.
{{/*
Common labels
*/}}

{{- define "sigma.labels" -}}
helm.sh/chart: {{ include "sigma.chart" . }}
{{ include "sigma.selectorLabels" . }}
Expand All @@ -42,10 +43,38 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{- define "sigma.server.labels" -}}
app.kubernetes.io/name: {{ template "sigma.server" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "sigma.worker.labels" -}}
app.kubernetes.io/name: {{ template "sigma.worker" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "sigma.distribution.labels" -}}
app.kubernetes.io/name: {{ template "sigma.distribution" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}


{{/*
Selector labels
*/}}
{{- define "sigma.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sigma.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "sigma.server" -}}
{{- printf "%s-server" (include "common.names.fullname" .) -}}
{{- end -}}

{{- define "sigma.worker" -}}
{{- printf "%s-worker" (include "common.names.fullname" .) -}}
{{- end -}}

{{- define "sigma.distribution" -}}
{{- printf "%s-distribution" (include "common.names.fullname" .) -}}
{{- end -}}
28 changes: 15 additions & 13 deletions deploy/sigma/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ data:
path: {{ .Chart.Name }}.db
mysql:
host: {{ .Release.Name }}-mysql
port: 3306
user: sigma
password: sigma
port: {{ .Values.mysql.primary.service.ports.mysql }}
user: {{ .Values.mysql.auth.username }}
password: {{ .Values.mysql.auth.password }}
dbname: sigma
postgresql:
host: localhost
host: {{ .Release.Name }}-postgresql
port: 5432
user: sigma
password: sigma
dbname: sigma
sslmode: disable
redis:
url: redis://:sigma@{{ .Release.Name }}-redis-master:6379/0
url: redis://:{{ .Values.redis.auth.password }}@{{ .Release.Name }}-redis-master:{{ .Values.redis.master.service.ports.redis }}/0
http:
server: 0.0.0.0:3000
worker: 0.0.0.0:3001
server: 0.0.0.0:{{.Values.service.server.port}}
worker: 0.0.0.0:{{.Values.service.worker.port}}
daemon:
gc:
# if blob not associate with artifact
Expand All @@ -44,11 +44,13 @@ data:
filesystem:
path: /
s3:
ak: sigma
sk: sigma-sigma
endpoint: http://{{ .Release.Name }}-minio:9000
ak: {{ .Values.minio.accessKey }}
sk: {{ .Values.minio.secretKey }}
endpoint: http://{{ .Release.Name }}-minio:{{ .Values.minio.service.port }}
region: cn-north-1
bucket: sigma
{{- range .Values.minio.buckets }}
bucket: {{ .name | quote }}
{{end}}
forcePathStyle: true
proxy:
enabled: true
Expand All @@ -64,7 +66,7 @@ data:
password: internal-sigma
admin:
username: sigma
password: sigma
password: {{ randAlphaNum 8 | b64enc | trunc 8 }}
token:
realm: ""
service: ""
Expand All @@ -75,4 +77,4 @@ data:
{{- else if eq .Values.middleware.type "external" }}
sigma.yaml: |-
{{ .Values.config | toYaml | nindent 4 }}
{{- end }}
{{- end }}
71 changes: 71 additions & 0 deletions deploy/sigma/templates/distribution/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sigma.distribution" . }}
labels:
{{- include "sigma.distribution.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "sigma.distribution.labels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "sigma.distribution.labels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ printf "%s-distribution" .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- distribution
ports:
- name: http
containerPort: {{ .Values.service.distribution.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /
port: {{ .Values.service.distribution.port }}
readinessProbe:
httpGet:
path: /
port: {{ .Values.service.distribution.port }}
volumeMounts:
- name: "config"
mountPath: "/etc/sigma/config.yaml"
subPath: "config.yaml"
readOnly: true
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: "config"
configMap:
name: {{ printf "%s-configmap" .Chart.Name }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
28 changes: 28 additions & 0 deletions deploy/sigma/templates/distribution/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "sigma.distribution" . }}
labels:
{{- include "sigma.distribution.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "sigma.distribution" . }}
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 }}
15 changes: 15 additions & 0 deletions deploy/sigma/templates/distribution/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "sigma.distribution" . }}
labels:
{{- include "sigma.distribution.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.distribution.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "sigma.distribution.labels" . | nindent 4 }}
33 changes: 8 additions & 25 deletions deploy/sigma/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "sigma.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 -}}
{{- $releaseName := .Release.Name -}}
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 }}
Expand All @@ -37,25 +26,19 @@ spec:
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .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 }}
name: {{ $releaseName }}-{{ .svcName }}
{{/* name: {{- printf "%s-%s" $releaseName .svcName -}}*/}}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
number: {{ .svcPort }}
{{- end }}
{{- end }}
{{- end }}
Loading
Loading