diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6b238c2 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,23 @@ +kind: pipeline +name: publish +type: docker + +platform: + os: linux + arch: arm64 + +trigger: + branch: + - main + +steps: + - name: step1 + image: alpine + commands: + - ./build-tools/upload-new-versions.sh + environment: + GITEA_PASSWORD: + from_secret: gitea_password + +image_pull_secrets: + - dockerconfigjson diff --git a/README.md b/README.md index 3876e4d..89bc52c 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ $ curl --user : -X POST --upload-file ./.tgz https: ### Installation ```bash -$ helm repo add --username --password https://hostname.of.gitea/api/packages/scubbo/helm +$ helm repo add --username --password https://hostname.of.gitea/api/packages//helm $ helm install / ``` + +## Other links + +* [General documentation on repositories](https://helm.sh/docs/topics/chart_repository/) +* [Gitea's own documentation](https://docs.gitea.com/next/usage/packages/helm) \ No newline at end of file diff --git a/build-tools/upload-new-versions.sh b/build-tools/upload-new-versions.sh new file mode 100755 index 0000000..11bceae --- /dev/null +++ b/build-tools/upload-new-versions.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -x + +apk add git curl jq helm; +# Intentionally does not handle renames, which would begin with `R`. +changed_charts=$(git show --name-status --pretty="format:" | grep '^[MA]' | cut -f 2- | grep '^charts' | cut -d '/' -f 1,2 | sort | uniq); +echo "$changed_charts"; +current_versions=$(curl -s --user scubbo:$GITEA_PASSWORD https://gitea.scubbo.org/api/v1/packages/scubbo | jq -r '.[] | select(.type == "helm") | .name + "___" + .version'); +echo "$current_versions"; + +mkdir bundles; +for changed_chart in $changed_charts +do + echo "Operating on $changed_chart"; + # e.g. /Users/scubbo/Code/helm-charts/hello-world-0.1.1.tgz + output_location=$(helm package $changed_chart | rev | cut -d ' ' -f 1 | rev); + # e.g. hello-world-0.1.1 + file_metadata=$(echo $output_location | rev | cut -d '/' -f 1 | cut -c 5- | rev); + chart_name=$(echo $file_metadata | rev | cut -d '-' -f 2- | rev); + chart_version=$(echo $file_metadata | rev | cut -d '-' -f 1 | rev); + if [[ $(echo $current_versions | grep "$chart_name___$chart_version" | wc -l ) -eq 1 ]]; then + # I.e. if the current version in the repo is the same as what we're trying to push + # TODO - should we check that we're pushing a _newer_ version? + # TODO - does the API only show the current version, or all versions? + echo "Version clash ($chart_version) for $chart_name"; + exit 1; + else + # Move to a directory so we can upload later. Do this after checking all packages so there's no partial update + mv $output_location bundles/; + fi +done + +# All packages have been checked, no version conflicts - upload them all! +find bundles -type f -exec curl -s --user "scubbo:$GITEA_PASSWORD" -X POST --upload-file '{}' https://gitea.scubbo.org/api/packages/scubbo/helm/api/charts \; +rm -rf bundles; diff --git a/charts/hello-world/Chart.yaml b/charts/hello-world/Chart.yaml index e123dc3..b765578 100644 --- a/charts/hello-world/Chart.yaml +++ b/charts/hello-world/Chart.yaml @@ -15,7 +15,7 @@ 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.1 +version: 0.1.3 # 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 diff --git a/charts/media-share/Chart.yaml b/charts/media-share/Chart.yaml new file mode 100644 index 0000000..7a51c0a --- /dev/null +++ b/charts/media-share/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: media-share +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" diff --git a/charts/media-share/README.md b/charts/media-share/README.md new file mode 100644 index 0000000..b0d8518 --- /dev/null +++ b/charts/media-share/README.md @@ -0,0 +1,3 @@ +A trivial chart which hosts media from a given directory on a basic web server. + +Useful for temporarily uploading stuff to transfer to friends more easily than via email/etc. diff --git a/charts/media-share/templates/NOTES.txt b/charts/media-share/templates/NOTES.txt new file mode 100644 index 0000000..9a784be --- /dev/null +++ b/charts/media-share/templates/NOTES.txt @@ -0,0 +1 @@ +Don't forget to update Cloudflared! Service url is http://{{ include "media-share.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }} \ No newline at end of file diff --git a/charts/media-share/templates/_helpers.tpl b/charts/media-share/templates/_helpers.tpl new file mode 100644 index 0000000..2fd4d18 --- /dev/null +++ b/charts/media-share/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "media-share.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 "media-share.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 "media-share.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "media-share.labels" -}} +helm.sh/chart: {{ include "media-share.chart" . }} +{{ include "media-share.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "media-share.selectorLabels" -}} +app.kubernetes.io/name: {{ include "media-share.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "media-share.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "media-share.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/media-share/templates/deployment.yaml b/charts/media-share/templates/deployment.yaml new file mode 100644 index 0000000..c1a7b4c --- /dev/null +++ b/charts/media-share/templates/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "media-share.fullname" . }} + labels: + {{- include "media-share.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "media-share.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "media-share.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: python:latest + imagePullPolicy: IfNotPresent + command: [ "python", "-c"] + args: [ "import http.server; s=http.server.HTTPServer((\"0.0.0.0\", 8000), http.server.SimpleHTTPRequestHandler); s.serve_forever()" ] + workingDir: "/media" + ports: + - name: http + containerPort: 80 + protocol: TCP + volumeMounts: + - mountPath: /media + name: {{ include "media-share.fullname" . }}-pv + volumes: + - name: {{ include "media-share.fullname" . }}-pv + persistentVolumeClaim: + claimName: {{ include "media-share.fullname" . }}-pvc + + diff --git a/charts/media-share/templates/service.yaml b/charts/media-share/templates/service.yaml new file mode 100644 index 0000000..fd37162 --- /dev/null +++ b/charts/media-share/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "media-share.fullname" . }} + labels: + {{- include "media-share.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 8000 + protocol: TCP + name: http + selector: + {{- include "media-share.selectorLabels" . | nindent 4 }} diff --git a/charts/media-share/templates/tests/test-connection.yaml b/charts/media-share/templates/tests/test-connection.yaml new file mode 100644 index 0000000..ecb3cc8 --- /dev/null +++ b/charts/media-share/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "media-share.fullname" . }}-test-connection" + labels: + {{- include "media-share.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "media-share.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/media-share/templates/volumes.yaml b/charts/media-share/templates/volumes.yaml new file mode 100644 index 0000000..e80b1a8 --- /dev/null +++ b/charts/media-share/templates/volumes.yaml @@ -0,0 +1,28 @@ +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ include "media-share.fullname" . }}-pv + namespace: {{ .Release.Namespace }} +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteMany + nfs: + server: {{ .Values.volume.nfsServer }} + path: {{ .Values.volume.nfsPath }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "media-share.fullname" . }}-pvc + namespace: {{ .Release.Namespace }} +spec: + storageClassName: "" + volumeName: {{ include "media-share.fullname" . }}-pv + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi diff --git a/charts/media-share/values.yaml b/charts/media-share/values.yaml new file mode 100644 index 0000000..0e68176 --- /dev/null +++ b/charts/media-share/values.yaml @@ -0,0 +1,33 @@ +# Default values for media-share. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +volume: + nfsServer: "rassigma.avril" + nfsPath: "/mnt/BERTHA/shared-media/media"