Skip to content

Commit

Permalink
migrate helm chart (#4685)
Browse files Browse the repository at this point in the history
* migrate heml chart

* refactor

* Update helm-lint-test.yaml

* Update package.json

* Update Chart.yaml

* Update Chart.yaml

* rename

* Update helm-chart-lint-test.yaml
  • Loading branch information
juanpicado committed Jun 16, 2024
1 parent 15a86b7 commit e7517ac
Show file tree
Hide file tree
Showing 20 changed files with 928 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ yarn.js
packages/ui-components/storybook-static
dist.js
bundle.js
charts/
47 changes: 47 additions & 0 deletions .github/workflows/helm-chart-lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Lint and Test Helm Chart

on:
pull_request:
paths:
- 'charts/**'

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.4.1

# Python is required because `ct lint` runs Yamale (https://github.com/23andMe/Yamale) and
# yamllint (https://github.com/adrienverge/yamllint) which require Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.6.1
- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --config ct.yaml)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Run chart-testing (lint)
run: ct lint --config ct.yaml

- name: Create kind cluster
uses: helm/kind-action@v1.9.0
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
run: ct install --config ct.yaml
32 changes: 32 additions & 0 deletions .github/workflows/helm-chart-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release Helm Charts

on:
push:
branches:
- master
paths:
- 'charts/**'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- 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
with:
version: v3.4.0

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.5.0
env:
CR_TOKEN: "${{ secrets.CR_TOKEN }}"
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ jest.config.js
contrib/
storage_default_storage/
docker-bin/

# charts
charts/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ test/cli/e2e-yarn4/bin/yarn-4.0.0-rc.14.cjs
yarn.js
website/docs/api/*
packages/ui-components/storybook-static/*
charts/
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Charts

/charts @juanpicado
22 changes: 22 additions & 0 deletions charts/verdaccio/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v2
description: A lightweight private node.js proxy registry
name: verdaccio
version: 4.17.0
appVersion: 5.31.1
home: https://verdaccio.org
icon: https://cdn.verdaccio.dev/logos/default.png
sources:
- https://verdaccio.org
- https://github.com/verdaccio/verdaccio
keywords:
- npm
- registry
- yarn
- pnpm
- javascript
- nodejs
maintainers:
- name: juanpicado
email: juanpicado19@gmail.com
- name: jhonmike
email: jhon.msdev@gmail.com
25 changes: 25 additions & 0 deletions charts/verdaccio/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
1. Get the application URL by running these commands:
{{- $tls := .Values.ingress.tls }}
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- if $tls }}
https://{{ tpl $host $ }}
{{- else }}
http://{{ tpl $host $ }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "verdaccio.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "verdaccio.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "verdaccio.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "verdaccio.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
171 changes: 171 additions & 0 deletions charts/verdaccio/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "verdaccio.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 "verdaccio.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 "verdaccio.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "verdaccio.selectorLabels" -}}
app.kubernetes.io/name: {{ include "verdaccio.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "verdaccio.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "verdaccio.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Renders a value that contains template.
Usage:
{{ include "tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "tplvalues.render" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}

{{/*
Pod Labels
spec:
template:
metadata:
labels:
{{- include "verdaccio.podLabels" . | nindent 8 }}
*/}}
{{- define "verdaccio.podLabels" -}}
{{- include "verdaccio.labels" . }}
{{- $global := .Values.global }}
{{- $local := .Values.podLabels }}
{{- $labels := dict }}
{{- if $global }}
{{- range $k,$v := $global.podLabels }}
{{- $labels = merge $labels (dict $k (tpl $v $)) }}
{{- end }}
{{- end }}
{{- if $local }}
{{- range $k,$v := $local }}
{{- $labels = merge $labels (dict $k (tpl $v $)) }}
{{- end }}
{{- end }}
{{- if (not (empty $labels)) }}
{{- toYaml $labels | nindent 0 }}
{{- end }}
{{- end -}}

{{/*
Pod Annotations
spec:
template:
metadata:
annotations:
{{- include "verdaccio.podAnnotations" . | nindent 8 }}
*/}}
{{- define "verdaccio.podAnnotations" -}}
{{- $global := .Values.global }}
{{- $local := .Values.podAnnotations }}
{{- $annotations := dict }}
{{- if $global }}
{{- range $k,$v := $global.podAnnotations }}
{{- $annotations = merge $annotations (dict $k (tpl $v $)) }}
{{- end }}
{{- end -}}
{{- if $local }}
{{- range $k,$v := $local }}
{{- $annotations = merge $annotations (dict $k (tpl $v $)) }}
{{- end }}
{{- end -}}
{{- if (not (empty $annotations)) }}
{{- toYaml $annotations }}
{{- end }}
{{- end }}

{{/*
# templates/deployment.yaml
spec:
template:
spec:
{{- include "verdaccio.imagePullSecrets" . | nindent 6 }}

# values.yaml
image:
pullSecrets:
- mypullsecret
*/}}
{{- define "verdaccio.imagePullSecrets" -}}
{{- $images := .Values.image }}
{{- $global := .Values.global }}
{{- $pullSecrets := list }}

{{- if $global }}
{{- if $global.image }}
{{- range $global.image.pullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- range $images.pullSecrets -}}
{{- $pullSecrets = append $pullSecrets . -}}
{{- end -}}

{{- if (not (empty $pullSecrets)) }}
imagePullSecrets:
{{- range $pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
{{- end -}}
9 changes: 9 additions & 0 deletions charts/verdaccio/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "verdaccio.fullname" . }}
labels:
{{- include "verdaccio.labels" . | nindent 4 }}
data:
config.yaml: |-
{{- include "tplvalues.render" (dict "value" .Values.configMap "context" $) | nindent 4 }}

0 comments on commit e7517ac

Please sign in to comment.