diff --git a/.github/workflows/build-container.yaml b/.github/workflows/build-container.yaml new file mode 100644 index 000000000..67def0e4f --- /dev/null +++ b/.github/workflows/build-container.yaml @@ -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 / + 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 "$GITHUB_ACTOR@users.noreply.github.com" + + - 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/chart-releaser-action@v1.6.0 + with: + charts_dir: 'chart' + pages_branch: 'chart-publications' + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f24cf8275 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM docker.io/nginx:alpine as runtime +COPY . /usr/share/nginx/html/ \ No newline at end of file diff --git a/chart/keeweb/.helmignore b/chart/keeweb/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/chart/keeweb/.helmignore @@ -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/ diff --git a/chart/keeweb/Chart.yaml b/chart/keeweb/Chart.yaml new file mode 100644 index 000000000..cf6e3ce39 --- /dev/null +++ b/chart/keeweb/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: keeweb +description: A helm chart which deploys the KeeWeb password manager. + +type: application +version: 0.1.0 diff --git a/chart/keeweb/templates/_helpers.tpl b/chart/keeweb/templates/_helpers.tpl new file mode 100644 index 000000000..44ad04f1f --- /dev/null +++ b/chart/keeweb/templates/_helpers.tpl @@ -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 }} diff --git a/chart/keeweb/templates/deployment.yaml b/chart/keeweb/templates/deployment.yaml new file mode 100644 index 000000000..0f6ae46f3 --- /dev/null +++ b/chart/keeweb/templates/deployment.yaml @@ -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 }} diff --git a/chart/keeweb/templates/hpa.yaml b/chart/keeweb/templates/hpa.yaml new file mode 100644 index 000000000..da294f2a8 --- /dev/null +++ b/chart/keeweb/templates/hpa.yaml @@ -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 }} diff --git a/chart/keeweb/templates/ingress.yaml b/chart/keeweb/templates/ingress.yaml new file mode 100644 index 000000000..945ca8596 --- /dev/null +++ b/chart/keeweb/templates/ingress.yaml @@ -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 }} diff --git a/chart/keeweb/templates/service.yaml b/chart/keeweb/templates/service.yaml new file mode 100644 index 000000000..2f831f444 --- /dev/null +++ b/chart/keeweb/templates/service.yaml @@ -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 }} diff --git a/chart/keeweb/values.yaml b/chart/keeweb/values.yaml new file mode 100644 index 000000000..2cb81723a --- /dev/null +++ b/chart/keeweb/values.yaml @@ -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: {}