Skip to content

Commit

Permalink
Implement chart publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Nov 13, 2024
1 parent b71621f commit b606c90
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/build-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Build container
on:
push:
branches:
- gh-pages
workflow_dispatch:

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
extract-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
ref: gh-pages
- name: Extract version
id: extract_version
run: |
apt update -y && apt install -y jq
echo ::set-output name=version::$(jq -r '.version' update.json)
build:
runs-on: ubuntu-latest
needs: extract-version
steps:
- name: Download KeeWeb
uses: actions/checkout@v3
with:
fetch-depth: 1
ref: gh-pages
path: Pages
- name: Download Build
uses: actions/checkout@v3
with:
fetch-depth: 1
ref: master
path: Build
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Process repository name
run: echo "IMAGE_PATH=${REGISTRY}/${IMAGE_NAME@L}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_PATH }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./Pages
file: ./Build/Dockerfile
push: true
tags: ${{ env.IMAGE_PATH }}:${{ needs.extract-version.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}

publish:
needs:
- build
- extract-version
runs-on: ubuntu-latest
steps:
- name: Download Build
uses: actions/checkout@v3
with:
fetch-depth: 1
ref: master

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Update Helm Chart Version
working-directory: chart/keeweb
run: |
# The current version is stored in inputs.tag, we need to rewrite the charts.yaml file with the new version
# However we can only replace the version: property if it is at the start of a line
echo "Updating Chart.yaml version to ${{ needs.extract-version.outputs.version }}"
sed -i "s/^version: \(.*\)/version: ${{ needs.extract-version.outputs.version }}/g" Chart.yaml
# Now this inserted a version with a v prefix, we need to remove only that initial v
sed -i "1s/version: v\(.*\)/version: \1/g" Chart.yaml
- name: Add Bitnami chart repository
run: helm repo add bitnami https://charts.bitnami.com/bitnami

- name: Install chart dependencies
run: helm dependency update chart/keeweb

- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: 'chart'
pages_branch: 'chart-publications'
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM docker.io/nginx:alpine as runtime
COPY . /usr/share/nginx/html/
23 changes: 23 additions & 0 deletions chart/keeweb/.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/
6 changes: 6 additions & 0 deletions chart/keeweb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: keeweb
description: A helm chart which deploys the KeeWeb password manager.

type: application
version: 0.1.0
51 changes: 51 additions & 0 deletions chart/keeweb/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "keeweb.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 "keeweb.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 "keeweb.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "keeweb.selectorLabels" -}}
app.kubernetes.io/name: {{ include "keeweb.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
52 changes: 52 additions & 0 deletions chart/keeweb/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "keeweb.fullname" . }}
labels:
{{- include "keeweb.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "keeweb.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "keeweb.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.Version }}"
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 }}
32 changes: 32 additions & 0 deletions chart/keeweb/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "keeweb.fullname" . }}
labels:
{{- include "keeweb.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "keeweb.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
42 changes: 42 additions & 0 deletions chart/keeweb/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "keeweb.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "keeweb.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
tls:
- hosts:
{{- range .Values.ingress.hosts }}
- {{ . | quote }}
{{- end }}
secretName: "parchment-website-tls"
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
- path: "/"
pathType: "ImplementationSpecific"
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions chart/keeweb/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "keeweb.fullname" . }}
labels:
{{- include "keeweb.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "keeweb.selectorLabels" . | nindent 4 }}
46 changes: 46 additions & 0 deletions chart/keeweb/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Default values for wiki.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: ghcr.io/ldtteam/keeweb
pullPolicy: Always
#tag: latest

imagePullSecrets: []

ingress:
enabled: false
annotations: {}
hosts: []

service:
type: ClusterIP
port: 80

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

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

0 comments on commit b606c90

Please sign in to comment.