Skip to content

Commit

Permalink
Merge pull request #1 from enzops/main
Browse files Browse the repository at this point in the history
Add CI and Helm Charts
  • Loading branch information
Kaysoro authored Dec 5, 2024
2 parents eaf9636 + 5e4db80 commit d0e624c
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 1 deletion.
61 changes: 60 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,72 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set Docker image tag
id: set-tag
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
else
echo "tag_name=${GITHUB_SHA}" >> $GITHUB_ENV
fi
- name: Build and push Docker images
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
ghcr.io/${{ github.repository }}:${{ env.tag_name }}
cache-from: type=gha
cache-to: type=gha,mode=max

deploy-helm:
runs-on: ubuntu-latest
needs: [docker_build]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Kubernetes context
run: |
mkdir -p ${HOME}/.kube
echo "${{ secrets.KUBECONFIG }}" > ${HOME}/.kube/config
- name: Install Helm
uses: azure/setup-helm@v4

- name: Set image tag
id: set-image-tag
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "image_tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
else
echo "image_tag_name=${GITHUB_SHA}" >> $GITHUB_ENV
fi
- name: Deploy Helm Chart
run: |
helm upgrade --install ${{ github.event.repository.name }} charts/${{ github.event.repository.name }} \
--namespace kaellybot \
--create-namespace \
--set image.tag="${{ env.image_tag_name }}" \
--set secrets.MYSQL_URL="${{ secrets.MYSQL_URL }}" \
--set secrets.MYSQL_USER="${{ secrets.MYSQL_USER }}" \
--set secrets.MYSQL_PASSWORD="${{ secrets.MYSQL_PASSWORD }}" \
--set secrets.MYSQL_DATABASE="${{ secrets.MYSQL_DATABASE }}" \
--set secrets.RABBITMQ_ADDRESS="${{ secrets.RABBITMQ_ADDRESS }}" \
--set secrets.REDIS_URL="${{ secrets.REDIS_URL }}" \
--set secrets.REDIS_USER="${{ secrets.REDIS_USER }}" \
--set secrets.REDIS_PASSWORD="${{ secrets.REDIS_PASSWORD }}" \
--set configMap.REDIS_CACHE_RETENTION="${{ secrets.REDIS_CACHE_RETENTION }}" \
--set configMap.REDIS_CACHE_SIZE="${{ secrets.REDIS_PASSWORD }}" \
--set configMap.ALMANAX_CRON_TAB="${{ secrets.ALMANAX_CRON_TAB }}" \
--set configMap.UPDATE_SET_CRON_TAB="${{ secrets.UPDATE_SET_CRON_TAB }}" \
--set configMap.HTTP_TIMEOUT="${{ secrets.HTTP_TIMEOUT }}" \
--set configMap.PROBE_PORT="${{ secrets.PROBE_PORT }}" \
--set configMap.METRIC_PORT="${{ secrets.METRIC_PORT }}" \
--set configMap.LOG_LEVEL="${{ secrets.LOG_LEVEL }}" \
--set-string configMap.PRODUCTION="${{ secrets.PRODUCTION }}"
23 changes: 23 additions & 0 deletions charts/kaelly-encyclopedia/.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/
24 changes: 24 additions & 0 deletions charts/kaelly-encyclopedia/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: kaelly-encyclopedia
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.0"
62 changes: 62 additions & 0 deletions charts/kaelly-encyclopedia/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "kaelly-encyclopedia.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 "kaelly-encyclopedia.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 "kaelly-encyclopedia.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "kaelly-encyclopedia.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "kaelly-encyclopedia.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/kaelly-encyclopedia/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
namespace: {{ .Release.Namespace }}
data:
{{- if .Values.configMap }}
{{- range $key, $value := .Values.configMap }}
{{ $key }}: "{{ $value }}"
{{- end }}
{{- else }}
{{- end }}
60 changes: 60 additions & 0 deletions charts/kaelly-encyclopedia/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "kaelly-encyclopedia.fullname" . }}
labels:
{{- include "kaelly-encyclopedia.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "kaelly-encyclopedia.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "kaelly-encyclopedia.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
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 }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-configmap
- secretRef:
name: {{ .Release.Name }}-secrets
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
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 }}
13 changes: 13 additions & 0 deletions charts/kaelly-encyclopedia/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-secrets
namespace: {{ .Release.Namespace }}
type: Opaque
data:
{{- if .Values.secrets }}
{{- range $key, $value := .Values.secrets }}
{{ $key }}: {{ $value | b64enc }}
{{- end }}
{{- else }}
{{- end }}
97 changes: 97 additions & 0 deletions charts/kaelly-encyclopedia/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Default values for kaelly-encyclopedia.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/
replicaCount: 1

# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
image:
repository: ghcr.io/kaellybot/kaelly-encyclopedia
# This sets the pull policy for images.
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""

# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: []
# This is to override the chart name.
nameOverride: ""
fullnameOverride: ""

# This is for setting Kubernetes Annotations to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
podAnnotations: {}
# This is for setting Kubernetes Labels to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
podLabels: {}

podSecurityContext:
{}
# fsGroup: 2000

securityContext:
{}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

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: 512Mi
requests:
# cpu: 100m
memory: 128Mi

# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
livenessProbe:
httpGet:
path: /live
port: 9090
readinessProbe:
httpGet:
path: /ready
port: 9090

#This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

configMap:
REDIS_CACHE_RETENTION: "60m"
REDIS_CACHE_SIZE: "1000"
ALMANAX_CRON_TAB: "1 0 0 * * *"
UPDATE_SET_CRON_TAB: "0 0 2 * * *"
HTTP_TIMEOUT: "10s"
PROBE_PORT: "9090"
METRIC_PORT: "2112"
LOG_LEVEL: "info"
PRODUCTION: "false"

secrets:
MYSQL_URL: ""
MYSQL_USER: ""
MYSQL_PASSWORD: ""
MYSQL_DATABASE: ""
RABBITMQ_ADDRESS: ""
REDIS_URL: ""
REDIS_USER: ""
REDIS_PASSWORD: ""

0 comments on commit d0e624c

Please sign in to comment.