Skip to content

Commit

Permalink
Helm charts for ArgoCD (#17)
Browse files Browse the repository at this point in the history
* chore: Update docker push command and Dockerfile labels
  - Update docker push command in Taskfile.dist.yml to push all tags to the registry.
  - Remove unnecessary labels and update the description in the Dockerfile.
* chore: add Helm chart for Kubernetes deployment
  - Add .helmignore file to specify patterns to ignore during package building.
  - Create Helm Chart files: Chart.yaml, _helpers.tpl, deployment.yaml, secret.yaml, and values.yaml.
  - Define default values for Helm deployment, including replica count, service port, image details, and security context.
* ci(sec): Add codacy config
* feat: Helm charts for Argo
  • Loading branch information
Searge committed Nov 13, 2023
1 parent 15a44b1 commit fdd872f
Show file tree
Hide file tree
Showing 19 changed files with 327 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
languages:
go:
enabled: true
extensions:
- "gosec"
- "staticcheck"
exclude_paths:
- ".bundle/**"
2 changes: 1 addition & 1 deletion Taskfile.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ tasks:
dir: "{{.USER_WORKING_DIR}}/docker/{{.Version}}"
cmds:
- >
docker push ${REGISTRY_NAME}:{{.Tag}}
docker push --all-tags ${REGISTRY_NAME}
- echo "Pushed ${REGISTRY_NAME}:{{.Tag}}"
11 changes: 7 additions & 4 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
FROM quay.io/projectquay/golang:1.20 as builder

LABEL org.opencontainers.image.source=https://github.com/geekopsua/geekbot
LABEL org.opencontainers.image.description DESCRIPTION="Kubernetes Bot for Telegram"
LABEL org.opencontainers.image.licenses Apache-2.0

ARG CGO_ENABLED
ARG TARGET_OS
ARG TARGET_ARCH
Expand All @@ -16,6 +12,13 @@ RUN go install github.com/go-task/task/v3/cmd/task@latest \
&& task install && task build

FROM scratch

LABEL org.opencontainers.image.title="GeekBot"
LABEL org.opencontainers.image.description DESCRIPTION="Kubernetes Bot for Telegram"
LABEL org.opencontainers.image.source=https://github.com/geekopsua/geekbot
LABEL org.opencontainers.image.vendor="GeekOps"
LABEL org.opencontainers.image.licenses Apache-2.0

WORKDIR /
COPY --from=builder /go/src/app/build/package/geekbot-* ./geekbot
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Expand Down
Empty file added deploy/.gitignore
Empty file.
23 changes: 23 additions & 0 deletions deploy/argo-cd/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
7 changes: 7 additions & 0 deletions deploy/argo-cd/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: argo-cd
version: 1.0.0
dependencies:
- name: argo-cd
version: 5.46.8
repository: https://argoproj.github.io/argo-helm
10 changes: 10 additions & 0 deletions deploy/argo-cd/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
argo-cd:
dex:
enabled: false
notifications:
enabled: false
applicationSet:
enabled: false
server:
extraArgs:
- --insecure
23 changes: 23 additions & 0 deletions deploy/geekbot/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
12 changes: 12 additions & 0 deletions deploy/geekbot/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v2
name: geekbot
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "0.0.1"

dependencies:
- name: mariadb
version: 13.1.3
repository: oci://registry-1.docker.io/bitnamicharts
condition: mariadb.enabled
62 changes: 62 additions & 0 deletions deploy/geekbot/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "helm.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 "helm.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 "helm.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "helm.labels" -}}
helm.sh/chart: {{ include "helm.chart" . }}
{{ include "helm.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

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

{{/*
Create the name of the service account to use
*/}}
{{- define "helm.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "helm.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
61 changes: 61 additions & 0 deletions deploy/geekbot/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "deploy.fullname" . }}
labels:
{{- include "deploy.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "deploy.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "deploy.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "deploy.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 }}
7 changes: 7 additions & 0 deletions deploy/geekbot/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.secret.name }}
type: Opaque
data:
token: {{ .Values.secret.key | b64enc | quote }}
18 changes: 18 additions & 0 deletions deploy/geekbot/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Default values for helm.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1
service:
port: 80
image:
registry: "ghcr.io/geekopsua/geekbot"
tag: "latest"
os: "linux"
arch: "amd64"
secret:
name: "kbot"
tokenKey: token
tokenName: TELE_TOKEN
securityContext:
privileged: true
23 changes: 23 additions & 0 deletions deploy/root-app/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
5 changes: 5 additions & 0 deletions deploy/root-app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: root-app
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
18 changes: 18 additions & 0 deletions deploy/root-app/templates/argo-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argo-cd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/geekopsua/geekbot.git
path: deploy/argo-cd
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
selfHeal: true
23 changes: 23 additions & 0 deletions deploy/root-app/templates/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: prometheus
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://prometheus-community.github.io/helm-charts
chart: prometheus
targetRevision: 25.3.1
helm:
values: |
pushgateway:
enabled: false
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true
18 changes: 18 additions & 0 deletions deploy/root-app/templates/root-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: root-app
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/geekopsua/geekbot.git
path: deploy/root-app
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
selfHeal: true
Empty file added deploy/root-app/values.yaml
Empty file.

0 comments on commit fdd872f

Please sign in to comment.