Skip to content

Commit

Permalink
feat(helm|actions): adding helm chart initial draft, github actions f…
Browse files Browse the repository at this point in the history
…or release (#10)
  • Loading branch information
fafnirZ authored Jul 3, 2023
1 parent a613d8b commit 6068c3a
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 9 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release
on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set tag as env var # https://stackoverflow.com/a/58178121/11757369
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Log in to Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:}${{ steps.vars.outputs.tag }}
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
12 changes: 4 additions & 8 deletions examples/config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
cron:
timezone: Australia/Sydney
wake: 0 9 * * * # 9am everyday
sleep: 0 18 * * * # 6pm everyday
specs:
resources:
deployments:
- name: smtp
namespace: apps
- name: resourceName
namespace: namespaceName
statefulsets:
- name: cubestore-workers
namespace: cube
- name: resourceName
namespace: namespaceName
31 changes: 31 additions & 0 deletions examples/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
global:
namespace: hibernate

hibernate:

image: ghcr.io/performl/hibernate:latest

# Environment Variables
# env:
# - name: EXAMPLE_ENV_VAR
# value: "example"


cron:
timezone: Australia/Sydney
sleep: 0 18 * * 1-5 # 6pm every weekday
wake: 0 9 * * 1-5 # 9am every weekday

# for GKE spot nodes
# nodeSelector:
# iam.gke.io/gke-metadata-server-enabled: "true"
# cloud.google.com/gke-spot: "true"

config: |
specs:
resources:
deployments:
- name: app1
namespace: apps
23 changes: 23 additions & 0 deletions helm/hibernate/.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/hibernate/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: hibernate
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"
8 changes: 8 additions & 0 deletions helm/hibernate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Hibernate Helm Charts

## Installing
```bash
helm install hibernate hibernate \
--create-namespace \
--namespace=hibernate
```
7 changes: 7 additions & 0 deletions helm/hibernate/templates/configMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: hibernate-config
namespace: {{ .Values.global.namespace }}
data:
config.yaml: {{- .Values.hibernate.config | toYaml | indent 1}}
77 changes: 77 additions & 0 deletions helm/hibernate/templates/jobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: hibernate-sleep
namespace: {{ .Values.global.namespace }}
spec:
timezone: {{ .Values.hibernate.cron.timezone }}
schedule: {{ .Values.hibernate.cron.sleep }}
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
{{- if .Values.hibernate.cron.nodeSelector }}
nodeSelector:
{{ .Values.hibernate.cron.nodeSelector | toYaml | indent 12 }}
{{- end }}
serviceAccountName: hibernate-manager
containers:
- name: hibernate-sleep
image: {{ .Values.hibernate.image }}
volumeMounts:
- name: config
mountPath: "/app/config.yaml"
subPath: "config.yaml"
readOnly: true
args:
- --action=sleep
{{- if .Values.hibernate.env }}
env:
{{ .Values.hibernate.env | toYaml | indent 12 }}
{{- end }}
volumes:
- name: config
configMap:
name: hibernate-config
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: hibernate-wake
namespace: {{ .Values.global.namespace }}
spec:
timezone: {{ .Values.hibernate.cron.timezone }}
schedule: {{ .Values.hibernate.cron.wake }}
successfulJobsHistoryLimit: 0
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
{{- if .Values.hibernate.cron.nodeSelector }}
nodeSelector:
{{ .Values.hibernate.cron.nodeSelector | toYaml | indent 12 }}
{{- end }}
serviceAccountName: hibernate-manager
containers:
- name: hibernate-sleep
image: {{ .Values.hibernate.image }}
volumeMounts:
- name: config
mountPath: "/app/config.yaml"
subPath: "config.yaml"
readOnly: true
args:
- --action=sleep
{{- if .Values.hibernate.env }}
env:
{{ .Values.hibernate.env | toYaml | indent 12 }}
{{- end }}
volumes:
- name: config
configMap:
name: hibernate-config
29 changes: 29 additions & 0 deletions helm/hibernate/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: hibernate-manager
namespace: hibernate
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: hibernate-manager-role
rules:
- apiGroups: ["", "apps"] # "" indicates the core API group, "apps" indicate "AppsV1"
resources: ["deployments", "statefulsets", "configmaps"]
verbs: ["get", "watch", "list", "update", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: hibernate-manager-role-binding
subjects:
# You can specify more than one "subject"
- kind: ServiceAccount
name: hibernate-manager
namespace: hibernate
roleRef:
# "roleRef" specifies the binding to a Role / ClusterRole
kind: ClusterRole # this must be Role or ClusterRole
name: hibernate-manager-role
apiGroup: rbac.authorization.k8s.io
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.10
v1.0.0

0 comments on commit 6068c3a

Please sign in to comment.