feat: add TeamCity to CI module

This commit is contained in:
Stefan Reimer 2021-12-03 22:14:11 +01:00
parent 6b868907af
commit 525bbb3dbb
10 changed files with 357 additions and 0 deletions

View File

@ -0,0 +1,18 @@
apiVersion: v2
name: teamcity
description: A Helm chart to install a simple TeamCity installation
type: application
version: 0.1.0
appVersion: "2021.2"
home: https://kubezero.com
icon: https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png
keywords:
- kubezero
- teamcity
maintainers:
- name: Quarky9
dependencies:
- name: kubezero-lib
version: ">= 0.1.4"
repository: https://cdn.zero-downtime.net/charts/
kubeVersion: ">= 1.18.0"

View File

@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "teamcity.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 "teamcity.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 "teamcity.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "teamcity.labels" -}}
helm.sh/chart: {{ include "teamcity.chart" . }}
{{ include "teamcity.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "teamcity.selectorLabels" -}}
app.kubernetes.io/name: {{ include "teamcity.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "teamcity.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "teamcity.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "teamcity.fullname" . }}-agent
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.agentReplicaCount }}
selector:
matchLabels:
app.kubernetes.io/instance: teamcity-agent
app.kubernetes.io/name: teamcity
template:
metadata:
labels:
app.kubernetes.io/instance: teamcity-agent
app.kubernetes.io/name: teamcity
spec:
# serviceAccountName: {{ include "teamcity.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: "{{ .Chart.Name }}-agent"
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
image: "{{ .Values.image.agent.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: SERVER_URL
value: "{{ include "teamcity.fullname" . }}:8111"
resources:
{{- toYaml .Values.resources | nindent 10 }}
volumeMounts:
- name: teamcity-config
mountPath: /data/teamcity_agent/conf
volumes:
- name: teamcity-config
emptyDir: {}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end -}}

View File

@ -0,0 +1,18 @@
{{- if .Values.istio.enabled }}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: {{ include "kubezero-lib.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
gateways:
- {{ .Values.istio.gateway }}
hosts:
- {{ .Values.istio.url }}
http:
- route:
- destination:
host: {{ include "teamcity.fullname" . }}
{{- end }}

View File

@ -0,0 +1,28 @@
{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "teamcity.fullname" . }}-manage-agents
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["list", "get"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "create", "list", "delete"]
- apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["list", "get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "teamcity.fullname" . }}-manage-agents
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "teamcity.fullname" . }}-manage-agents
subjects:
- kind: ServiceAccount
name: {{ include "teamcity.serviceAccountName" . }}
{{- end }}

View File

@ -0,0 +1,33 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "teamcity.fullname" . }}-data
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
{{- if .Values.pvc.data.storageClass }}
storageClassName: {{ .Values.pvc.data.storageClass }}
{{- end }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.pvc.data.storageSize }}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "teamcity.fullname" . }}-logs
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
{{- if .Values.pvc.logs.storageClass }}
storageClassName: {{ .Values.pvc.logs.storageClass }}
{{- end }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.pvc.logs.storageSize }}

View File

@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "teamcity.fullname" . }}
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "kubezero-lib.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "kubezero-lib.labels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "teamcity.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
image: "{{ .Values.image.server.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: app
containerPort: 8111
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: teamcity-data
mountPath: /data/teamcity_server/datadir
- name: teamcity-logs
mountPath: /opt/teamcity/logs
volumes:
- name: teamcity-data
{{- if .Values.pvc.data }}
persistentVolumeClaim:
claimName: {{ include "teamcity.fullname" . }}-data
{{- else }}
emptyDir: {}
{{- end }}
- name: teamcity-logs
{{- if .Values.pvc.logs }}
persistentVolumeClaim:
claimName: {{ include "teamcity.fullname" . }}-logs
{{- else }}
emptyDir: {}
{{- end -}}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end -}}

View File

@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: "{{ include "teamcity.fullname" . }}"
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
protocol: TCP
targetPort: app
name: app
selector:
{{- include "kubezero-lib.selectorLabels" . | nindent 4 }}
sessionAffinity: None

View File

@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "teamcity.serviceAccountName" . }}
labels:
{{- include "kubezero-lib.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,57 @@
# Default values for teamcity.
agentReplicaCount: 0
image:
server:
repository: jetbrains/teamcity-server
agent:
repository: jetbrains/teamcity-agent
tag: ""
pullPolicy: IfNotPresent
pvc:
data:
#storageClass: default
storageSize: 4Gi
logs:
#storageClass: default
storageSize: 1Gi
serviceAccount:
create: true
annotations: {}
name: ""
rbac:
create: true
podAnnotations: {}
podSecurityContext:
fsGroup: 1000
securityContext: {}
service:
type: ClusterIP
port: 8111
istio:
enabled: false
gateway: istio-ingress/private-ingressgateway
url: "" # tc.example.com
resources: {}
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}