Skip to content

Commit

Permalink
Merge pull request #25 from colearendt/add-ghcr-chart
Browse files Browse the repository at this point in the history
Add regcred chart
  • Loading branch information
colearendt authored Jan 27, 2022
2 parents 5a1677b + 8116017 commit 4244e65
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
docs:
#!/bin/bash
helm-docs --chart-search-root=charts --template-files=README.md.gotmpl --template-files=./_templates.gotmpl

lint:
#!/bin/bash
ct lint ./charts --target-branch main
14 changes: 14 additions & 0 deletions charts/_templates.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- define "colearendt.install" }}
{{- $repoName := "colearendt" }}
{{- $repoUrl := "https://colearendt.github.io/helm" }}

## Installing the Chart

To install the chart with the release name `my-release` at version {{ template "chart.version" . }}:

```bash
helm repo add {{ $repoName }} {{ $repoUrl }}
helm install {{- if (regexMatch "[0-9]+\\.[0-9]+\\.[0-9]+-[a-zA-Z\\.0-9]+" .Version) }} --devel{{ end }} my-release {{ $repoName }}/{{ template "chart.name" . }} --version={{ template "chart.version" . }}
```

{{- end }}
23 changes: 23 additions & 0 deletions charts/regcred/.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/
12 changes: 12 additions & 0 deletions charts/regcred/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v2
name: regcred
description: A Helm chart that deploys registry credential secrets

type: application
version: 0.1.0
appVersion: "0.1.0"

maintainers:
- name: colearendt
email: [email protected]
url: https://github.com/colearendt
54 changes: 54 additions & 0 deletions charts/regcred/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# regcred

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.1.0](https://img.shields.io/badge/AppVersion-0.1.0-informational?style=flat-square)

## Installing the Chart

To install the chart with the release name `my-release` at version 0.1.0:

```bash
helm repo add colearendt https://colearendt.github.io/helm
helm install my-release colearendt/regcred --version=0.1.0
```

#### Description

This chart simplifies the creation
of ["Registry Credentials"](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) for
use authenticating a Kubernetes cluster to a Container Registry for pulling images.

This is very important for (1) private images and (2) DockerHub, because of their unfortunate rate limit.

Each helm deployment only creates a single secret, but that secret can have multiple credentials within it.

Use this chart to automate away the annoying parts of registry credentials.

#### Examples

`ghcr.io`
```yaml
registryCredentials:
- url: ghcr.io
username: 'colearendt'
password: 'my-github-pat'
```
`docker.io` (DockerHub)
```yaml
registryCredentials:
- url: docker.io
username: 'colearendt'
password: 'my-password-or-token'
```

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| extraLabels | object | `{}` | |
| fullnameOverride | string | `""` | |
| nameOverride | string | `""` | |
| registryCredentials | list | `[]` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0)
39 changes: 39 additions & 0 deletions charts/regcred/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{ template "chart.header" . }}

{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}

{{ template "colearendt.install" . }}

#### Description

This chart simplifies the creation
of ["Registry Credentials"](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) for
use authenticating a Kubernetes cluster to a Container Registry for pulling images.

This is very important for (1) private images and (2) DockerHub, because of their unfortunate rate limit.

Each helm deployment only creates a single secret, but that secret can have multiple credentials within it.

Use this chart to automate away the annoying parts of registry credentials.

#### Examples

`ghcr.io`
```yaml
registryCredentials:
- url: ghcr.io
username: 'colearendt'
password: 'my-github-pat'
```

`docker.io` (DockerHub)
```yaml
registryCredentials:
- url: docker.io
username: 'colearendt'
password: 'my-password-or-token'
```

{{ template "chart.valuesSection" . }}

{{ template "helm-docs.versionFooter" . }}
10 changes: 10 additions & 0 deletions charts/regcred/ci/advanced-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extraLabels:
mylabel: fun

registryCredentials:
- url: ghcr.io
username: 'username'
password: 'password'
- url: docker.io
username: 'other_username'
password: 'other_password'
Empty file.
4 changes: 4 additions & 0 deletions charts/regcred/ci/example-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
registryCredentials:
- url: ghcr.io
username: 'username'
password: 'password'
51 changes: 51 additions & 0 deletions charts/regcred/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "regcred.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 "regcred.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 "regcred.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "regcred.selectorLabels" -}}
app.kubernetes.io/name: {{ include "regcred.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/regcred/templates/_regcred.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- /*
Base64 Encode the essential "username:password" key
Required keys:
username
password
*/ -}}
{{- define "regcred.b64Creds" -}}
{{- printf "%s:%s" .username .password | b64enc }}
{{- end }}

{{- define "regcred.regCred" -}}
{{- $secret := include "regcred.b64Creds" . }}
{{- printf "\"%s\":{\"auth\": \"%s\"}" .url ($secret) }}
{{- end }}

{{- define "regcred.registryCredentials" -}}
{{- $total := "" }}
{{- range $rc := . }}
{{- $rcTmp := include "regcred.regCred" . }}
{{- $total = join "," (list $total $rcTmp) }}
{{- $total = trimPrefix "," $total }}
{{- end }}
{{- printf "{\"auths\":{%s}}" $total | b64enc }}
{{- end }}
14 changes: 14 additions & 0 deletions charts/regcred/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.registryCredentials -}}
kind: Secret
type: kubernetes.io/dockerconfigjson
apiVersion: v1
metadata:
name: {{ include "regcred.fullname" . }}
labels:
{{- include "regcred.labels" . | nindent 4}}
{{- with .Values.extraLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
data:
.dockerconfigjson: {{- include "regcred.registryCredentials" .Values.registryCredentials | nindent 4 }}
{{- end -}}
12 changes: 12 additions & 0 deletions charts/regcred/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Declare variables to be passed into your templates.

nameOverride: ""
fullnameOverride: ""

extraLabels: {}

registryCredentials: []
# - url: ghcr.io
# username: 'username'
# password: 'password'
#

0 comments on commit 4244e65

Please sign in to comment.