The Unified and Autonomous Development Platform
Adding helm charts and build script
Shamil Nunhuck482ba4036656
diff --git a/server-product/helm/.helmignore b/server-product/helm/.helmignorenew file mode 100644index 0000000000..0e8a0eb36f--- /dev/null+++ b/server-product/helm/.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/server-product/helm/Chart.yaml b/server-product/helm/Chart.yamlnew file mode 100644index 0000000000..73ac548cf8--- /dev/null+++ b/server-product/helm/Chart.yaml@@ -0,0 +1,6 @@+apiVersion: v2+name: onedev+description: All-In-One DevOps Platform+type: application+version: 0.0.11+appVersion: ${buildVersion}diff --git a/server-product/helm/build.sh b/server-product/helm/build.shnew file mode 100644index 0000000000..28a48f273d--- /dev/null+++ b/server-product/helm/build.sh@@ -0,0 +1,21 @@+#!/bin/bash++set -e++cd ../target++buildVersion=`ls onedev-*.zip|sed -e 's/onedev-\(.*\).zip/\1/'`++rm -rf helm-resources+cp -r ../helm helm-resources+rm helm-resources/build.sh++if [[ "$OSTYPE" == "darwin"* ]]; then+ find helm-resources -name "*.yaml" | xargs sed -i '' "s/\${buildVersion}/${buildVersion}/g"+else+ find helm-resources -name "*.yaml" | xargs sed -i -e "s/\${buildVersion}/${buildVersion}/g"+fi++zip -r helm-resources.zip helm-resources++diff --git a/server-product/helm/templates/NOTES.txt b/server-product/helm/templates/NOTES.txtnew file mode 100644index 0000000000..b94cf12b7e--- /dev/null+++ b/server-product/helm/templates/NOTES.txt@@ -0,0 +1,8 @@+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 }}+{{- end }}\ No newline at end of filediff --git a/server-product/helm/templates/_helpers.tpl b/server-product/helm/templates/_helpers.tplnew file mode 100644index 0000000000..b6008cde47--- /dev/null+++ b/server-product/helm/templates/_helpers.tpl@@ -0,0 +1,62 @@+{{/*+Expand the name of the chart.+*/}}+{{- define "onedev.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 "onedev.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 "onedev.chart" -}}+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Common labels+*/}}+{{- define "onedev.labels" -}}+helm.sh/chart: {{ include "onedev.chart" . }}+{{ include "onedev.selectorLabels" . }}+{{- if .Chart.AppVersion }}+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}+{{- end }}+app.kubernetes.io/managed-by: {{ .Release.Service }}+{{- end }}++{{/*+Selector labels+*/}}+{{- define "onedev.selectorLabels" -}}+app.kubernetes.io/name: {{ include "onedev.name" . }}+app.kubernetes.io/instance: {{ .Release.Name }}+{{- end }}++{{/*+Create the name of the service account to use+*/}}+{{- define "onedev.serviceAccountName" -}}+{{- if .Values.serviceAccount.create }}+{{- default (include "onedev.fullname" .) .Values.serviceAccount.name }}+{{- else }}+{{- default "default" .Values.serviceAccount.name }}+{{- end }}+{{- end }}diff --git a/server-product/helm/templates/cluster-role-bindings.yaml b/server-product/helm/templates/cluster-role-bindings.yamlnew file mode 100644index 0000000000..d08684b074--- /dev/null+++ b/server-product/helm/templates/cluster-role-bindings.yaml@@ -0,0 +1,15 @@+kind: ClusterRoleBinding+apiVersion: rbac.authorization.k8s.io/v1+metadata:+ name: onedev+subjects:+ - kind: ServiceAccount+ name: onedev+ namespace: onedev+ - kind: ServiceAccount+ name: deploy+ namespace: deploy+roleRef:+ kind: ClusterRole+ name: onedev+ apiGroup: rbac.authorization.k8s.iodiff --git a/server-product/helm/templates/cluster-roles.yaml b/server-product/helm/templates/cluster-roles.yamlnew file mode 100644index 0000000000..69bd3a7f65--- /dev/null+++ b/server-product/helm/templates/cluster-roles.yaml@@ -0,0 +1,20 @@+kind: ClusterRole+apiVersion: rbac.authorization.k8s.io/v1+metadata:+ name: onedev+rules:+ - apiGroups: [""]+ resources: ["namespaces"]+ verbs: ["get", "list", "create", "delete"] #require this permission to run builds in isolated namespaces+ - apiGroups: ["rbac.authorization.k8s.io"]+ resources: ["clusterrolebindings"]+ verbs: ["get", "list", "create", "delete"] #require this permission to bind cluster roles to service account of running builds+ - apiGroups: [""]+ resources: ["nodes"]+ verbs: ["get", "list", "patch"] #require this permission to label nodes with build cache properties to increase cache hit rate+ - apiGroups: [""]+ resources: ["services", "pods", "pods/log", "pods/exec", "secrets", "configmaps", "events"]+ verbs: ["get", "list", "watch", "create", "patch", "delete"] #require this permission to run builds as pods+ - apiGroups: ["apps"]+ resources: ["deployments"]+ verbs: ["get", "list", "create", "patch", "delete"] #require this permission to run builds as pods\ No newline at end of filediff --git a/server-product/helm/templates/deployment.yaml b/server-product/helm/templates/deployment.yamlnew file mode 100644index 0000000000..1a6339dc3c--- /dev/null+++ b/server-product/helm/templates/deployment.yaml@@ -0,0 +1,118 @@+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ .Release.Name }}-onedev+ labels:+ tier: server+ {{- include "onedev.labels" . | nindent 4 }}+spec:+ replicas: 1 # only allow one replicas as OneDev doesn't support clustering+ selector:+ matchLabels:+ tier: server+ app: onedev+ strategy:+ type: Recreate+ template:+ metadata:+ labels:+ tier: server+ app: onedev+ {{- with .Values.podAnnotations }}+ annotations:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ spec:+ serviceAccountName: onedev+ containers:+ - name: onedev+ resources:+ requests:+ memory: {{ .Values.resources.onedev.memory }}+ volumeMounts:+ - mountPath: "/opt/onedev"+ name: onedev+ image: "1dev/server:{{ .Values.image.tag | default .Chart.AppVersion }}"+ ports:+ - containerPort: 6610+ - containerPort: 6611+ env:+ - name: hibernate_dialect+ value: org.hibernate.dialect.MySQL5InnoDBDialect+ - name: hibernate_connection_driver_class+ value: com.mysql.cj.jdbc.Driver+ - name: hibernate_connection_url+ value: jdbc:mysql://{{ .Release.Name }}-mysql:3306/onedev?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false+ - name: hibernate_connection_username+ value: root+ - name: hibernate_connection_password+ valueFrom:+ secretKeyRef:+ name: {{.Release.Name}}-mysql+ key: password+ - name: hibernate_hikari_maximumPoolSize+ value: "25"+ initContainers:+ - name: init+ image: busybox+ command: ["sh", "-c", "until nslookup {{ .Release.Name }}-mysql.{{.Release.Namespace}}.svc.cluster.local; do echo waiting for mysql; sleep 2; done;"]+ volumes:+ - name: onedev+ persistentVolumeClaim:+ claimName: {{ .Release.Name }}-onedev++---+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ .Release.Name }}-mysql+ labels:+ tier: database+spec:+ selector:+ matchLabels:+ tier: database+ strategy:+ type: Recreate+ template:+ metadata:+ name: mysql+ labels:+ tier: database+ app: onedev+ spec:+ containers:+ - name: mysql+ image: mysql:5.7+ resources:+ requests:+ memory: {{ .Values.resources.mysql.memory }}+ args:+ - "--ignore-db-dir=lost+found"+ env:+ - name: MYSQL_DATABASE+ value: onedev+ - name: MYSQL_ROOT_PASSWORD+ valueFrom:+ secretKeyRef:+ name: {{.Release.Name}}-mysql+ key: password+ ports:+ - containerPort: 3306+ volumeMounts:+ - name: mysql+ mountPath: /var/lib/mysql+ readinessProbe:+ exec:+ command:+ - bash+ - "-c"+ - |+ mysql -uroot -p$MYSQL_ROOT_PASSWORD -e 'SELECT 1'+ initialDelaySeconds: 5+ periodSeconds: 2+ timeoutSeconds: 1+ volumes:+ - name: mysql+ persistentVolumeClaim:+ claimName: {{ .Release.Name }}-mysql\ No newline at end of filediff --git a/server-product/helm/templates/ingress.yaml b/server-product/helm/templates/ingress.yamlnew file mode 100644index 0000000000..c60f942915--- /dev/null+++ b/server-product/helm/templates/ingress.yaml@@ -0,0 +1,34 @@+{{- if .Values.ingress.enabled -}}+{{- $fullName := include "onedev.fullname" . -}}+{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}+apiVersion: networking.k8s.io/v1beta1+{{- else -}}+apiVersion: extensions/v1beta1+{{- end }}+kind: Ingress+metadata:+ name: {{ .Release.Name }}+spec:+ {{- 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 }}+ backend:+ serviceName: {{ template "onedev.fullname" $ }}-onedev+ servicePort: 80+ {{- end }}+ {{- end }}+ {{- end }}diff --git a/server-product/helm/templates/persistent-volume-claims.yaml b/server-product/helm/templates/persistent-volume-claims.yamlnew file mode 100644index 0000000000..9e6c071c8a--- /dev/null+++ b/server-product/helm/templates/persistent-volume-claims.yaml@@ -0,0 +1,37 @@+{{- $onedevPvc := lookup "v1" "PersistentVolumeClaim" .Release.Namespace "onedev" -}}+{{- if not $onedevPvc }}+apiVersion: v1+kind: PersistentVolumeClaim+metadata:+ annotations:+ "helm.sh/resource-policy": keep+ name: {{ .Release.Name }}-onedev+ labels:+ tier: server+spec:+ storageClassName: {{ .Values.volumes.onedev.storageClassName }}+ accessModes:+ - ReadWriteOnce+ resources:+ requests:+ storage: {{ .Values.volumes.onedev.size }}+ {{- end }}+---+{{- $mysqlPvc := lookup "v1" "PersistentVolumeClaim" .Release.Namespace "mysql" -}}+{{ if not $mysqlPvc }}+apiVersion: v1+kind: PersistentVolumeClaim+metadata:+ annotations:+ "helm.sh/resource-policy": keep+ name: {{ .Release.Name }}-mysql+ labels:+ tier: database+spec:+ storageClassName: {{ .Values.volumes.onedev.storageClassName }}+ accessModes:+ - ReadWriteOnce+ resources:+ requests:+ storage: {{ .Values.volumes.onedev.size }}+{{- end }}\ No newline at end of filediff --git a/server-product/helm/templates/secrets.yaml b/server-product/helm/templates/secrets.yamlnew file mode 100644index 0000000000..6b9f792862--- /dev/null+++ b/server-product/helm/templates/secrets.yaml@@ -0,0 +1,20 @@+{{- $secret_name := "{{.Release.Name}}-mysql" -}}++apiVersion: v1+kind: Secret+metadata:+ name: {{.Release.Name}}-mysql++data:+ # try to get the old secret+ # keep in mind, that a dry-run only returns an empty map+ {{- $old_sec := lookup "v1" "Secret" .Release.Namespace $secret_name }}++ # check, if a secret is already set+ {{- if or (not $old_sec) (not $old_sec.data) }}+ # if not set, then generate a new password+ password: {{ randAlphaNum 20 | b64enc }}+ {{ else }}+ # if set, then use the old value+ password: {{ index $old_sec.data "password" }}+ {{ end }}\ No newline at end of filediff --git a/server-product/helm/templates/service-accounts.yaml b/server-product/helm/templates/service-accounts.yamlnew file mode 100644index 0000000000..94919ff538--- /dev/null+++ b/server-product/helm/templates/service-accounts.yaml@@ -0,0 +1,4 @@+apiVersion: v1+kind: ServiceAccount+metadata:+ name: onedevdiff --git a/server-product/helm/templates/services.yaml b/server-product/helm/templates/services.yamlnew file mode 100644index 0000000000..d51ef55692--- /dev/null+++ b/server-product/helm/templates/services.yaml@@ -0,0 +1,33 @@+apiVersion: v1+kind: Service+metadata:+ name: {{ .Release.Name }}-onedev+ labels:+ tier: server+ app: ondev+spec:+ type: ClusterIP+ ports:+ - name: http+ port: 80+ targetPort: 6610+ protocol: TCP+ - name: ssh+ port: 22+ targetPort: 6611+ protocol: TCP+ selector:+ tier: server+---+apiVersion: v1+kind: Service+metadata:+ name: {{ .Release.Name }}-mysql+ labels:+ tier: database+ app: onedev+spec:+ ports:+ - port: 3306+ selector:+ tier: databasediff --git a/server-product/helm/values.yaml b/server-product/helm/values.yamlnew file mode 100644index 0000000000..085f4f0719--- /dev/null+++ b/server-product/helm/values.yaml@@ -0,0 +1,30 @@+image:+ repository:+ pullPolicy: IfNotPresent+ tag: ${buildVersion}++ingress:+ enabled: false+ annotations: {}+ hosts:+ - host: chart-example.local+ paths: []+ tls: []+ # - secretName: chart-example-tls+ # hosts:+ # - chart-example.local+++volumes:+ onedev:+ storageClassName: openebs-hostpath+ size: 100Gi+ mysql:+ storageClassName: openebs-hostpath+ size: 20Gi++resources:+ onedev:+ memory: 2Gi+ mysql:+ memory: 500Mi