Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Action with helm #32

Merged
merged 15 commits into from
Apr 11, 2024
52 changes: 52 additions & 0 deletions .github/actions/deploy/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy to Etimo Kubernetes
description: Deploy to Etimo Kubernetes

inputs:
image:
description: The image to deploy
required: true
tag:
description: The tag of the image to deploy
required: true
namespace:
description: The namespace to deploy to
required: true
cluster:
description: The cluster to deploy to
required: true
name:
description: The name of the deployment
required: true
ingress:
description: Whether to create an ingress for the deployment
required: false
default: "false"
private:
description: Whether the ingress is private
required: false
default: "false"
targetPort:
description: The target port for the ingress and the port that the deployment listens on
required: false
kubeconfig:
description: The kubeconfig to use
required: true

runs:
using: composite
steps:
- name: Deploy
uses: WyriHaximus/github-action-helm3@v3
with:
exec: |
helm upgrade ${{ inputs.name }} ./helm/app --kube-context=etimo-staging \
--install --atomic --namespace=${{ inputs.namespace }} \
--debug \
--set global.name=${{ inputs.name }} \
--set global.author=${{ github.actor }} \
--set app.deployment.image.name=${{ inputs.image }} \
--set app.deployment.image.tag=${{ inputs.tag }} \
--set app.ingress.enabled="${{ inputs.ingress }}" \
--set app.deployment.port="${{ inputs.targetPort }}" \
kubeconfig: '${{ inputs.kubeconfig }}'
overrule_existing_kubeconfig: "true"
23 changes: 23 additions & 0 deletions helm/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/
24 changes: 24 additions & 0 deletions helm/app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: app
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: 0.1.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.16.0"
4 changes: 4 additions & 0 deletions helm/app/charts/app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
name: app
version: 1.0.0
description: A Helm chart for an application
49 changes: 49 additions & 0 deletions helm/app/charts/app/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.global.name }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ .Values.global.name }}
helm.sh/chart: {{ include "app.chart" . }}
app.kubernetes.io/instance: {{ .Values.global.name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ .Values.global.name }}
app.kubernetes.io/instance: {{ .Values.global.name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ .Values.global.name }}
app.kubernetes.io/instance: {{ .Values.global.name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.deployment.image.name }}:{{ tpl .Values.deployment.image.tag $ }}"
imagePullPolicy: {{ .Values.deployment.image.pullPolicy }}
{{- if .Values.deployment.port }}
ports:
- name: http
containerPort: {{ .Values.deployment.port }}
protocol: TCP
{{- end }}
resources:
requests:
cpu: 0.1
memory: 64Mi
limits:
cpu: 0.1
memory: 128Mi
{{- if .Values.deployment.restartPolicy }}
restartPolicy: {{ .Values.deployment.restartPolicy }}
{{- end }}
{{- if .Values.deployment.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.deployment.terminationGracePeriodSeconds }}
{{- end }}
revisionHistoryLimit: 3
{{- if .Values.deployment.progressDeadlineSeconds }}
progressDeadlineSeconds: {{ .Values.deployment.progressDeadlineSeconds }}
{{- end }}
23 changes: 23 additions & 0 deletions helm/app/charts/app/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{ if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "{{ .Values.global.name }}"
namespace: {{ .Release.Namespace }}
annotations:
cert-manager.io/cluster-issuer: le-staging-wildcard-issuer
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: 'true'
spec:
rules:
- host: "{{ .Values.global.name }}-{{ tpl .Release.Namespace $ }}.{{ tpl .Values.global.clusterDomain $ }}"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: "{{ .Values.global.name }}"
port:
number: 80
{{ end }}
20 changes: 20 additions & 0 deletions helm/app/charts/app/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ if .Values.deployment.port }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.global.name }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ .Values.global.name }}
helm.sh/chart: {{ include "app.chart" . }}
app.kubernetes.io/instance: {{ .Values.global.name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
selector:
app.kubernetes.io/name: {{ .Values.global.name }}
ports:
- protocol: TCP
port: 80
targetPort: {{ .Values.deployment.port }}
type: ClusterIP
{{ end }}
22 changes: 22 additions & 0 deletions helm/app/charts/app/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
deployment:
port: 8080
restartPolicy: Always
terminationGracePeriodSeconds: 30
revisionHistoryLimit: 5
progressDeadlineSeconds: 600

image:
repository: imageRepo
name: imageName
tag: latest
pullPolicy: IfNotPresent

ingress:
enabled: true
oauth2proxy:
enabled: true
domain: "{{ .Values.global.domains.base }}"
path: /api/admin2/
pathType: Prefix
serverSnippet: |
large_client_header_buffers 4 64k;
2 changes: 2 additions & 0 deletions helm/app/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
App url:
https://{{ .Values.global.name }}-{{ .Release.Namespace }}.{{ tpl .Values.global.clusterDomain $ }}
62 changes: 62 additions & 0 deletions helm/app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "app.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 "app.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 "app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
6 changes: 6 additions & 0 deletions helm/app/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global:
name: app
author: author-name
baseDomain: etimo-test.live
cluster: staging
clusterDomain: "{{ .Values.global.cluster }}.{{ .Values.global.baseDomain }}"