Skip to content

Commit

Permalink
Merge pull request 2i2c-org#16 from GeorgianaElena/helm-chart
Browse files Browse the repository at this point in the history
Create a helm chart for this project
  • Loading branch information
GeorgianaElena authored Aug 22, 2024
2 parents 593cb5f + 14b34d7 commit cecae08
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ repos:
hooks:
- id: black

# Autoformat: markdown, yaml
# Autoformat: markdown, yaml (but not helm templates)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
# Don't run prettier on our jinja2 template files. We run djlint instead
exclude: "kubespawner/templates/.*\\.html"
exclude: helm-chart/templates/.*

# Misc...
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM python:3.12.5-slim-bullseye

RUN apt-get update && apt-get install -y git

RUN pip3 install gunicorn

RUN git clone https://github.com/2i2c-org/unnamed-thingity-thing /opt
WORKDIR /opt
RUN mkdir /opt/unnamed-thingity-thing

COPY . /opt/unnamed-thingity-thing

WORKDIR /opt/unnamed-thingity-thing

RUN pip3 install -r requirements.txt
23 changes: 23 additions & 0 deletions helm-chart/.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 helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: unnamed
description: A Helm chart for Kubernetes
version: 0.1.0
appVersion: "1.16.0"
51 changes: 51 additions & 0 deletions helm-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "unnamed.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 "unnamed.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 "unnamed.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "unnamed.selectorLabels" -}}
app.kubernetes.io/name: {{ include "unnamed.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
56 changes: 56 additions & 0 deletions helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "unnamed.fullname" . }}
labels:
{{- include "unnamed.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "unnamed.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "unnamed.selectorLabels" . | nindent 8 }}
spec:
initContainers:
- name: db-migrate
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- python
- ./comptest/manage.py
- migrate
securityContext:
runAsUser: 0
volumeMounts:
- name: db
mountPath: /mnt
readOnly: false
containers:
- name: run-app
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
workingDir: /opt/unnamed-thingity-thing/comptest
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
command:
- gunicorn
- comptest.wsgi
securityContext:
runAsUser: 0
volumeMounts:
- name: db
mountPath: /mnt
readOnly: false
volumes:
- name: db
persistentVolumeClaim:
claimName: db-pvc
35 changes: 35 additions & 0 deletions helm-chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "unnamed.fullname" . }}
labels:
{{- include "unnamed.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- . | toYaml | nindent 4 }}
{{- end }}
spec:
{{- with .Values.ingress.ingressClassName }}
ingressClassName: "{{ . }}"
{{- end }}
rules:
{{- range $host := .Values.ingress.hosts | default (list "") }}
- http:
paths:
- path: {{ $.Values.ingress.path }}
pathType: {{ $.Values.ingress.pathType }}
backend:
service:
name: {{ include "unnamed.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- if $host }}
host: {{ $host | quote }}
{{- end }}
{{- end }}
{{- with .Values.ingress.tls }}
tls:
{{- . | toYaml | nindent 4 }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions helm-chart/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: db-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
# To be updated with the actual storage size
storage: 1Gi
14 changes: 14 additions & 0 deletions helm-chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "unnamed.fullname" . }}
labels:
{{- include "unnamed.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- name: http
port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
selector: {{ include "unnamed.selectorLabels" . | nindent 4 }}
41 changes: 41 additions & 0 deletions helm-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Default values for helm-chart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: "unnamed"
tag: "1.0.1"
pullPolicy: IfNotPresent

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}

podSecurityContext: {}

securityContext: {}

service:
type: ClusterIP
port: 8000

ingress:
enabled: false
className: nginx
annotations: {}
hosts: []
path: /
pathType: Prefix
tls: []

resources: {}

nodeSelector: {}

tolerations: []

affinity: {}

0 comments on commit cecae08

Please sign in to comment.