diff --git a/.github/helm-docs/_templates.gotmpl b/.github/helm-docs/_templates.gotmpl new file mode 100644 index 0000000..d3c215d --- /dev/null +++ b/.github/helm-docs/_templates.gotmpl @@ -0,0 +1,10 @@ +{{ define "extra.installation" -}} + +## Installation + +```bash +helm repo add nethermind https://nethermindeth.github.io/helm-charts +helm install {{ template "chart.name" . }} nethermind/{{ template "chart.name" . }} +``` + +{{- end }} \ No newline at end of file diff --git a/.github/workflows/chart-releaser.yaml b/.github/workflows/chart-releaser.yaml new file mode 100644 index 0000000..c5b84f1 --- /dev/null +++ b/.github/workflows/chart-releaser.yaml @@ -0,0 +1,51 @@ +name: Helm Charts Release + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + helm-chart-release: + permissions: + contents: write + 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: Set up Helm + uses: azure/setup-helm@v3 + with: + version: v3.12.1 + + - name: Helm Dependencies + run: | + helm dependency update helm-chart + + - name: Run chart-releaser + uses: helm/chart-releaser-action@main + with: + charts_dir: helm-chart + pages_branch: charts-releases + skip_upload: true + env: + CR_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CR_SKIP_EXISTING: true + CR_GENERATE_RELEASE_NOTES: true + + - name: Publish to JFrog Artifactory + shell: bash + run: | + helm registry login nethermind.jfrog.io --username ${{ secrets.ARTIFACTORY_ANGKOR_USERNAME }} --password ${{ secrets.ARTIFACTORY_ANGKOR_TOKEN_CONTRIBUTOR }} + for chart in .cr-release-packages/*.tgz; do + helm push "$chart" oci://nethermind.jfrog.io/angkor-helmoci-local + done diff --git a/.github/workflows/helm-docs.yaml b/.github/workflows/helm-docs.yaml new file mode 100644 index 0000000..aca3e5f --- /dev/null +++ b/.github/workflows/helm-docs.yaml @@ -0,0 +1,31 @@ +name: Generate Helm Docs + +on: pull_request + +permissions: + contents: write + pull-requests: write + +jobs: + generate-helm-docs: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + fetch-depth: 0 + + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Run helm-docs + run: docker run --rm -v $(pwd):/helm-docs jnorwood/helm-docs:v1.14.2 --chart-search-root=. --template-files=./.github/helm-docs/_templates.gotmpl --template-files=README.md.gotmpl + + - name: Commit & Push changes + uses: actions-js/push@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.event.pull_request.head.ref }} + message: "docs: auto-generate chart docs" \ No newline at end of file diff --git a/.helmignore b/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/.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/helm-chart/Chart.yaml b/helm-chart/Chart.yaml new file mode 100644 index 0000000..c1e3e33 --- /dev/null +++ b/helm-chart/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: jrpc-interceptor +description: A Helm chart for the JRPC Interceptor application +type: application +version: 0.1.0 +appVersion: "main" +maintainers: + - name: Nethermind + url: https://nethermind.io diff --git a/helm-chart/templates/_helpers.tpl b/helm-chart/templates/_helpers.tpl new file mode 100644 index 0000000..43bd683 --- /dev/null +++ b/helm-chart/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "jrpc-interceptor.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 "jrpc-interceptor.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 "jrpc-interceptor.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "jrpc-interceptor.labels" -}} +helm.sh/chart: {{ include "jrpc-interceptor.chart" . }} +{{ include "jrpc-interceptor.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "jrpc-interceptor.selectorLabels" -}} +app.kubernetes.io/name: {{ include "jrpc-interceptor.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/helm-chart/templates/deployment.yaml b/helm-chart/templates/deployment.yaml new file mode 100644 index 0000000..fdd0b6a --- /dev/null +++ b/helm-chart/templates/deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "jrpc-interceptor.fullname" . }} + labels: + {{- include "jrpc-interceptor.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "jrpc-interceptor.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "jrpc-interceptor.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.ports.http }} + protocol: TCP + - name: metrics + containerPort: {{ .Values.ports.metrics }} + protocol: TCP + env: + - name: LISTEN_PORT + value: "{{ .Values.host }}:{{ .Values.ports.http }}" + - name: SERVICE_TO_PROXY + value: {{ .Values.env.SERVICE_TO_PROXY | quote }} + - name: LOG_SERVER_URL + value: "{{ .Values.host }}:{{ .Values.ports.logServer }}" + - name: PROMETHEUS_URL + value: "{{ .Values.host }}:{{ .Values.ports.metrics }}" + - name: USE_PROMETHEUS + value: {{ .Values.env.USE_PROMETHEUS | quote }} + - name: LOG_SERVER_DEBUG + value: {{ .Values.env.LOG_SERVER_DEBUG | quote }} + resources: + {{- toYaml .Values.resources | nindent 12 }} \ No newline at end of file diff --git a/helm-chart/templates/service.yaml b/helm-chart/templates/service.yaml new file mode 100644 index 0000000..189a983 --- /dev/null +++ b/helm-chart/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "jrpc-interceptor.fullname" . }} + labels: + {{- include "jrpc-interceptor.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.ports.http }} + targetPort: http + protocol: TCP + name: http + - port: {{ .Values.ports.metrics }} + targetPort: metrics + protocol: TCP + name: metrics + selector: + {{- include "jrpc-interceptor.selectorLabels" . | nindent 4 }} diff --git a/helm-chart/templates/servicemonitor.yaml b/helm-chart/templates/servicemonitor.yaml new file mode 100644 index 0000000..cf16cb0 --- /dev/null +++ b/helm-chart/templates/servicemonitor.yaml @@ -0,0 +1,27 @@ +{{- if .Values.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "jrpc-interceptor.fullname" . }} + {{- if .Values.serviceMonitor.namespace }} + namespace: {{ .Values.serviceMonitor.namespace }} + {{- else }} + namespace: {{ .Release.Namespace }} + {{- end }} + labels: + {{- include "jrpc-interceptor.labels" . | nindent 4 }} + {{- with .Values.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + endpoints: + - port: metrics + interval: {{ .Values.serviceMonitor.interval }} + scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }} + selector: + matchLabels: + {{- include "jrpc-interceptor.selectorLabels" . | nindent 6 }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} +{{- end }} diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml new file mode 100644 index 0000000..dbc9407 --- /dev/null +++ b/helm-chart/values.yaml @@ -0,0 +1,36 @@ +replicaCount: 1 + +image: + repository: ghcr.io/nethermindeth/jrpc-interceptor + pullPolicy: Always + tag: "main" + +service: + type: ClusterIP + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + +host: 0.0.0.0 + +ports: + http: 8081 + metrics: 9120 + logServer: 514 + +env: + SERVICE_TO_PROXY: "op-fullnode-op-execution:8545" + USE_PROMETHEUS: "true" + LOG_SERVER_DEBUG: "true" + +serviceMonitor: + enabled: true + namespace: "" # If empty, will use the release namespace + interval: 15s + scrapeTimeout: 10s + additionalLabels: {}