From c985acfe388a5f384514f26f3fc98d58367699fc Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 25 Mar 2022 06:11:49 +0100 Subject: [PATCH 01/52] chore: Jenkins X build pack --- .lighthouse/jenkins-x/pullrequest.yaml | 38 +++++ .lighthouse/jenkins-x/release.yaml | 44 ++++++ .lighthouse/jenkins-x/triggers.yaml | 16 +++ Dockerfile | 6 + OWNERS | 4 + OWNERS_ALIASES | 6 + charts/substrate-faucet/.helmignore | 21 +++ charts/substrate-faucet/Chart.yaml | 5 + charts/substrate-faucet/Kptfile | 11 ++ charts/substrate-faucet/Makefile | 48 +++++++ charts/substrate-faucet/README.md | 1 + charts/substrate-faucet/templates/NOTES.txt | 4 + .../substrate-faucet/templates/_helpers.tpl | 16 +++ charts/substrate-faucet/templates/canary.yaml | 66 +++++++++ .../templates/deployment.yaml | 79 ++++++++++ charts/substrate-faucet/templates/hpa.yaml | 28 ++++ .../substrate-faucet/templates/ingress.yaml | 48 +++++++ charts/substrate-faucet/templates/ksvc.yaml | 51 +++++++ charts/substrate-faucet/templates/sa.yaml | 16 +++ .../substrate-faucet/templates/service.yaml | 29 ++++ charts/substrate-faucet/values.yaml | 135 ++++++++++++++++++ preview/Kptfile | 11 ++ preview/helmfile.yaml | 31 ++++ preview/values.yaml.gotmpl | 8 ++ 24 files changed, 722 insertions(+) create mode 100644 .lighthouse/jenkins-x/pullrequest.yaml create mode 100644 .lighthouse/jenkins-x/release.yaml create mode 100644 .lighthouse/jenkins-x/triggers.yaml create mode 100644 Dockerfile create mode 100644 OWNERS create mode 100644 OWNERS_ALIASES create mode 100755 charts/substrate-faucet/.helmignore create mode 100644 charts/substrate-faucet/Chart.yaml create mode 100755 charts/substrate-faucet/Kptfile create mode 100755 charts/substrate-faucet/Makefile create mode 100755 charts/substrate-faucet/README.md create mode 100755 charts/substrate-faucet/templates/NOTES.txt create mode 100755 charts/substrate-faucet/templates/_helpers.tpl create mode 100755 charts/substrate-faucet/templates/canary.yaml create mode 100755 charts/substrate-faucet/templates/deployment.yaml create mode 100755 charts/substrate-faucet/templates/hpa.yaml create mode 100755 charts/substrate-faucet/templates/ingress.yaml create mode 100755 charts/substrate-faucet/templates/ksvc.yaml create mode 100755 charts/substrate-faucet/templates/sa.yaml create mode 100755 charts/substrate-faucet/templates/service.yaml create mode 100755 charts/substrate-faucet/values.yaml create mode 100644 preview/Kptfile create mode 100644 preview/helmfile.yaml create mode 100644 preview/values.yaml.gotmpl diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml new file mode 100644 index 0000000..a0912eb --- /dev/null +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -0,0 +1,38 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: pullrequest +spec: + pipelineSpec: + tasks: + - name: from-build-pack + resources: {} + taskSpec: + metadata: {} + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/pullrequest.yaml@versionStream + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone-pr.yaml@versionStream + name: "" + resources: {} + - name: jx-variables + resources: {} + - name: build-python-unittest + resources: {} + - name: check-registry + resources: {} + - name: build-container-build + resources: {} + - name: promote-jx-preview + resources: {} + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 12h0m0s +status: {} diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml new file mode 100644 index 0000000..699e67a --- /dev/null +++ b/.lighthouse/jenkins-x/release.yaml @@ -0,0 +1,44 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: release +spec: + pipelineSpec: + tasks: + - name: from-build-pack + resources: {} + taskSpec: + metadata: {} + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/release.yaml@versionStream + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone.yaml@versionStream + name: "" + resources: {} + - name: next-version + resources: {} + - name: jx-variables + resources: {} + - name: build-python-unittest + resources: {} + - name: check-registry + resources: {} + - name: build-container-build + resources: {} + - name: promote-changelog + resources: {} + - name: promote-helm-release + resources: {} + - name: promote-jx-promote + resources: {} + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 12h0m0s +status: {} diff --git a/.lighthouse/jenkins-x/triggers.yaml b/.lighthouse/jenkins-x/triggers.yaml new file mode 100644 index 0000000..ae2fcfa --- /dev/null +++ b/.lighthouse/jenkins-x/triggers.yaml @@ -0,0 +1,16 @@ +apiVersion: config.lighthouse.jenkins-x.io/v1alpha1 +kind: TriggerConfig +spec: + presubmits: + - name: pr + context: "pr" + always_run: true + optional: false + source: "pullrequest.yaml" + postsubmits: + - name: release + context: "release" + source: "release.yaml" + branches: + - ^main$ + - ^master$ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d8b60dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:onbuild +COPY requirements.txt . +ENV PORT 8080 +EXPOSE 8080 +ENTRYPOINT ["python"] +CMD ["app.py"] diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..40ced59 --- /dev/null +++ b/OWNERS @@ -0,0 +1,4 @@ +approvers: +- faisalthaheem +reviewers: +- faisalthaheem diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES new file mode 100644 index 0000000..c7b561f --- /dev/null +++ b/OWNERS_ALIASES @@ -0,0 +1,6 @@ +aliases: +- faisalthaheem +best-approvers: +- faisalthaheem +best-reviewers: +- faisalthaheem diff --git a/charts/substrate-faucet/.helmignore b/charts/substrate-faucet/.helmignore new file mode 100755 index 0000000..f0c1319 --- /dev/null +++ b/charts/substrate-faucet/.helmignore @@ -0,0 +1,21 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/substrate-faucet/Chart.yaml b/charts/substrate-faucet/Chart.yaml new file mode 100644 index 0000000..3be8323 --- /dev/null +++ b/charts/substrate-faucet/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +icon: https://raw.githubusercontent.com/cdfoundation/artwork/master/jenkinsx/icon/color/jenkinsx-icon-color.png +name: substrate-faucet +version: 0.1.0-SNAPSHOT diff --git a/charts/substrate-faucet/Kptfile b/charts/substrate-faucet/Kptfile new file mode 100755 index 0000000..2a814c7 --- /dev/null +++ b/charts/substrate-faucet/Kptfile @@ -0,0 +1,11 @@ +apiVersion: kpt.dev/v1alpha1 +kind: Kptfile +metadata: + name: charts +upstream: + type: git + git: + commit: b52b35506a05e046d54615c3ade97f3aef8bfb08 + repo: https://github.com/jenkins-x/jx3-pipeline-catalog + directory: /helm/charts + ref: master diff --git a/charts/substrate-faucet/Makefile b/charts/substrate-faucet/Makefile new file mode 100755 index 0000000..bdc3a42 --- /dev/null +++ b/charts/substrate-faucet/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := substrate-faucet +OS := $(shell uname) +RELEASE_VERSION := $(shell cat ../../VERSION) + +build: clean + rm -rf requirements.lock + helm dependency build + helm lint + +install: clean build + helm install . --name ${NAME} + +upgrade: clean build + helm upgrade ${NAME} . + +delete: + helm delete --purge ${NAME} + +clean: + rm -rf charts + rm -rf ${NAME}*.tgz + +release: clean + helm dependency build + helm lint + helm init --client-only + helm package . + curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts + rm -rf ${NAME}*.tgz% + +tag: +ifeq ($(OS),Darwin) + sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml + sed -i "" -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml +else ifeq ($(OS),Linux) + sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/peaqnetwork\/substrate-faucet|" values.yaml + sed -i -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml +else + echo "platfrom $(OS) not supported to release from" + exit -1 +endif + git add --all + git commit -m "chore: release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed + git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)" + git push origin v$(RELEASE_VERSION) diff --git a/charts/substrate-faucet/README.md b/charts/substrate-faucet/README.md new file mode 100755 index 0000000..89f8286 --- /dev/null +++ b/charts/substrate-faucet/README.md @@ -0,0 +1 @@ +# my application \ No newline at end of file diff --git a/charts/substrate-faucet/templates/NOTES.txt b/charts/substrate-faucet/templates/NOTES.txt new file mode 100755 index 0000000..97823be --- /dev/null +++ b/charts/substrate-faucet/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/charts/substrate-faucet/templates/_helpers.tpl b/charts/substrate-faucet/templates/_helpers.tpl new file mode 100755 index 0000000..f0d83d2 --- /dev/null +++ b/charts/substrate-faucet/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "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). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/substrate-faucet/templates/canary.yaml b/charts/substrate-faucet/templates/canary.yaml new file mode 100755 index 0000000..b5f55d3 --- /dev/null +++ b/charts/substrate-faucet/templates/canary.yaml @@ -0,0 +1,66 @@ +{{- if .Values.canary.enabled }} +apiVersion: flagger.app/v1beta1 +kind: Canary +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.canary.labels }} +{{ toYaml .Values.canary.labels | indent 4 }} +{{- end }} +spec: + provider: istio + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + progressDeadlineSeconds: {{ .Values.canary.progressDeadlineSeconds }} + {{- if .Values.hpa.enabled }} + autoscalerRef: + apiVersion: autoscaling/v2beta1 + kind: HorizontalPodAutoscaler + name: {{ template "fullname" . }} + {{- end }} + service: + port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + gateways: + - {{ template "fullname" . }} + hosts: + - {{ .Values.canary.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain) }} + analysis: + interval: {{ .Values.canary.analysis.interval }} + threshold: {{ .Values.canary.analysis.threshold }} + maxWeight: {{ .Values.canary.analysis.maxWeight }} + stepWeight: {{ .Values.canary.analysis.stepWeight }} + metrics: + - name: latency + templateRef: + name: latency + namespace: istio-system + thresholdRange: + max: {{ .Values.canary.analysis.metrics.latency.threshold }} + interval: {{ .Values.canary.analysis.metrics.latency.interval | quote }} + +--- + +apiVersion: networking.istio.io/v1alpha3 +kind: Gateway +metadata: + name: {{ template "fullname" . }} +{{- if .Values.canary.gatewayLabels }} + labels: +{{ toYaml .Values.canary.gatewayLabels | indent 4 }} +{{- end }} +spec: + selector: + istio: ingressgateway + servers: + - port: + number: {{ .Values.service.externalPort }} + name: http + protocol: HTTP + hosts: + - {{ .Values.canary.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain) }} +{{- end }} diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml new file mode 100755 index 0000000..a5e4c62 --- /dev/null +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -0,0 +1,79 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.deploymentLabels }} +{{ toYaml .Values.deploymentLabels | indent 4 }} +{{- end }} +spec: + selector: + matchLabels: + app: {{ template "fullname" . }} +{{- if .Values.hpa.enabled }} +{{- else }} + replicas: {{ .Values.replicaCount }} +{{- end }} + template: + metadata: + labels: + draft: {{ default "draft-app" .Values.draft }} + app: {{ template "fullname" . }} +{{- if .Values.podsLabels }} +{{ toYaml .Values.podsLabels | indent 6 }} +{{- end }} +{{- if .Values.podAnnotations }} + annotations: +{{ toYaml .Values.podAnnotations | indent 8 }} +{{- end }} + spec: +{{- if .Values.serviceAccount.enabled }} +{{- if .Values.serviceAccount.name }} + serviceAccountName: {{ .Values.serviceAccount.name }} +{{- else }} + serviceAccountName: {{ template "fullname" . }} +{{- end }} +{{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: VERSION + value: {{ .Chart.Version }} +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ quote $pval }} +{{- end }} + envFrom: +{{ toYaml .Values.envFrom | indent 10 }} + ports: + - name: http + containerPort: {{ .Values.service.internalPort }} + livenessProbe: + httpGet: + path: {{ .Values.livenessProbe.probePath | default .Values.probePath }} + port: {{ .Values.service.internalPort }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.readinessProbe.probePath | default .Values.probePath }} + port: {{ .Values.service.internalPort }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 12 }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + imagePullSecrets: +{{- range $pval := .Values.jx.imagePullSecrets }} + - name: {{ quote $pval }} +{{- end }} +{{- end }} diff --git a/charts/substrate-faucet/templates/hpa.yaml b/charts/substrate-faucet/templates/hpa.yaml new file mode 100755 index 0000000..a20a001 --- /dev/null +++ b/charts/substrate-faucet/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.hpa.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.hpa.labels }} +{{ toYaml .Values.hpa.labels | indent 4 }} +{{- end }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + minReplicas: {{ .Values.hpa.minReplicas }} + maxReplicas: {{ .Values.hpa.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.hpa.cpuTargetAverageUtilization }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.hpa.memoryTargetAverageUtilization }} +{{- end }} \ No newline at end of file diff --git a/charts/substrate-faucet/templates/ingress.yaml b/charts/substrate-faucet/templates/ingress.yaml new file mode 100755 index 0000000..7c641c1 --- /dev/null +++ b/charts/substrate-faucet/templates/ingress.yaml @@ -0,0 +1,48 @@ +{{- if and (.Values.jxRequirements.ingress.domain) (not .Values.knativeDeploy) }} +{{- $annotations := dict }} +{{- $_ := merge $annotations .Values.ingress.annotations .Values.jxRequirements.ingress.annotations }} +{{- if not (hasKey $annotations "kubernetes.io/ingress.class") }} +{{- $_ := set $annotations "kubernetes.io/ingress.class" (.Values.ingress.classAnnotation | default "nginx") }} +{{- end }} +{{- if and (hasKey .Values.jxRequirements.ingress "serviceType") (.Values.jxRequirements.ingress.serviceType) (eq .Values.jxRequirements.ingress.serviceType "NodePort") (not (hasKey $annotations "jenkins.io/host")) }} +{{- $_ := set $annotations "jenkins.io/host" .Values.jxRequirements.ingress.domain }} +{{- end }} +apiVersion: {{ .Values.jxRequirements.ingress.apiVersion }} +kind: Ingress +metadata: + annotations: +{{- if $annotations }} +{{ toYaml $annotations | indent 4 }} +{{- end }} + name: {{ .Values.service.name }} +{{- if .Values.ingress.labels }} +{{ toYaml .Values.ingress.labels | indent 4 }} +{{- end }} +spec: + rules: + - http: + paths: + - pathType: {{ .Values.ingress.pathType | default "ImplementationSpecific" }} + backend: + service: + name: {{ .Values.service.name }} + port: + number: {{ .Values.service.externalPort }} +{{- if eq "NodePort" .Values.jxRequirements.ingress.serviceType }} + path: "/{{ .Release.Namespace }}/hook" +{{- else if .Values.jxRequirements.ingress.domain }} + host: {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} +{{- end }} +{{- if .Values.jxRequirements.ingress.tls.enabled }} + tls: + - hosts: + - {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} +{{- if and (hasKey .Values.jxRequirements.ingress.tls "secretName") (.Values.jxRequirements.ingress.tls.secretName) }} + secretName: "{{ .Values.jxRequirements.ingress.tls.secretName }}" +{{- else if .Values.jxRequirements.ingress.tls.production }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-p" +{{- else }} + secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-s" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/substrate-faucet/templates/ksvc.yaml b/charts/substrate-faucet/templates/ksvc.yaml new file mode 100755 index 0000000..ebf2a53 --- /dev/null +++ b/charts/substrate-faucet/templates/ksvc.yaml @@ -0,0 +1,51 @@ +{{- if .Values.knativeDeploy }} +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + {{- if .Values.service.name }} + name: {{ .Values.service.name }} + {{- else }} + name: {{ template "fullname" . }} + {{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.service.labels }} +{{ toYaml .Values.service.labels | indent 4 }} +{{- end }} +spec: + template: + metadata: + annotations: + autoscaling.knative.dev/minScale: "0" +{{- if .Values.podsLabels }} + labels: +{{ toYaml .Values.podsLabels | indent 8 }} +{{- end }} + spec: + containers: + - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: VERSION + value: {{ .Chart.Version }} +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ quote $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.livenessProbe.probePath | default .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + httpGet: + path: {{ .Values.readinessProbe.probePath | default .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 14 }} +{{- end }} diff --git a/charts/substrate-faucet/templates/sa.yaml b/charts/substrate-faucet/templates/sa.yaml new file mode 100755 index 0000000..c1f9836 --- /dev/null +++ b/charts/substrate-faucet/templates/sa.yaml @@ -0,0 +1,16 @@ +{{- if .Values.serviceAccount.enabled }} +apiVersion: v1 +kind: ServiceAccount +metadata: +{{- if .Values.serviceAccount.name }} + name: {{ .Values.serviceAccount.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + {{- if .Values.serviceAccount.labels }} + labels: {{- toYaml .Values.serviceAccount.labels | nindent 4 }} + {{- end }} + {{- if .Values.serviceAccount.annotations }} + annotations: {{ toYaml .Values.serviceAccount.annotations | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/substrate-faucet/templates/service.yaml b/charts/substrate-faucet/templates/service.yaml new file mode 100755 index 0000000..67664f3 --- /dev/null +++ b/charts/substrate-faucet/templates/service.yaml @@ -0,0 +1,29 @@ +{{- if or .Values.knativeDeploy .Values.canary.enabled }} +{{- else }} +apiVersion: v1 +kind: Service +metadata: +{{- if .Values.service.name }} + name: {{ .Values.service.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.service.labels }} +{{ toYaml .Values.service.labels | indent 4 }} +{{- end }} +{{- if .Values.service.annotations }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +{{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: http + selector: + app: {{ template "fullname" . }} +{{- end }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml new file mode 100755 index 0000000..8300ee0 --- /dev/null +++ b/charts/substrate-faucet/values.yaml @@ -0,0 +1,135 @@ +# Default values for your projects. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +# Add annotations to the pods +podAnnotations: {} +# Add labels to the pods +podsLabels: {} +# Add labels to the deployment +deploymentLabels: {} + +image: + repository: draft + tag: dev + pullPolicy: IfNotPresent + +# optional list of image pull secrets to use to pull images +jx: + # optional image pull secrets + imagePullSecrets: [] + + # whether to create a Release CRD when installing charts with Release CRDs included + releaseCRD: true + +# define environment variables here as a map of key: value +env: + +# enable this flag to use knative serve to deploy the app +knativeDeploy: false + +# HorizontalPodAutoscaler +hpa: + enabled: false + minReplicas: 2 + maxReplicas: 6 + cpuTargetAverageUtilization: 80 + memoryTargetAverageUtilization: 80 + # Add labels to the HPA + labels: {} + +# Canary deployments +# If enabled, Istio and Flagger need to be installed in the cluster +canary: + enabled: false + progressDeadlineSeconds: 60 + analysis: + interval: "1m" + threshold: 5 + maxWeight: 60 + stepWeight: 20 + # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. + metrics: + latency: + threshold: 500 + interval: "1m" + # The host is using Istio Gateway or the underlying ingress mechanism + # This value is defaulted from the environments jx-requirements.yml ingress configuration + host: "" + # Add labels to the canary + labels: {} + # Add labels to the canary gateway + gatewayLabels: {} + +service: + name: substrate-faucet + type: ClusterIP + externalPort: 80 + internalPort: 8080 + annotations: {} + # Add labels to the service + labels: {} +resources: + limits: + cpu: 400m + memory: 256Mi + requests: + cpu: 200m + memory: 128Mi +probePath: / +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + # Optional distinct liveness probe path, if empty the probePath is used + probePath: "" +readinessProbe: + failureThreshold: 1 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + # Optional distinct readiness probe path, if empty the probePath is used + probePath: "" + +# custom ingress annotations on this service +ingress: + annotations: {} + # defaults to nginx if no other ingress class annotation specified + classAnnotation: "" + # Add labels to the ingress + labels: {} + + # ingress path type + pathType: ImplementationSpecific + +serviceAccount: + enabled: true + name: "" + annotations: {} +# iam.gke.io/gcp-service-account: my-sa-in-gke + # Add labels to the SA + labels: {} +# my-custom-label: value + +# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 +jxRequirements: + ingress: + # shared ingress annotations on all services + annotations: {} + # kubernetes.io/ingress.class: nginx + + apiVersion: "networking.k8s.io/v1" + + # the domain for hosts + domain: "" + externalDNS: false + namespaceSubDomain: -jx. + serviceType: "" + tls: + email: "" + enabled: false + production: false + secretName: "" + + diff --git a/preview/Kptfile b/preview/Kptfile new file mode 100644 index 0000000..6e6ae8a --- /dev/null +++ b/preview/Kptfile @@ -0,0 +1,11 @@ +apiVersion: kpt.dev/v1alpha1 +kind: Kptfile +metadata: + name: preview +upstream: + type: git + git: + commit: b52b35506a05e046d54615c3ade97f3aef8bfb08 + repo: https://github.com/jenkins-x/jx3-pipeline-catalog + directory: /helm/preview + ref: master diff --git a/preview/helmfile.yaml b/preview/helmfile.yaml new file mode 100644 index 0000000..7485be5 --- /dev/null +++ b/preview/helmfile.yaml @@ -0,0 +1,31 @@ +environments: + default: + values: + - jx-values.yaml +repositories: +- name: jx3 + url: https://jenkins-x-charts.github.io/repo +releases: +- chart: jx3/jx-verify + name: jx-verify + namespace: '{{ requiredEnv "PREVIEW_NAMESPACE" }}' +- chart: '../charts/{{ requiredEnv "APP_NAME" }}' + name: preview + wait: true + createNamespace: true + namespace: '{{ requiredEnv "PREVIEW_NAMESPACE" }}' + values: + - jx-values.yaml + - values.yaml.gotmpl + hooks: + - events: ["presync"] + showlogs: true + command: "jx" + args: + - secret + - copy + - --create-namespace + - --selector + - "secret.jenkins-x.io/replica-source=true" + - --to + - '{{ requiredEnv "PREVIEW_NAMESPACE" }}' diff --git a/preview/values.yaml.gotmpl b/preview/values.yaml.gotmpl new file mode 100644 index 0000000..0283df2 --- /dev/null +++ b/preview/values.yaml.gotmpl @@ -0,0 +1,8 @@ +jxRequirements: + ingress: + namespaceSubDomain: "-pr{{ requiredEnv "PULL_NUMBER" }}." + +image: + repository: "{{ requiredEnv "DOCKER_REGISTRY" }}/{{ requiredEnv "DOCKER_REGISTRY_ORG" }}/{{ requiredEnv "APP_NAME" }}" + tag: "{{ requiredEnv "VERSION" }}" + pullPolicy: "Always" From eb92e48a1c26c37f44432797f83cd12ef80b54ce Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 25 Mar 2022 06:33:03 +0100 Subject: [PATCH 02/52] feat: added git ignore --- .gitignore | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de2d5e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,152 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ From 866705df29b532d632fa49a322dfd9f24b7c9752 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 25 Mar 2022 06:33:20 +0100 Subject: [PATCH 03/52] chore: updated dockerfile cmd --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d8b60dc..24c53e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,4 @@ COPY requirements.txt . ENV PORT 8080 EXPOSE 8080 ENTRYPOINT ["python"] -CMD ["app.py"] +CMD ["faucet.py"] From 912e540efcfcafeb8b89f7cea99aac17e574de4f Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 25 Mar 2022 06:33:28 +0100 Subject: [PATCH 04/52] feat: addded project requirements --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c04ed6c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +substrate-interface==1.2.2 +discord.py==1.7.3 \ No newline at end of file From fafb15cc1d2594eefc130ac9f0831aff96410fdd Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 25 Mar 2022 06:33:47 +0100 Subject: [PATCH 05/52] chore: updated cpu requests --- .lighthouse/jenkins-x/pullrequest.yaml | 6 +++--- .lighthouse/jenkins-x/release.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml index a0912eb..f4ccacc 100644 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -15,7 +15,7 @@ spec: name: "" resources: requests: - cpu: 400m + cpu: 50m memory: 512Mi workingDir: /workspace/source steps: @@ -24,8 +24,8 @@ spec: resources: {} - name: jx-variables resources: {} - - name: build-python-unittest - resources: {} + # - name: build-python-unittest + # resources: {} - name: check-registry resources: {} - name: build-container-build diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml index 699e67a..4698e78 100644 --- a/.lighthouse/jenkins-x/release.yaml +++ b/.lighthouse/jenkins-x/release.yaml @@ -15,7 +15,7 @@ spec: name: "" resources: requests: - cpu: 400m + cpu: 50m memory: 512Mi workingDir: /workspace/source steps: From d48cb3ba9ca40d8cb91d0c1b1e532bd6dd6a7ee1 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 25 Mar 2022 07:18:28 +0100 Subject: [PATCH 06/52] feat: Dockerized app feat: environment variables used for config chore: readme updates --- Dockerfile | 12 ++++++++++-- README.md | 24 +++++++++--------------- faucet.py | 34 ++++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 24c53e0..0f650bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,14 @@ -FROM python:onbuild -COPY requirements.txt . +FROM python:3.8 + +WORKDIR /app + +COPY ["requirements.txt", "/app/"] +RUN pip install -r requirements.txt + +COPY ["faucet.py", "/app/"] + ENV PORT 8080 EXPOSE 8080 + ENTRYPOINT ["python"] CMD ["faucet.py"] diff --git a/README.md b/README.md index e842f0b..25ea0e8 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,12 @@ This bot is a really simple bot without security or threshold. It's used to send ## How to use : -- create a discord bot -- create a substrate address -- configure : - -``` -TOKEN = 'Your_Discord_Bot_Token' -``` -``` -faucet_mnemonic = 'Your Substrate Mnemonic' -``` - -``` -# usually you run it on the same server than the node -node_rpc = "http://127.0.0.1:9933" -``` +Following environment variables should be defined + +|Key|Description| +|---|---| +|DISCORD_BOT_TOKEN|The secret bot token to use for connecting to discord| +|NODE_RPC|https://wss.test.peaq.network| +|FAUCET_MNEMONIC|use the value from subkey generate| +|TOKENS_TO_SEND|100 * 10**12| +|CURRENCY_SYMBOL|PEAQ| diff --git a/faucet.py b/faucet.py index d33dec4..37023d2 100644 --- a/faucet.py +++ b/faucet.py @@ -1,4 +1,5 @@ import os +import time import random import discord from discord.ext import commands @@ -6,14 +7,28 @@ from substrateinterface.exceptions import SubstrateRequestException from substrateinterface.utils.ss58 import ss58_encode +def get_env_var_or_exit(var_name): + var = os.environ.get(var_name) + + if var == None or len(var) == 0: + print("Please check if [{}] is defined. Will exit after 30s sleep".format(var_name)) + time.sleep(30) + import sys + sys.exit(1) + + return var + # Your Discord bot token -TOKEN = '' -faucet_mnemonic = '' +DISCORD_BOT_TOKEN = get_env_var_or_exit("DISCORD_BOT_TOKEN") +NODE_RPC = get_env_var_or_exit("NODE_RPC") +FAUCET_MNEMONIC = get_env_var_or_exit("FAUCET_MNEMONIC") +TOKENS_TO_SEND = get_env_var_or_exit("TOKENS_TO_SEND") +CURRENCY_SYMBOL = get_env_var_or_exit("CURRENCY_SYMBOL") + # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') -keypair = Keypair.create_from_mnemonic('faucet_mnemonic') -# substrate RPC node -node_rpc = "http://127.0.0.1:9933" +keypair = Keypair.create_from_mnemonic(FAUCET_MNEMONIC) + @bot.command(name='send', help='Send token from faucet') async def nine_nine(ctx, arg): @@ -22,7 +37,7 @@ async def nine_nine(ctx, arg): await ctx.send("Hold on Capt'ain, you can't send me private messages !") else: substrate = SubstrateInterface( - url=node_rpc, + url=NODE_RPC, address_type=42, type_registry_preset='substrate-node-template' ) @@ -31,13 +46,12 @@ async def nine_nine(ctx, arg): call_function='transfer', call_params={ 'dest': arg, - 'value': 100 * 10**12 + 'value': TOKENS_TO_SEND } ) reply = "" - keypair = Keypair.create_from_mnemonic(faucet_mnemonic) extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair) reply = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=False) - await ctx.send(ctx.author.mention + " Awesome, you just received 100 dPIRL, it has no real value it's only the testnet token :) " + reply['extrinsic_hash'] + str(ctx.channel.type)) + await ctx.send(ctx.author.mention + " Awesome, you just received {} {}, it has no real value it's only the testnet token :) ".format(TOKENS_TO_SEND, CURRENCY_SYMBOL) + reply['extrinsic_hash'] + str(ctx.channel.type)) -bot.run(TOKEN) +bot.run(DISCORD_BOT_TOKEN) From 703f2e0d460b27ab9be94c955a559cfaa7c31b9d Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 31 Mar 2022 17:49:02 +0200 Subject: [PATCH 07/52] feat: parameterized through env variables feat: abuse prevention by request periods --- .dockerignore | 0 app/.gitignore | 1 + faucet.py => app/faucet.py | 39 ++++++++++++++++++++++++++++++-------- requirements.txt | 3 ++- 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 app/.gitignore rename faucet.py => app/faucet.py (57%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..e0e6347 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +run.sh \ No newline at end of file diff --git a/faucet.py b/app/faucet.py similarity index 57% rename from faucet.py rename to app/faucet.py index 37023d2..7d2e564 100644 --- a/faucet.py +++ b/app/faucet.py @@ -1,7 +1,7 @@ import os +from pickletools import read_decimalnl_short import time -import random -import discord +import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair from substrateinterface.exceptions import SubstrateRequestException @@ -20,10 +20,19 @@ def get_env_var_or_exit(var_name): # Your Discord bot token DISCORD_BOT_TOKEN = get_env_var_or_exit("DISCORD_BOT_TOKEN") +#the address of our network NODE_RPC = get_env_var_or_exit("NODE_RPC") +#to construct the private/public key pair FAUCET_MNEMONIC = get_env_var_or_exit("FAUCET_MNEMONIC") +#how many tokens to send, on peaq network 1 PEAQ = 1,000,000,000,000,000,000 TOKENS_TO_SEND = get_env_var_or_exit("TOKENS_TO_SEND") -CURRENCY_SYMBOL = get_env_var_or_exit("CURRENCY_SYMBOL") +#the token symbol +TOKEN_SYMBOL = get_env_var_or_exit("TOKEN_SYMBOL") +#how often can a user ask for a token? in seconds +ISSUE_INTERVAL = get_env_var_or_exit("ISSUE_INTERVAL") +#redis +REDIS_IP = get_env_var_or_exit("REDIS_IP") +REDIS_PORT = get_env_var_or_exit("REDIS_PORT") # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') @@ -32,14 +41,24 @@ def get_env_var_or_exit(var_name): @bot.command(name='send', help='Send token from faucet') async def nine_nine(ctx, arg): - if (ctx.channel.type == "private"): + + if (str(ctx.channel.type) == "private"): # Forbid DM in discord await ctx.send("Hold on Capt'ain, you can't send me private messages !") else: + + #ensure we comply with send frequency + r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) + if r.exists(arg): + await ctx.send("You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + return + else: + r.set(name=arg,value="set") + r.expire(arg,ISSUE_INTERVAL) + + substrate = SubstrateInterface( - url=NODE_RPC, - address_type=42, - type_registry_preset='substrate-node-template' + url=NODE_RPC ) call = substrate.compose_call( call_module='Balances', @@ -52,6 +71,10 @@ async def nine_nine(ctx, arg): reply = "" extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair) reply = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=False) - await ctx.send(ctx.author.mention + " Awesome, you just received {} {}, it has no real value it's only the testnet token :) ".format(TOKENS_TO_SEND, CURRENCY_SYMBOL) + reply['extrinsic_hash'] + str(ctx.channel.type)) + + msg = " Awesome, you just received \"{}\" {}! The extrinsic hash is [{}]".format(int(TOKENS_TO_SEND)/1000000000000000000, TOKEN_SYMBOL, reply['extrinsic_hash']) + await ctx.send(str(ctx.author.mention) + msg) + print(str(ctx.author.name) + msg) +print("Starting bot") bot.run(DISCORD_BOT_TOKEN) diff --git a/requirements.txt b/requirements.txt index c04ed6c..32aed38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ substrate-interface==1.2.2 -discord.py==1.7.3 \ No newline at end of file +discord.py==1.7.3 +redis==4.1.4 \ No newline at end of file From 6893785179cf4939e53e846ded14220e0f246554 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 31 Mar 2022 18:36:55 +0200 Subject: [PATCH 08/52] feat: chart customization feat: documentation update --- .dockerignore | 5 ++ .gitignore | 2 + .lighthouse/jenkins-x/pullrequest.yaml | 3 ++ .lighthouse/jenkins-x/release.yaml | 3 ++ README.md | 46 +++++++++++++++++-- .../templates/deployment.yaml | 19 ++++++++ charts/substrate-faucet/values.yaml | 29 ++++++------ 7 files changed, 91 insertions(+), 16 deletions(-) diff --git a/.dockerignore b/.dockerignore index e69de29..76b7895 100644 --- a/.dockerignore +++ b/.dockerignore @@ -0,0 +1,5 @@ +.lighthouse +charts/* +preview/* +test-net-faucet-bot-config.yaml +test-net-faucet-bot-secret.yaml \ No newline at end of file diff --git a/.gitignore b/.gitignore index de2d5e0..97a6f75 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +test-net-faucet-bot-config.yaml +test-net-faucet-bot-secret.yaml \ No newline at end of file diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml index f4ccacc..673a399 100644 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -16,6 +16,9 @@ spec: resources: requests: cpu: 50m + memory: 256Mi + limits: + cpu: 100m memory: 512Mi workingDir: /workspace/source steps: diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml index 4698e78..b186979 100644 --- a/.lighthouse/jenkins-x/release.yaml +++ b/.lighthouse/jenkins-x/release.yaml @@ -16,6 +16,9 @@ spec: resources: requests: cpu: 50m + memory: 256Mi + limits: + cpu: 100m memory: 512Mi workingDir: /workspace/source steps: diff --git a/README.md b/README.md index 25ea0e8..99846fa 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,52 @@ This bot is a really simple bot without security or threshold. It's used to send ## How to use : -Following environment variables should be defined +A configmap named "test-net-faucet-bot-config" can be used to override the default values as specified in the following table +Please adapt to your target namespace + +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-net-faucet-bot-config + namespace: jx-devbr +data: + DISCORD_BOT_TOKEN: very + FAUCET_MNEMONIC: charm +``` + + +Default values are as follows |Key|Description| |---|---| |DISCORD_BOT_TOKEN|The secret bot token to use for connecting to discord| |NODE_RPC|https://wss.test.peaq.network| |FAUCET_MNEMONIC|use the value from subkey generate| -|TOKENS_TO_SEND|100 * 10**12| -|CURRENCY_SYMBOL|PEAQ| +|TOKENS_TO_SEND|1000000000000000000| +|TOKEN_SYMBOL|PEAQ| +|ISSUE_INTERVAL|5| +|REDIS_IP|127.0.0.1| +|REDIS_PORT|6379| + + +Additionally a secret must be created under the name of "test-net-faucet-bot-secret" containing the bot token and key mnemonic. +Remember to change the DISCORD_BOT_TOKEN and FAUCET_MNEMONIC variable's data to actual values. +Use the following command to encode to base64 + +```bash +#encode with disabled line wrapping +echo -n 'secret here' | base64 -w 0 +``` + +```yaml +apiVersion: v1 +data: + DISCORD_BOT_TOKEN: bXlwYXNzd29yZA== + FAUCET_MNEMONIC: bXlwYXNzd29yZA== +kind: Secret +metadata: + name: test-net-faucet-bot-secret + namespace: jx-devbr +type: Opaque +``` \ No newline at end of file diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index a5e4c62..36a786a 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -39,6 +39,25 @@ spec: {{- end }} {{- end }} containers: + - name: redis + image: redis:5.0.4 + ports: + - containerPort: 6379 + resources: + requests: + cpu: 50m + memory: 100Mi + readinessProbe: + tcpSocket: + port: 6379 + initialDelaySeconds: 30 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: 6379 + initialDelaySeconds: 30 + periodSeconds: 20 + - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 8300ee0..47ee247 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,15 +24,26 @@ jx: # define environment variables here as a map of key: value env: + - DISCORD_BOT_TOKEN="" + - NODE_RPC=wss://wss.test.peaq.network + - FAUCET_MNEMONIC="" + - TOKENS_TO_SEND=1000000000000000000 + - TOKEN_SYMBOL="PEAQ" + - ISSUE_INTERVAL=5 + - REDIS_IP=127.0.0.1 + - REDIS_PORT=6379 + +envFrom: + - test-net-faucet-bot-config # enable this flag to use knative serve to deploy the app knativeDeploy: false # HorizontalPodAutoscaler hpa: - enabled: false - minReplicas: 2 - maxReplicas: 6 + enabled: true + minReplicas: 1 + maxReplicas: 4 cpuTargetAverageUtilization: 80 memoryTargetAverageUtilization: 80 # Add labels to the HPA @@ -61,20 +72,12 @@ canary: # Add labels to the canary gateway gatewayLabels: {} -service: - name: substrate-faucet - type: ClusterIP - externalPort: 80 - internalPort: 8080 - annotations: {} - # Add labels to the service - labels: {} resources: limits: - cpu: 400m + cpu: 100m memory: 256Mi requests: - cpu: 200m + cpu: 50m memory: 128Mi probePath: / livenessProbe: From 233c977ff8ee4a15508fd558656bf2daab477658 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 10:35:40 +0200 Subject: [PATCH 09/52] chore: bot secrets --- charts/substrate-faucet/templates/deployment.yaml | 14 ++++++++++++++ charts/substrate-faucet/values.yaml | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 36a786a..140ba4f 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -64,6 +64,20 @@ spec: env: - name: VERSION value: {{ .Chart.Version }} + - name: DISCORD_BOT_TOKEN + valueFrom: + secretKeyRef: + name: {{ .Values.botSecrets.name }} + namespace: {{ .Values.botSecrets.namespace }} + key: DISCORD_BOT_TOKEN + optional: false + - name: FAUCET_MNEMONIC + valueFrom: + secretKeyRef: + name: {{ .Values.botSecrets.name }} + namespace: {{ .Values.botSecrets.namespace }} + key: FAUCET_MNEMONIC + optional: false {{- range $pkey, $pval := .Values.env }} - name: {{ $pkey }} value: {{ quote $pval }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 47ee247..9bab19e 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -36,6 +36,10 @@ env: envFrom: - test-net-faucet-bot-config +botSecrets: + namespace: default + name: test-net-faucet-bot-secret + # enable this flag to use knative serve to deploy the app knativeDeploy: false From d2b03ecd944d2958e76d89a8320e0976711c578e Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 10:50:05 +0200 Subject: [PATCH 10/52] fix: paths chore: adjusted limits for build --- .lighthouse/jenkins-x/pullrequest.yaml | 4 ++-- .lighthouse/jenkins-x/release.yaml | 4 ++-- Dockerfile | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml index 673a399..b51d38a 100644 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -15,10 +15,10 @@ spec: name: "" resources: requests: - cpu: 50m + cpu: 100m memory: 256Mi limits: - cpu: 100m + cpu: 200m memory: 512Mi workingDir: /workspace/source steps: diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml index b186979..922b6cd 100644 --- a/.lighthouse/jenkins-x/release.yaml +++ b/.lighthouse/jenkins-x/release.yaml @@ -15,10 +15,10 @@ spec: name: "" resources: requests: - cpu: 50m + cpu: 100m memory: 256Mi limits: - cpu: 100m + cpu: 200m memory: 512Mi workingDir: /workspace/source steps: diff --git a/Dockerfile b/Dockerfile index 0f650bf..3cfe3af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,8 @@ WORKDIR /app COPY ["requirements.txt", "/app/"] RUN pip install -r requirements.txt -COPY ["faucet.py", "/app/"] - -ENV PORT 8080 -EXPOSE 8080 +COPY ["app/faucet.py", "/app/"] +WORKDIR /app ENTRYPOINT ["python"] CMD ["faucet.py"] From 5cef569a7eb2083f854ee85fa8d81a93ecebe5e0 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:04:30 +0200 Subject: [PATCH 11/52] fix: restore service values --- charts/substrate-faucet/values.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 9bab19e..b059488 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -40,12 +40,21 @@ botSecrets: namespace: default name: test-net-faucet-bot-secret +service: + name: substrate-faucet + type: ClusterIP + externalPort: 80 + internalPort: 8080 + annotations: {} + # Add labels to the service + labels: {} + # enable this flag to use knative serve to deploy the app knativeDeploy: false # HorizontalPodAutoscaler hpa: - enabled: true + enabled: false minReplicas: 1 maxReplicas: 4 cpuTargetAverageUtilization: 80 From cc9bf253aa287c8fced53180a6ca492cc9dce0b7 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:18:28 +0200 Subject: [PATCH 12/52] feat: added promethus stats --- README.md | 1 + app/faucet.py | 26 +++++++++++++++++++++++++- charts/substrate-faucet/values.yaml | 1 + requirements.txt | 3 ++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99846fa..b51fd26 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Default values are as follows |ISSUE_INTERVAL|5| |REDIS_IP|127.0.0.1| |REDIS_PORT|6379| +|PROMETHEUS_PORT|8080| Additionally a secret must be created under the name of "test-net-faucet-bot-secret" containing the bot token and key mnemonic. diff --git a/app/faucet.py b/app/faucet.py index 7d2e564..fe5fa72 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -1,11 +1,18 @@ import os from pickletools import read_decimalnl_short import time +from threading import Thread import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair from substrateinterface.exceptions import SubstrateRequestException from substrateinterface.utils.ss58 import ss58_encode +from prometheus_client import start_http_server, Counter + +# prometheus metrics +INVOCATION_COUNT = Counter('invocation_count', 'Number of times tokens have been requested.') +ISSUANCE_TOTAL = Counter('issuance_total', 'Total tokens issued.') +ISSUANCE_THROTTLED = Counter('issuance_throttled', 'Total issuance requests throttled (too quickly requested again).') def get_env_var_or_exit(var_name): var = os.environ.get(var_name) @@ -33,15 +40,18 @@ def get_env_var_or_exit(var_name): #redis REDIS_IP = get_env_var_or_exit("REDIS_IP") REDIS_PORT = get_env_var_or_exit("REDIS_PORT") +#prometheus +PROMETHEUS_PORT = get_env_var_or_exit("PROMETHEUS_PORT") # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') keypair = Keypair.create_from_mnemonic(FAUCET_MNEMONIC) - @bot.command(name='send', help='Send token from faucet') async def nine_nine(ctx, arg): + INVOCATION_COUNT.inc() + if (str(ctx.channel.type) == "private"): # Forbid DM in discord await ctx.send("Hold on Capt'ain, you can't send me private messages !") @@ -51,6 +61,7 @@ async def nine_nine(ctx, arg): r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) if r.exists(arg): await ctx.send("You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + ISSUANCE_THROTTLED.inc() return else: r.set(name=arg,value="set") @@ -72,9 +83,22 @@ async def nine_nine(ctx, arg): extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair) reply = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=False) + # inform user msg = " Awesome, you just received \"{}\" {}! The extrinsic hash is [{}]".format(int(TOKENS_TO_SEND)/1000000000000000000, TOKEN_SYMBOL, reply['extrinsic_hash']) await ctx.send(str(ctx.author.mention) + msg) + + # log to console print(str(ctx.author.name) + msg) + + # store metrics + ISSUANCE_TOTAL.inc(int(TOKENS_TO_SEND)/1000000000000000000) + +def prometheus_server(): + start_http_server(int(PROMETHEUS_PORT)) + +print("Starting prometheus server") +t_prometheus = Thread(target=prometheus_server) +t_prometheus.start() print("Starting bot") bot.run(DISCORD_BOT_TOKEN) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index b059488..b9a641c 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -32,6 +32,7 @@ env: - ISSUE_INTERVAL=5 - REDIS_IP=127.0.0.1 - REDIS_PORT=6379 + - PROMETHEUS_PORT=8080 envFrom: - test-net-faucet-bot-config diff --git a/requirements.txt b/requirements.txt index 32aed38..a64936c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ substrate-interface==1.2.2 discord.py==1.7.3 -redis==4.1.4 \ No newline at end of file +redis==4.1.4 +prometheus-client==0.13.1 \ No newline at end of file From 4a8537d2828421a718dae593b98537efebbf2668 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:31:43 +0200 Subject: [PATCH 13/52] chore: fix arg length (addr len) to 48 --- app/faucet.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/faucet.py b/app/faucet.py index fe5fa72..59dae74 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -52,6 +52,9 @@ async def nine_nine(ctx, arg): INVOCATION_COUNT.inc() + if arg != None and len(arg) != 48: + return + if (str(ctx.channel.type) == "private"): # Forbid DM in discord await ctx.send("Hold on Capt'ain, you can't send me private messages !") From fb4f6bd4beef5a71ec70d88e237d263aa5797e81 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:42:57 +0200 Subject: [PATCH 14/52] fix: indent --- .../templates/deployment.yaml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 140ba4f..24e8b1a 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -66,18 +66,18 @@ spec: value: {{ .Chart.Version }} - name: DISCORD_BOT_TOKEN valueFrom: - secretKeyRef: - name: {{ .Values.botSecrets.name }} - namespace: {{ .Values.botSecrets.namespace }} - key: DISCORD_BOT_TOKEN - optional: false + secretKeyRef: + name: {{ .Values.botSecrets.name }} + namespace: {{ .Values.botSecrets.namespace }} + key: DISCORD_BOT_TOKEN + optional: false - name: FAUCET_MNEMONIC valueFrom: - secretKeyRef: - name: {{ .Values.botSecrets.name }} - namespace: {{ .Values.botSecrets.namespace }} - key: FAUCET_MNEMONIC - optional: false + secretKeyRef: + name: {{ .Values.botSecrets.name }} + namespace: {{ .Values.botSecrets.namespace }} + key: FAUCET_MNEMONIC + optional: false {{- range $pkey, $pval := .Values.env }} - name: {{ $pkey }} value: {{ quote $pval }} From 0a59e14ae5665e6b7fdb9c5b3047d02fc69cddd9 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:57:48 +0200 Subject: [PATCH 15/52] fix: invalid tag removed --- charts/substrate-faucet/templates/deployment.yaml | 2 -- charts/substrate-faucet/values.yaml | 1 - 2 files changed, 3 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 24e8b1a..76fc509 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -68,14 +68,12 @@ spec: valueFrom: secretKeyRef: name: {{ .Values.botSecrets.name }} - namespace: {{ .Values.botSecrets.namespace }} key: DISCORD_BOT_TOKEN optional: false - name: FAUCET_MNEMONIC valueFrom: secretKeyRef: name: {{ .Values.botSecrets.name }} - namespace: {{ .Values.botSecrets.namespace }} key: FAUCET_MNEMONIC optional: false {{- range $pkey, $pval := .Values.env }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index b9a641c..4ccec62 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -38,7 +38,6 @@ envFrom: - test-net-faucet-bot-config botSecrets: - namespace: default name: test-net-faucet-bot-secret service: From 4f5dbc8c5c004c9ad335917008a0a5cb3f8d0923 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:38:02 +0200 Subject: [PATCH 16/52] fix: config map --- charts/substrate-faucet/values.yaml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 4ccec62..ce6a19a 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,18 +24,19 @@ jx: # define environment variables here as a map of key: value env: - - DISCORD_BOT_TOKEN="" - - NODE_RPC=wss://wss.test.peaq.network - - FAUCET_MNEMONIC="" - - TOKENS_TO_SEND=1000000000000000000 - - TOKEN_SYMBOL="PEAQ" - - ISSUE_INTERVAL=5 - - REDIS_IP=127.0.0.1 - - REDIS_PORT=6379 - - PROMETHEUS_PORT=8080 + DISCORD_BOT_TOKEN="" + NODE_RPC=wss://wss.test.peaq.network + FAUCET_MNEMONIC="" + TOKENS_TO_SEND=1000000000000000000 + TOKEN_SYMBOL="PEAQ" + ISSUE_INTERVAL=5 + REDIS_IP=127.0.0.1 + REDIS_PORT=6379 + PROMETHEUS_PORT=8080 envFrom: - - test-net-faucet-bot-config + - configMapRef: + name: test-net-faucet-bot-config botSecrets: name: test-net-faucet-bot-secret From c6dbe269ff51de4ea10c3acf5a0e3369ab9af613 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:46:10 +0200 Subject: [PATCH 17/52] fix: env list update --- charts/substrate-faucet/values.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index ce6a19a..956afe2 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,15 +24,15 @@ jx: # define environment variables here as a map of key: value env: - DISCORD_BOT_TOKEN="" - NODE_RPC=wss://wss.test.peaq.network - FAUCET_MNEMONIC="" - TOKENS_TO_SEND=1000000000000000000 - TOKEN_SYMBOL="PEAQ" - ISSUE_INTERVAL=5 - REDIS_IP=127.0.0.1 - REDIS_PORT=6379 - PROMETHEUS_PORT=8080 + - DISCORD_BOT_TOKEN: "" + - NODE_RPC: wss://wss.test.peaq.network + - FAUCET_MNEMONIC: "" + - TOKENS_TO_SEND: 1000000000000000000 + - TOKEN_SYMBOL: "PEAQ" + - ISSUE_INTERVAL: 5 + - REDIS_IP: 127.0.0.1 + - REDIS_PORT: 6379 + - PROMETHEUS_PORT: 8080 envFrom: - configMapRef: From c79a19eac94c2d14b5b588bbfd33a48a9a46d502 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:59:29 +0200 Subject: [PATCH 18/52] fix: rectified env list --- charts/substrate-faucet/values.yaml | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 956afe2..dd06f4b 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,15 +24,24 @@ jx: # define environment variables here as a map of key: value env: - - DISCORD_BOT_TOKEN: "" - - NODE_RPC: wss://wss.test.peaq.network - - FAUCET_MNEMONIC: "" - - TOKENS_TO_SEND: 1000000000000000000 - - TOKEN_SYMBOL: "PEAQ" - - ISSUE_INTERVAL: 5 - - REDIS_IP: 127.0.0.1 - - REDIS_PORT: 6379 - - PROMETHEUS_PORT: 8080 + - name: "DISCORD_BOT_TOKEN" + value: "" + - name: NODE_RPC + value: "wss://wss.test.peaq.network" + - name: "FAUCET_MNEMONIC" + value: "" + - name: "TOKENS_TO_SEND" + value: 1000000000000000000 + - name: "TOKEN_SYMBOL" + value: "PEAQ" + - name: "ISSUE_INTERVAL" + value: 5 + - name: "REDIS_IP" + value: 127.0.0.1 + - name: "REDIS_PORT" + value: 6379 + - name: "PROMETHEUS_PORT" + value: 8080 envFrom: - configMapRef: From 312e3e47f35bed8d38fe661c3e64248bc8edad56 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:12:39 +0200 Subject: [PATCH 19/52] fix: names updated --- charts/substrate-faucet/values.yaml | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index dd06f4b..8971550 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,24 +24,24 @@ jx: # define environment variables here as a map of key: value env: - - name: "DISCORD_BOT_TOKEN" - value: "" - - name: NODE_RPC - value: "wss://wss.test.peaq.network" - - name: "FAUCET_MNEMONIC" - value: "" - - name: "TOKENS_TO_SEND" - value: 1000000000000000000 - - name: "TOKEN_SYMBOL" - value: "PEAQ" - - name: "ISSUE_INTERVAL" - value: 5 - - name: "REDIS_IP" - value: 127.0.0.1 - - name: "REDIS_PORT" - value: 6379 - - name: "PROMETHEUS_PORT" - value: 8080 + - pkey: "DISCORD_BOT_TOKEN" + pval: "" + - pkey: NODE_RPC + pval: "wss://wss.test.peaq.network" + - pkey: "FAUCET_MNEMONIC" + pval: "" + - pkey: "TOKENS_TO_SEND" + pval: 1000000000000000000 + - pkey: "TOKEN_SYMBOL" + pval: "PEAQ" + - pkey: "ISSUE_INTERVAL" + pval: 5 + - pkey: "REDIS_IP" + pval: 127.0.0.1 + - pkey: "REDIS_PORT" + pval: 6379 + - pkey: "PROMETHEUS_PORT" + pval: 8080 envFrom: - configMapRef: From 60bb2f70e57d1f648c67649b7de3df4c91283d3a Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:31:10 +0200 Subject: [PATCH 20/52] fix: dedicated config --- .../templates/deployment.yaml | 15 +++++++++++ charts/substrate-faucet/values.yaml | 27 +++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 76fc509..3c921ef 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -76,6 +76,21 @@ spec: name: {{ .Values.botSecrets.name }} key: FAUCET_MNEMONIC optional: false + - name: NODE_RPC + value: {{ .Values.botConfig.NODE_RPC }} + - name: TOKENS_TO_SEND + value: {{ .Values.botConfig.TOKENS_TO_SEND }} + - name: TOKEN_SYMBOL + value: {{ .Values.botConfig.TOKEN_SYMBOL }} + - name: ISSUE_INTERVAL + value: {{ .Values.botConfig.ISSUE_INTERVAL }} + - name: REDIS_IP + value: {{ .Values.botConfig.REDIS_IP }} + - name: REDIS_PORT + value: {{ .Values.botConfig.REDIS_PORT }} + - name: PROMETHEUS_PORT + value: {{ .Values.botConfig.PROMETHEUS_PORT }} + {{- range $pkey, $pval := .Values.env }} - name: {{ $pkey }} value: {{ quote $pval }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 8971550..54da7ea 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,29 +24,20 @@ jx: # define environment variables here as a map of key: value env: - - pkey: "DISCORD_BOT_TOKEN" - pval: "" - - pkey: NODE_RPC - pval: "wss://wss.test.peaq.network" - - pkey: "FAUCET_MNEMONIC" - pval: "" - - pkey: "TOKENS_TO_SEND" - pval: 1000000000000000000 - - pkey: "TOKEN_SYMBOL" - pval: "PEAQ" - - pkey: "ISSUE_INTERVAL" - pval: 5 - - pkey: "REDIS_IP" - pval: 127.0.0.1 - - pkey: "REDIS_PORT" - pval: 6379 - - pkey: "PROMETHEUS_PORT" - pval: 8080 envFrom: - configMapRef: name: test-net-faucet-bot-config +botConfig: + NODE_RPC: "wss://wss.test.peaq.network" + TOKENS_TO_SEND: 1000000000000000000 + TOKEN_SYMBOL: "PEAQ" + ISSUE_INTERVAL: 5 + REDIS_IP: "127.0.0.1" + REDIS_PORT: 6379 + PROMETHEUS_PORT: 8080 + botSecrets: name: test-net-faucet-bot-secret From 91c012f536747c5ffffecf1243d5bd19b9c139dc Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:45:08 +0200 Subject: [PATCH 21/52] fix: variables to strings --- app/faucet.py | 8 ++++---- charts/substrate-faucet/values.yaml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 59dae74..c3d45d7 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -32,7 +32,7 @@ def get_env_var_or_exit(var_name): #to construct the private/public key pair FAUCET_MNEMONIC = get_env_var_or_exit("FAUCET_MNEMONIC") #how many tokens to send, on peaq network 1 PEAQ = 1,000,000,000,000,000,000 -TOKENS_TO_SEND = get_env_var_or_exit("TOKENS_TO_SEND") +TOKENS_TO_SEND = int(get_env_var_or_exit("TOKENS_TO_SEND")) #the token symbol TOKEN_SYMBOL = get_env_var_or_exit("TOKEN_SYMBOL") #how often can a user ask for a token? in seconds @@ -61,7 +61,7 @@ async def nine_nine(ctx, arg): else: #ensure we comply with send frequency - r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) + r = redis.Redis(host=REDIS_IP, port=int(REDIS_PORT)) if r.exists(arg): await ctx.send("You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) ISSUANCE_THROTTLED.inc() @@ -87,14 +87,14 @@ async def nine_nine(ctx, arg): reply = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=False) # inform user - msg = " Awesome, you just received \"{}\" {}! The extrinsic hash is [{}]".format(int(TOKENS_TO_SEND)/1000000000000000000, TOKEN_SYMBOL, reply['extrinsic_hash']) + msg = " Awesome, you just received \"{}\" {}! The extrinsic hash is [{}]".format(TOKENS_TO_SEND/1000000000000000000, TOKEN_SYMBOL, reply['extrinsic_hash']) await ctx.send(str(ctx.author.mention) + msg) # log to console print(str(ctx.author.name) + msg) # store metrics - ISSUANCE_TOTAL.inc(int(TOKENS_TO_SEND)/1000000000000000000) + ISSUANCE_TOTAL.inc(TOKENS_TO_SEND/1000000000000000000) def prometheus_server(): start_http_server(int(PROMETHEUS_PORT)) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 54da7ea..7282d94 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -31,12 +31,12 @@ envFrom: botConfig: NODE_RPC: "wss://wss.test.peaq.network" - TOKENS_TO_SEND: 1000000000000000000 + TOKENS_TO_SEND: "1000000000000000000" TOKEN_SYMBOL: "PEAQ" ISSUE_INTERVAL: 5 REDIS_IP: "127.0.0.1" - REDIS_PORT: 6379 - PROMETHEUS_PORT: 8080 + REDIS_PORT: "6379" + PROMETHEUS_PORT: "8080" botSecrets: name: test-net-faucet-bot-secret From fe566d00cd623bb0d83d3282707c2e5e70bc5c9f Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 14:11:04 +0200 Subject: [PATCH 22/52] fix: disabled dynamic env --- charts/substrate-faucet/templates/deployment.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 3c921ef..27d7f55 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -91,12 +91,12 @@ spec: - name: PROMETHEUS_PORT value: {{ .Values.botConfig.PROMETHEUS_PORT }} -{{- range $pkey, $pval := .Values.env }} +{% comment %} {{- range $pkey, $pval := .Values.env }} - name: {{ $pkey }} value: {{ quote $pval }} {{- end }} envFrom: -{{ toYaml .Values.envFrom | indent 10 }} +{{ toYaml .Values.envFrom | indent 10 }} {% endcomment %} ports: - name: http containerPort: {{ .Values.service.internalPort }} From bf1ce4cbc6a6dfed26bb19f1140b80aafa68c670 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 14:38:20 +0200 Subject: [PATCH 23/52] fix: env variables adjusted --- app/faucet.py | 10 ++++----- .../templates/deployment.yaml | 21 +++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index c3d45d7..bcd652d 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -36,12 +36,12 @@ def get_env_var_or_exit(var_name): #the token symbol TOKEN_SYMBOL = get_env_var_or_exit("TOKEN_SYMBOL") #how often can a user ask for a token? in seconds -ISSUE_INTERVAL = get_env_var_or_exit("ISSUE_INTERVAL") +ISSUE_INTERVAL = int(get_env_var_or_exit("ISSUE_INTERVAL")) #redis REDIS_IP = get_env_var_or_exit("REDIS_IP") -REDIS_PORT = get_env_var_or_exit("REDIS_PORT") +REDIS_PORT = int(get_env_var_or_exit("REDIS_PORT")) #prometheus -PROMETHEUS_PORT = get_env_var_or_exit("PROMETHEUS_PORT") +PROMETHEUS_PORT = int(get_env_var_or_exit("PROMETHEUS_PORT")) # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') @@ -61,7 +61,7 @@ async def nine_nine(ctx, arg): else: #ensure we comply with send frequency - r = redis.Redis(host=REDIS_IP, port=int(REDIS_PORT)) + r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) if r.exists(arg): await ctx.send("You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) ISSUANCE_THROTTLED.inc() @@ -97,7 +97,7 @@ async def nine_nine(ctx, arg): ISSUANCE_TOTAL.inc(TOKENS_TO_SEND/1000000000000000000) def prometheus_server(): - start_http_server(int(PROMETHEUS_PORT)) + start_http_server(PROMETHEUS_PORT) print("Starting prometheus server") t_prometheus = Thread(target=prometheus_server) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 27d7f55..98bd943 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -77,26 +77,19 @@ spec: key: FAUCET_MNEMONIC optional: false - name: NODE_RPC - value: {{ .Values.botConfig.NODE_RPC }} + value: "{{ .Values.botConfig.NODE_RPC }}" - name: TOKENS_TO_SEND - value: {{ .Values.botConfig.TOKENS_TO_SEND }} + value: "{{ .Values.botConfig.TOKENS_TO_SEND }}" - name: TOKEN_SYMBOL - value: {{ .Values.botConfig.TOKEN_SYMBOL }} + value: "{{ .Values.botConfig.TOKEN_SYMBOL }}" - name: ISSUE_INTERVAL - value: {{ .Values.botConfig.ISSUE_INTERVAL }} + value: "{{ .Values.botConfig.ISSUE_INTERVAL }}" - name: REDIS_IP - value: {{ .Values.botConfig.REDIS_IP }} + value: "{{ .Values.botConfig.REDIS_IP }}" - name: REDIS_PORT - value: {{ .Values.botConfig.REDIS_PORT }} + value: "{{ .Values.botConfig.REDIS_PORT }}" - name: PROMETHEUS_PORT - value: {{ .Values.botConfig.PROMETHEUS_PORT }} - -{% comment %} {{- range $pkey, $pval := .Values.env }} - - name: {{ $pkey }} - value: {{ quote $pval }} -{{- end }} - envFrom: -{{ toYaml .Values.envFrom | indent 10 }} {% endcomment %} + value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" ports: - name: http containerPort: {{ .Values.service.internalPort }} From 0931bd6901efcf16263f44258c1653be6aa8c2ec Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:53:16 +0200 Subject: [PATCH 24/52] chore: adjust limits --- charts/substrate-faucet/templates/deployment.yaml | 2 +- charts/substrate-faucet/values.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 98bd943..d9fba6a 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -45,7 +45,7 @@ spec: - containerPort: 6379 resources: requests: - cpu: 50m + cpu: 250m memory: 100Mi readinessProbe: tcpSocket: diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 7282d94..87372c5 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -88,11 +88,11 @@ canary: resources: limits: - cpu: 100m - memory: 256Mi + cpu: 500m + memory: 512Mi requests: - cpu: 50m - memory: 128Mi + cpu: 250m + memory: 256Mi probePath: / livenessProbe: initialDelaySeconds: 60 From 9743eb75a8310dfe5b02738f64ca43eea949a414 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 16:57:52 +0200 Subject: [PATCH 25/52] chore: Disable resources --- .lighthouse/jenkins-x/pullrequest.yaml | 14 +++++++------- .lighthouse/jenkins-x/release.yaml | 14 +++++++------- charts/substrate-faucet/templates/deployment.yaml | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml index b51d38a..0989000 100644 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -13,13 +13,13 @@ spec: stepTemplate: image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/pullrequest.yaml@versionStream name: "" - resources: - requests: - cpu: 100m - memory: 256Mi - limits: - cpu: 200m - memory: 512Mi + # resources: + # requests: + # cpu: 100m + # memory: 256Mi + # limits: + # cpu: 200m + # memory: 512Mi workingDir: /workspace/source steps: - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone-pr.yaml@versionStream diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml index 922b6cd..ccda5cc 100644 --- a/.lighthouse/jenkins-x/release.yaml +++ b/.lighthouse/jenkins-x/release.yaml @@ -13,13 +13,13 @@ spec: stepTemplate: image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/release.yaml@versionStream name: "" - resources: - requests: - cpu: 100m - memory: 256Mi - limits: - cpu: 200m - memory: 512Mi + # resources: + # requests: + # cpu: 100m + # memory: 256Mi + # limits: + # cpu: 200m + # memory: 512Mi workingDir: /workspace/source steps: - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone.yaml@versionStream diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index d9fba6a..0d5a721 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -43,10 +43,10 @@ spec: image: redis:5.0.4 ports: - containerPort: 6379 - resources: + {% comment %} resources: requests: cpu: 250m - memory: 100Mi + memory: 100Mi {% endcomment %} readinessProbe: tcpSocket: port: 6379 @@ -108,8 +108,8 @@ spec: periodSeconds: {{ .Values.readinessProbe.periodSeconds }} successThreshold: {{ .Values.readinessProbe.successThreshold }} timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} - resources: -{{ toYaml .Values.resources | indent 12 }} + {% comment %} resources: +{{ toYaml .Values.resources | indent 12 }} {% endcomment %} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} imagePullSecrets: {{- range $pval := .Values.jx.imagePullSecrets }} From 637a37a34d63de87dd47172a4273338feac79fe9 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:00:35 +0200 Subject: [PATCH 26/52] fix: removed comments --- charts/substrate-faucet/templates/deployment.yaml | 12 +++++------- charts/substrate-faucet/values.yaml | 8 +------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 0d5a721..22597cf 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -43,10 +43,6 @@ spec: image: redis:5.0.4 ports: - containerPort: 6379 - {% comment %} resources: - requests: - cpu: 250m - memory: 100Mi {% endcomment %} readinessProbe: tcpSocket: port: 6379 @@ -89,7 +85,9 @@ spec: - name: REDIS_PORT value: "{{ .Values.botConfig.REDIS_PORT }}" - name: PROMETHEUS_PORT - value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" + value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" resources: + {{ toYaml .Values.resources | indent 12 }} + ports: - name: http containerPort: {{ .Values.service.internalPort }} @@ -108,8 +106,8 @@ spec: periodSeconds: {{ .Values.readinessProbe.periodSeconds }} successThreshold: {{ .Values.readinessProbe.successThreshold }} timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} - {% comment %} resources: -{{ toYaml .Values.resources | indent 12 }} {% endcomment %} + resources: +{{ toYaml .Values.resources | indent 12 }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} imagePullSecrets: {{- range $pval := .Values.jx.imagePullSecrets }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 87372c5..fba4ac7 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -86,13 +86,7 @@ canary: # Add labels to the canary gateway gatewayLabels: {} -resources: - limits: - cpu: 500m - memory: 512Mi - requests: - cpu: 250m - memory: 256Mi +resources: {} probePath: / livenessProbe: initialDelaySeconds: 60 From 8430e59290fb121a889e85f9299949e3116f0ae4 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:02:48 +0200 Subject: [PATCH 27/52] fix: remove resources --- charts/substrate-faucet/templates/deployment.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 22597cf..c4007cd 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -106,8 +106,6 @@ spec: periodSeconds: {{ .Values.readinessProbe.periodSeconds }} successThreshold: {{ .Values.readinessProbe.successThreshold }} timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} - resources: -{{ toYaml .Values.resources | indent 12 }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} imagePullSecrets: {{- range $pval := .Values.jx.imagePullSecrets }} From 81f9f431c29ad2a9ba80c78db3613596f6115e72 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:06:58 +0200 Subject: [PATCH 28/52] fix: Remove empty key --- charts/substrate-faucet/values.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index fba4ac7..ba84a22 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -86,7 +86,6 @@ canary: # Add labels to the canary gateway gatewayLabels: {} -resources: {} probePath: / livenessProbe: initialDelaySeconds: 60 From e72a0c55d7dfeb251a2c36a8d4988e6be921c2b8 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:25:33 +0200 Subject: [PATCH 29/52] fix: restore limits --- charts/substrate-faucet/templates/deployment.yaml | 2 ++ charts/substrate-faucet/values.yaml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index c4007cd..4586543 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -106,6 +106,8 @@ spec: periodSeconds: {{ .Values.readinessProbe.periodSeconds }} successThreshold: {{ .Values.readinessProbe.successThreshold }} timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 12 }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} imagePullSecrets: {{- range $pval := .Values.jx.imagePullSecrets }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index ba84a22..80867ce 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -86,6 +86,9 @@ canary: # Add labels to the canary gateway gatewayLabels: {} +resources: + limits: {} + requests: {} probePath: / livenessProbe: initialDelaySeconds: 60 From a91cfd851a7fa3a6f3c204f5f45b4f788b974bfd Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:28:52 +0200 Subject: [PATCH 30/52] fix: limits --- charts/substrate-faucet/templates/deployment.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 4586543..29eb825 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -43,6 +43,8 @@ spec: image: redis:5.0.4 ports: - containerPort: 6379 + resources: + requests: {} readinessProbe: tcpSocket: port: 6379 From b9814607acb79ecb7a5495806c4fc2eee06262be Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:34:25 +0200 Subject: [PATCH 31/52] fix: error removeal --- charts/substrate-faucet/templates/deployment.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 29eb825..9130ae2 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -87,9 +87,7 @@ spec: - name: REDIS_PORT value: "{{ .Values.botConfig.REDIS_PORT }}" - name: PROMETHEUS_PORT - value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" resources: - {{ toYaml .Values.resources | indent 12 }} - + value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" ports: - name: http containerPort: {{ .Values.service.internalPort }} From 8892bffb1e3ac44d376a6624eaa407f987058e14 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Mon, 4 Apr 2022 17:17:47 +0200 Subject: [PATCH 32/52] feat: throttle by discord username feat: inform user if invalid wallet address found --- app/faucet.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index bcd652d..9801d6d 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -53,22 +53,28 @@ async def nine_nine(ctx, arg): INVOCATION_COUNT.inc() if arg != None and len(arg) != 48: + # Inform of an invalid address + await ctx.send("That wallet address seems odd :thinking - sure you got that right?") return if (str(ctx.channel.type) == "private"): # Forbid DM in discord await ctx.send("Hold on Capt'ain, you can't send me private messages !") + return + else: + username = str(ctx.author.name) + #ensure we comply with send frequency r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) - if r.exists(arg): + if r.exists(username): await ctx.send("You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) ISSUANCE_THROTTLED.inc() return else: - r.set(name=arg,value="set") - r.expire(arg,ISSUE_INTERVAL) + r.set(name=username, value="set") + r.expire(username, ISSUE_INTERVAL) substrate = SubstrateInterface( From bc8dfdfe228b0016b4ffc1ab0f078b1012d6b40b Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Mon, 4 Apr 2022 17:58:04 +0200 Subject: [PATCH 33/52] fix: removed emoticon --- app/faucet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/faucet.py b/app/faucet.py index 9801d6d..3c225ad 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -54,7 +54,7 @@ async def nine_nine(ctx, arg): if arg != None and len(arg) != 48: # Inform of an invalid address - await ctx.send("That wallet address seems odd :thinking - sure you got that right?") + await ctx.send("That wallet address seems odd - sure you got that right?") return if (str(ctx.channel.type) == "private"): From a801370a902a2f555492d8a2537713999462eada Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:32:01 +0200 Subject: [PATCH 34/52] feat: author mention in denials --- app/faucet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 3c225ad..2506d6f 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -54,7 +54,7 @@ async def nine_nine(ctx, arg): if arg != None and len(arg) != 48: # Inform of an invalid address - await ctx.send("That wallet address seems odd - sure you got that right?") + await ctx.send(str(ctx.author.mention) + "That wallet address seems odd - sure you got that right?") return if (str(ctx.channel.type) == "private"): @@ -69,7 +69,7 @@ async def nine_nine(ctx, arg): #ensure we comply with send frequency r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) if r.exists(username): - await ctx.send("You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + await ctx.send(str(ctx.author.mention) + "You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) ISSUANCE_THROTTLED.inc() return else: From c8c0711124d5e5702a8ed89560823969e4ee6c13 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Mon, 4 Apr 2022 18:38:40 +0200 Subject: [PATCH 35/52] fix: added space between mention and message --- app/faucet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 2506d6f..2062c77 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -54,7 +54,7 @@ async def nine_nine(ctx, arg): if arg != None and len(arg) != 48: # Inform of an invalid address - await ctx.send(str(ctx.author.mention) + "That wallet address seems odd - sure you got that right?") + await ctx.send(str(ctx.author.mention) + " That wallet address seems odd - sure you got that right?") return if (str(ctx.channel.type) == "private"): @@ -69,7 +69,7 @@ async def nine_nine(ctx, arg): #ensure we comply with send frequency r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) if r.exists(username): - await ctx.send(str(ctx.author.mention) + "You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) ISSUANCE_THROTTLED.inc() return else: From 0a2556f6d7cf3846a47d0e21a5773f4da4de19b5 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 7 Apr 2022 17:21:06 +0200 Subject: [PATCH 36/52] chore: adapted for agung network --- .gitignore | 4 +++- charts/substrate-faucet/values.yaml | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 97a6f75..6019ffc 100644 --- a/.gitignore +++ b/.gitignore @@ -151,4 +151,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ test-net-faucet-bot-config.yaml -test-net-faucet-bot-secret.yaml \ No newline at end of file +test-net-faucet-bot-secret.yaml +agung-faucet-bot-config.yaml +agung-faucet-bot-secret.yaml \ No newline at end of file diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 80867ce..5813cc2 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -27,19 +27,19 @@ env: envFrom: - configMapRef: - name: test-net-faucet-bot-config + name: agung-faucet-bot-config botConfig: - NODE_RPC: "wss://wss.test.peaq.network" + NODE_RPC: "wss://wss.agung.peaq.network" TOKENS_TO_SEND: "1000000000000000000" - TOKEN_SYMBOL: "PEAQ" - ISSUE_INTERVAL: 5 + TOKEN_SYMBOL: "AGNG" + ISSUE_INTERVAL: 60 REDIS_IP: "127.0.0.1" REDIS_PORT: "6379" PROMETHEUS_PORT: "8080" botSecrets: - name: test-net-faucet-bot-secret + name: agung-faucet-bot-secret service: name: substrate-faucet From 8a0b35ec47c2a7097b43a7f8b71d7e9fa0d1a007 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 14 Apr 2022 13:58:00 +0200 Subject: [PATCH 37/52] feat: supress parallel requests --- app/faucet.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 2062c77..7c119f9 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -2,6 +2,7 @@ from pickletools import read_decimalnl_short import time from threading import Thread +import hashlib import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair @@ -64,18 +65,24 @@ async def nine_nine(ctx, arg): else: - username = str(ctx.author.name) + username = str(ctx.author.name).strip() + username_md5 = hashlib.md5(username) - #ensure we comply with send frequency - r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) - if r.exists(username): - await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) - ISSUANCE_THROTTLED.inc() - return - else: - r.set(name=username, value="set") - r.expire(username, ISSUE_INTERVAL) + print("Request from [{}]".format(username)) + # + r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) + + #prevent parallel requests + with r.lock(username_md5): + #ensure we comply with send frequency + if r.exists(username_md5): + await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + ISSUANCE_THROTTLED.inc() + return + else: + r.set(name=username_md5, value="set") + r.expire(username_md5, ISSUE_INTERVAL) substrate = SubstrateInterface( url=NODE_RPC From 461254096a90516f01c6b0a58e5dcceb86c0dc3c Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:07:24 +0200 Subject: [PATCH 38/52] fix: encoding before hashing --- app/faucet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/faucet.py b/app/faucet.py index 7c119f9..8234a71 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -66,7 +66,7 @@ async def nine_nine(ctx, arg): else: username = str(ctx.author.name).strip() - username_md5 = hashlib.md5(username) + username_md5 = hashlib.md5(username.encode('utf-8')) print("Request from [{}]".format(username)) From 1e32e0f4f6b805e6688e4a04ba3213fd217dcb3a Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:15:23 +0200 Subject: [PATCH 39/52] fix: convert to string --- app/faucet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/faucet.py b/app/faucet.py index 8234a71..52cdca1 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -66,7 +66,7 @@ async def nine_nine(ctx, arg): else: username = str(ctx.author.name).strip() - username_md5 = hashlib.md5(username.encode('utf-8')) + username_md5 = hashlib.md5(username.encode('utf-8')).hexdigest() print("Request from [{}]".format(username)) From 7fc3772901e053d92df2cf2175fc7d55a2f7c018 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:22:54 +0200 Subject: [PATCH 40/52] rollback. --- app/faucet.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 52cdca1..2062c77 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -2,7 +2,6 @@ from pickletools import read_decimalnl_short import time from threading import Thread -import hashlib import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair @@ -65,24 +64,18 @@ async def nine_nine(ctx, arg): else: - username = str(ctx.author.name).strip() - username_md5 = hashlib.md5(username.encode('utf-8')).hexdigest() + username = str(ctx.author.name) - print("Request from [{}]".format(username)) - - # + #ensure we comply with send frequency r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) - - #prevent parallel requests - with r.lock(username_md5): - #ensure we comply with send frequency - if r.exists(username_md5): - await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) - ISSUANCE_THROTTLED.inc() - return - else: - r.set(name=username_md5, value="set") - r.expire(username_md5, ISSUE_INTERVAL) + if r.exists(username): + await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + ISSUANCE_THROTTLED.inc() + return + else: + r.set(name=username, value="set") + r.expire(username, ISSUE_INTERVAL) + substrate = SubstrateInterface( url=NODE_RPC From e99f100fe45f8114f85508deb1ceac4cee226ac3 Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 14 Apr 2022 15:40:44 +0200 Subject: [PATCH 41/52] chore: fix the lock --- app/faucet.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 2062c77..ab50f14 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -2,6 +2,7 @@ from pickletools import read_decimalnl_short import time from threading import Thread +import hashlib import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair @@ -64,18 +65,24 @@ async def nine_nine(ctx, arg): else: - username = str(ctx.author.name) + username = str(ctx.author.name).strip() + username_md5 = hashlib.md5(username.encode('utf-8')).hexdigest() - #ensure we comply with send frequency - r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) - if r.exists(username): - await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) - ISSUANCE_THROTTLED.inc() - return - else: - r.set(name=username, value="set") - r.expire(username, ISSUE_INTERVAL) + print("Request from [{}]".format(username)) + # + r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) + + #prevent parallel requests + with r.lock('lock_' + username_md5): + #ensure we comply with send frequency + if r.exists(username_md5): + await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + ISSUANCE_THROTTLED.inc() + return + else: + r.set(name=username_md5, value="set") + r.expire(username_md5, ISSUE_INTERVAL) substrate = SubstrateInterface( url=NODE_RPC From 4689544dedcd9e0e6f0e5ffbb84dfa2ec297048b Mon Sep 17 00:00:00 2001 From: faisalthaheem <10938481+faisalthaheem@users.noreply.github.com> Date: Thu, 14 Apr 2022 16:05:29 +0200 Subject: [PATCH 42/52] chore: revert --- app/faucet.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index ab50f14..2062c77 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -2,7 +2,6 @@ from pickletools import read_decimalnl_short import time from threading import Thread -import hashlib import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair @@ -65,24 +64,18 @@ async def nine_nine(ctx, arg): else: - username = str(ctx.author.name).strip() - username_md5 = hashlib.md5(username.encode('utf-8')).hexdigest() + username = str(ctx.author.name) - print("Request from [{}]".format(username)) - - # + #ensure we comply with send frequency r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) - - #prevent parallel requests - with r.lock('lock_' + username_md5): - #ensure we comply with send frequency - if r.exists(username_md5): - await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) - ISSUANCE_THROTTLED.inc() - return - else: - r.set(name=username_md5, value="set") - r.expire(username_md5, ISSUE_INTERVAL) + if r.exists(username): + await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) + ISSUANCE_THROTTLED.inc() + return + else: + r.set(name=username, value="set") + r.expire(username, ISSUE_INTERVAL) + substrate = SubstrateInterface( url=NODE_RPC From 9e6aaff084c884b915c0b94b35c6ff81eda2c298 Mon Sep 17 00:00:00 2001 From: jaypan Date: Fri, 17 Feb 2023 18:17:40 +0100 Subject: [PATCH 43/52] Add multiple faucets/library upgrade/Refine code --- app/faucet.py | 127 +++++++++++++++++++++++++++++------------------ requirements.txt | 5 +- 2 files changed, 82 insertions(+), 50 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 2062c77..38f2600 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -1,12 +1,9 @@ import os -from pickletools import read_decimalnl_short import time from threading import Thread import redis from discord.ext import commands from substrateinterface import SubstrateInterface, Keypair -from substrateinterface.exceptions import SubstrateRequestException -from substrateinterface.utils.ss58 import ss58_encode from prometheus_client import start_http_server, Counter # prometheus metrics @@ -14,59 +11,86 @@ ISSUANCE_TOTAL = Counter('issuance_total', 'Total tokens issued.') ISSUANCE_THROTTLED = Counter('issuance_throttled', 'Total issuance requests throttled (too quickly requested again).') + +def notify_exit(): + time.sleep(30) + import sys + sys.exit(1) + + def get_env_var_or_exit(var_name): var = os.environ.get(var_name) - - if var == None or len(var) == 0: + + if var is None or len(var) == 0: print("Please check if [{}] is defined. Will exit after 30s sleep".format(var_name)) - time.sleep(30) - import sys - sys.exit(1) - - return var + notify_exit() + + return var + # Your Discord bot token DISCORD_BOT_TOKEN = get_env_var_or_exit("DISCORD_BOT_TOKEN") -#the address of our network +# the address of our network, seperate by "," and should be "ws" or "wss" NODE_RPC = get_env_var_or_exit("NODE_RPC") -#to construct the private/public key pair +# to construct the private/public key pair, seperate by "," FAUCET_MNEMONIC = get_env_var_or_exit("FAUCET_MNEMONIC") -#how many tokens to send, on peaq network 1 PEAQ = 1,000,000,000,000,000,000 +# how many tokens to send, on peaq network 1 PEAQ = 1,000,000,000,000,000,000 TOKENS_TO_SEND = int(get_env_var_or_exit("TOKENS_TO_SEND")) -#the token symbol +# the token symbol TOKEN_SYMBOL = get_env_var_or_exit("TOKEN_SYMBOL") -#how often can a user ask for a token? in seconds +# how often can a user ask for a token? in seconds ISSUE_INTERVAL = int(get_env_var_or_exit("ISSUE_INTERVAL")) -#redis +# redis REDIS_IP = get_env_var_or_exit("REDIS_IP") REDIS_PORT = int(get_env_var_or_exit("REDIS_PORT")) -#prometheus +# prometheus PROMETHEUS_PORT = int(get_env_var_or_exit("PROMETHEUS_PORT")) # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') -keypair = Keypair.create_from_mnemonic(FAUCET_MNEMONIC) + + +def prepare_url_key_pairs(node_rpcs, faucet_mnemonics): + node_rpc_entires = node_rpcs.split(',') + for rpc in node_rpc_entires: + if not rpc.lower().startswith('ws://') and rpc.lower().startswith('wss://'): + print('{} fails, please check the env again'.format(rpc)) + notify_exit() + + faucet_mnemonics_entries = faucet_mnemonics.split(',') + + if len(node_rpc_entires) != len(faucet_mnemonics_entries): + print('the rpc entry is not the same as the faucet entry, please check and redeploy') + notify_exit() + + return [{ + 'rpc_url': node_rpc_entires[i], + 'faucet_kp': Keypair.create_from_mnemonic(faucet_mnemonics_entries[i]) + } for i in range(0, len(node_rpc_entires))] + + +info_pairs = prepare_url_key_pairs(NODE_RPC, FAUCET_MNEMONIC) + @bot.command(name='send', help='Send token from faucet') async def nine_nine(ctx, arg): - + INVOCATION_COUNT.inc() - - if arg != None and len(arg) != 48: + + if arg is not None and len(arg) != 48: # Inform of an invalid address await ctx.send(str(ctx.author.mention) + " That wallet address seems odd - sure you got that right?") return - + if (str(ctx.channel.type) == "private"): # Forbid DM in discord await ctx.send("Hold on Capt'ain, you can't send me private messages !") return - + else: - username = str(ctx.author.name) - - #ensure we comply with send frequency + + # ensure we comply with send frequency r = redis.Redis(host=REDIS_IP, port=REDIS_PORT) if r.exists(username): await ctx.send(str(ctx.author.mention) + " You can only request once every [{}] second(s) !".format(ISSUE_INTERVAL)) @@ -74,37 +98,44 @@ async def nine_nine(ctx, arg): return else: r.set(name=username, value="set") - r.expire(username, ISSUE_INTERVAL) - - - substrate = SubstrateInterface( - url=NODE_RPC - ) - call = substrate.compose_call( - call_module='Balances', - call_function='transfer', - call_params={ - 'dest': arg, - 'value': TOKENS_TO_SEND - } - ) - reply = "" - extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair) - reply = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=False) - + r.expire(username, ISSUE_INTERVAL) + + extrinsic_url = [] + for info in info_pairs: + rpc_url = info['rpc_url'] + faucet_kp = info['faucet_kp'] + + with SubstrateInterface(url=rpc_url) as substrate: + call = substrate.compose_call( + call_module='Balances', + call_function='transfer', + call_params={ + 'dest': arg, + 'value': TOKENS_TO_SEND} + ) + reply = "" + extrinsic = substrate.create_signed_extrinsic(call=call, keypair=faucet_kp) + reply = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=False) + extrinsic_url.append( + '{1} on {0}'.format(rpc_url, reply['extrinsic_hash'])) + # inform user - msg = " Awesome, you just received \"{}\" {}! The extrinsic hash is [{}]".format(TOKENS_TO_SEND/1000000000000000000, TOKEN_SYMBOL, reply['extrinsic_hash']) + msg = " Awesome, you just received {} Token! Please check these extrinsic hash. \n {}".format( + TOKENS_TO_SEND / 1000000000000000000, + '\n'.join(extrinsic_url)) await ctx.send(str(ctx.author.mention) + msg) - + # log to console print(str(ctx.author.name) + msg) - + # store metrics - ISSUANCE_TOTAL.inc(TOKENS_TO_SEND/1000000000000000000) + ISSUANCE_TOTAL.inc(TOKENS_TO_SEND / 1000000000000000000) + def prometheus_server(): start_http_server(PROMETHEUS_PORT) + print("Starting prometheus server") t_prometheus = Thread(target=prometheus_server) t_prometheus.start() diff --git a/requirements.txt b/requirements.txt index a64936c..903d3ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -substrate-interface==1.2.2 +substrate-interface==1.2.4 discord.py==1.7.3 redis==4.1.4 -prometheus-client==0.13.1 \ No newline at end of file +prometheus-client==0.13.1 +scalecodec==1.0.35 From 2a0db1f7a75db5af60bdf1e1c8bda9d183baae9c Mon Sep 17 00:00:00 2001 From: jaypan Date: Mon, 20 Feb 2023 15:39:10 +0100 Subject: [PATCH 44/52] Extract constant --- app/faucet.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/faucet.py b/app/faucet.py index 38f2600..7552549 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -46,6 +46,8 @@ def get_env_var_or_exit(var_name): # prometheus PROMETHEUS_PORT = int(get_env_var_or_exit("PROMETHEUS_PORT")) +DECIMAL_BASE = 10 ** 18 + # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') @@ -121,7 +123,7 @@ async def nine_nine(ctx, arg): # inform user msg = " Awesome, you just received {} Token! Please check these extrinsic hash. \n {}".format( - TOKENS_TO_SEND / 1000000000000000000, + TOKENS_TO_SEND / DECIMAL_BASE, '\n'.join(extrinsic_url)) await ctx.send(str(ctx.author.mention) + msg) @@ -129,7 +131,7 @@ async def nine_nine(ctx, arg): print(str(ctx.author.name) + msg) # store metrics - ISSUANCE_TOTAL.inc(TOKENS_TO_SEND / 1000000000000000000) + ISSUANCE_TOTAL.inc(TOKENS_TO_SEND / DECIMAL_BASE) def prometheus_server(): From 24a19567044a7ecea232683964c4f74676a7e3a1 Mon Sep 17 00:00:00 2001 From: jaypan Date: Mon, 20 Feb 2023 15:44:08 +0100 Subject: [PATCH 45/52] Extract to env variable --- README.md | 7 ++++--- app/faucet.py | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b51fd26..423297f 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,10 @@ Default values are as follows |Key|Description| |---|---| |DISCORD_BOT_TOKEN|The secret bot token to use for connecting to discord| -|NODE_RPC|https://wss.test.peaq.network| -|FAUCET_MNEMONIC|use the value from subkey generate| +|NODE_RPC|wss://wss.test.peaq.network,wss://wss2.test.peaq.network| +|FAUCET_MNEMONIC|use the value from subkey generate,use the value from subkey2 generate| |TOKENS_TO_SEND|1000000000000000000| +|TOKENS_DECIMAL|1000000000000000000| |TOKEN_SYMBOL|PEAQ| |ISSUE_INTERVAL|5| |REDIS_IP|127.0.0.1| @@ -53,4 +54,4 @@ metadata: name: test-net-faucet-bot-secret namespace: jx-devbr type: Opaque -``` \ No newline at end of file +``` diff --git a/app/faucet.py b/app/faucet.py index 7552549..cec02a5 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -36,6 +36,8 @@ def get_env_var_or_exit(var_name): FAUCET_MNEMONIC = get_env_var_or_exit("FAUCET_MNEMONIC") # how many tokens to send, on peaq network 1 PEAQ = 1,000,000,000,000,000,000 TOKENS_TO_SEND = int(get_env_var_or_exit("TOKENS_TO_SEND")) +# how many tokens in one token, 10 ** 18 +TOKENS_DECIMAL = int(get_env_var_or_exit("TOKENS_DECIMAL")) # the token symbol TOKEN_SYMBOL = get_env_var_or_exit("TOKEN_SYMBOL") # how often can a user ask for a token? in seconds @@ -46,8 +48,6 @@ def get_env_var_or_exit(var_name): # prometheus PROMETHEUS_PORT = int(get_env_var_or_exit("PROMETHEUS_PORT")) -DECIMAL_BASE = 10 ** 18 - # associated address 5CfVS8r8sNiioYi4YmtJjPhYgxcxuMXYg1Gkp91LtHCmkqiQ bot = commands.Bot(command_prefix='!') @@ -123,7 +123,7 @@ async def nine_nine(ctx, arg): # inform user msg = " Awesome, you just received {} Token! Please check these extrinsic hash. \n {}".format( - TOKENS_TO_SEND / DECIMAL_BASE, + TOKENS_TO_SEND / TOKENS_DECIMAL, '\n'.join(extrinsic_url)) await ctx.send(str(ctx.author.mention) + msg) @@ -131,7 +131,7 @@ async def nine_nine(ctx, arg): print(str(ctx.author.name) + msg) # store metrics - ISSUANCE_TOTAL.inc(TOKENS_TO_SEND / DECIMAL_BASE) + ISSUANCE_TOTAL.inc(TOKENS_TO_SEND / TOKENS_DECIMAL) def prometheus_server(): From 4ddffb2115b4b740e62b7eaeaccd5c4947d5d5c4 Mon Sep 17 00:00:00 2001 From: niazhussain Date: Mon, 27 Feb 2023 10:32:15 +0100 Subject: [PATCH 46/52] add: configmap for multinode --- .lighthouse/jenkins-x/triggers.yaml | 2 +- charts/substrate-faucet/templates/deployment.yaml | 7 +++++-- charts/substrate-faucet/values.yaml | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.lighthouse/jenkins-x/triggers.yaml b/.lighthouse/jenkins-x/triggers.yaml index ae2fcfa..def0338 100644 --- a/.lighthouse/jenkins-x/triggers.yaml +++ b/.lighthouse/jenkins-x/triggers.yaml @@ -13,4 +13,4 @@ spec: source: "release.yaml" branches: - ^main$ - - ^master$ + #- ^master$ diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index 9130ae2..d4e2339 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -59,6 +59,9 @@ spec: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + envFrom: + - configMapRef: + name: {{ .Values.envconfigmap.name }} env: - name: VERSION value: {{ .Chart.Version }} @@ -74,8 +77,8 @@ spec: name: {{ .Values.botSecrets.name }} key: FAUCET_MNEMONIC optional: false - - name: NODE_RPC - value: "{{ .Values.botConfig.NODE_RPC }}" + #- name: NODE_RPC + # value: "{{ .Values.botConfig.NODE_RPC }}" - name: TOKENS_TO_SEND value: "{{ .Values.botConfig.TOKENS_TO_SEND }}" - name: TOKEN_SYMBOL diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 5813cc2..5ddce0d 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -24,7 +24,8 @@ jx: # define environment variables here as a map of key: value env: - +envconfigmap: + name: substrate-faucet-configmap envFrom: - configMapRef: name: agung-faucet-bot-config From 2c40771b246470474633ca8d43977edc998d48b2 Mon Sep 17 00:00:00 2001 From: niazhussain Date: Mon, 27 Feb 2023 11:28:59 +0100 Subject: [PATCH 47/52] enable triger on master --- .lighthouse/jenkins-x/triggers.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.lighthouse/jenkins-x/triggers.yaml b/.lighthouse/jenkins-x/triggers.yaml index def0338..ae2fcfa 100644 --- a/.lighthouse/jenkins-x/triggers.yaml +++ b/.lighthouse/jenkins-x/triggers.yaml @@ -13,4 +13,4 @@ spec: source: "release.yaml" branches: - ^main$ - #- ^master$ + - ^master$ From f94a3c1fdfae86678c2c981d5acb6c2fa92e89f6 Mon Sep 17 00:00:00 2001 From: jaypan Date: Mon, 27 Feb 2023 14:18:02 +0100 Subject: [PATCH 48/52] Fix errors --- app/faucet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/faucet.py b/app/faucet.py index cec02a5..f33a73b 100644 --- a/app/faucet.py +++ b/app/faucet.py @@ -55,7 +55,7 @@ def get_env_var_or_exit(var_name): def prepare_url_key_pairs(node_rpcs, faucet_mnemonics): node_rpc_entires = node_rpcs.split(',') for rpc in node_rpc_entires: - if not rpc.lower().startswith('ws://') and rpc.lower().startswith('wss://'): + if not rpc.lower().startswith('ws://') and not rpc.lower().startswith('wss://'): print('{} fails, please check the env again'.format(rpc)) notify_exit() From 04410d11adcb0bab7ab4fdd306ebd23bb45f5642 Mon Sep 17 00:00:00 2001 From: hussain Date: Sun, 30 Jun 2024 14:33:27 +0200 Subject: [PATCH 49/52] ci-fix: pipeline regenrate --- .lighthouse/jenkins-x/pullrequest.yaml | 41 ----- .lighthouse/jenkins-x/release.yaml | 47 ------ .lighthouse/jenkins-x/triggers.yaml | 16 -- charts/substrate-faucet/.helmignore | 21 --- charts/substrate-faucet/Chart.yaml | 5 - charts/substrate-faucet/Kptfile | 11 -- charts/substrate-faucet/Makefile | 48 ------ charts/substrate-faucet/README.md | 1 - charts/substrate-faucet/templates/NOTES.txt | 4 - .../substrate-faucet/templates/_helpers.tpl | 16 -- charts/substrate-faucet/templates/canary.yaml | 66 -------- .../templates/deployment.yaml | 119 -------------- charts/substrate-faucet/templates/hpa.yaml | 28 ---- .../substrate-faucet/templates/ingress.yaml | 48 ------ charts/substrate-faucet/templates/ksvc.yaml | 51 ------ charts/substrate-faucet/templates/sa.yaml | 16 -- .../substrate-faucet/templates/service.yaml | 29 ---- charts/substrate-faucet/values.yaml | 149 ------------------ preview/Kptfile | 11 -- preview/helmfile.yaml | 31 ---- preview/values.yaml.gotmpl | 8 - 21 files changed, 766 deletions(-) delete mode 100644 .lighthouse/jenkins-x/pullrequest.yaml delete mode 100644 .lighthouse/jenkins-x/release.yaml delete mode 100644 .lighthouse/jenkins-x/triggers.yaml delete mode 100755 charts/substrate-faucet/.helmignore delete mode 100644 charts/substrate-faucet/Chart.yaml delete mode 100755 charts/substrate-faucet/Kptfile delete mode 100755 charts/substrate-faucet/Makefile delete mode 100755 charts/substrate-faucet/README.md delete mode 100755 charts/substrate-faucet/templates/NOTES.txt delete mode 100755 charts/substrate-faucet/templates/_helpers.tpl delete mode 100755 charts/substrate-faucet/templates/canary.yaml delete mode 100755 charts/substrate-faucet/templates/deployment.yaml delete mode 100755 charts/substrate-faucet/templates/hpa.yaml delete mode 100755 charts/substrate-faucet/templates/ingress.yaml delete mode 100755 charts/substrate-faucet/templates/ksvc.yaml delete mode 100755 charts/substrate-faucet/templates/sa.yaml delete mode 100755 charts/substrate-faucet/templates/service.yaml delete mode 100755 charts/substrate-faucet/values.yaml delete mode 100644 preview/Kptfile delete mode 100644 preview/helmfile.yaml delete mode 100644 preview/values.yaml.gotmpl diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml deleted file mode 100644 index 0989000..0000000 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: PipelineRun -metadata: - creationTimestamp: null - name: pullrequest -spec: - pipelineSpec: - tasks: - - name: from-build-pack - resources: {} - taskSpec: - metadata: {} - stepTemplate: - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/pullrequest.yaml@versionStream - name: "" - # resources: - # requests: - # cpu: 100m - # memory: 256Mi - # limits: - # cpu: 200m - # memory: 512Mi - workingDir: /workspace/source - steps: - - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone-pr.yaml@versionStream - name: "" - resources: {} - - name: jx-variables - resources: {} - # - name: build-python-unittest - # resources: {} - - name: check-registry - resources: {} - - name: build-container-build - resources: {} - - name: promote-jx-preview - resources: {} - podTemplate: {} - serviceAccountName: tekton-bot - timeout: 12h0m0s -status: {} diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml deleted file mode 100644 index ccda5cc..0000000 --- a/.lighthouse/jenkins-x/release.yaml +++ /dev/null @@ -1,47 +0,0 @@ -apiVersion: tekton.dev/v1beta1 -kind: PipelineRun -metadata: - creationTimestamp: null - name: release -spec: - pipelineSpec: - tasks: - - name: from-build-pack - resources: {} - taskSpec: - metadata: {} - stepTemplate: - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/release.yaml@versionStream - name: "" - # resources: - # requests: - # cpu: 100m - # memory: 256Mi - # limits: - # cpu: 200m - # memory: 512Mi - workingDir: /workspace/source - steps: - - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone.yaml@versionStream - name: "" - resources: {} - - name: next-version - resources: {} - - name: jx-variables - resources: {} - - name: build-python-unittest - resources: {} - - name: check-registry - resources: {} - - name: build-container-build - resources: {} - - name: promote-changelog - resources: {} - - name: promote-helm-release - resources: {} - - name: promote-jx-promote - resources: {} - podTemplate: {} - serviceAccountName: tekton-bot - timeout: 12h0m0s -status: {} diff --git a/.lighthouse/jenkins-x/triggers.yaml b/.lighthouse/jenkins-x/triggers.yaml deleted file mode 100644 index ae2fcfa..0000000 --- a/.lighthouse/jenkins-x/triggers.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: config.lighthouse.jenkins-x.io/v1alpha1 -kind: TriggerConfig -spec: - presubmits: - - name: pr - context: "pr" - always_run: true - optional: false - source: "pullrequest.yaml" - postsubmits: - - name: release - context: "release" - source: "release.yaml" - branches: - - ^main$ - - ^master$ diff --git a/charts/substrate-faucet/.helmignore b/charts/substrate-faucet/.helmignore deleted file mode 100755 index f0c1319..0000000 --- a/charts/substrate-faucet/.helmignore +++ /dev/null @@ -1,21 +0,0 @@ -# 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 -*~ -# Various IDEs -.project -.idea/ -*.tmproj diff --git a/charts/substrate-faucet/Chart.yaml b/charts/substrate-faucet/Chart.yaml deleted file mode 100644 index 3be8323..0000000 --- a/charts/substrate-faucet/Chart.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: v1 -description: A Helm chart for Kubernetes -icon: https://raw.githubusercontent.com/cdfoundation/artwork/master/jenkinsx/icon/color/jenkinsx-icon-color.png -name: substrate-faucet -version: 0.1.0-SNAPSHOT diff --git a/charts/substrate-faucet/Kptfile b/charts/substrate-faucet/Kptfile deleted file mode 100755 index 2a814c7..0000000 --- a/charts/substrate-faucet/Kptfile +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: kpt.dev/v1alpha1 -kind: Kptfile -metadata: - name: charts -upstream: - type: git - git: - commit: b52b35506a05e046d54615c3ade97f3aef8bfb08 - repo: https://github.com/jenkins-x/jx3-pipeline-catalog - directory: /helm/charts - ref: master diff --git a/charts/substrate-faucet/Makefile b/charts/substrate-faucet/Makefile deleted file mode 100755 index bdc3a42..0000000 --- a/charts/substrate-faucet/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -CHART_REPO := http://jenkins-x-chartmuseum:8080 -CURRENT=$(pwd) -NAME := substrate-faucet -OS := $(shell uname) -RELEASE_VERSION := $(shell cat ../../VERSION) - -build: clean - rm -rf requirements.lock - helm dependency build - helm lint - -install: clean build - helm install . --name ${NAME} - -upgrade: clean build - helm upgrade ${NAME} . - -delete: - helm delete --purge ${NAME} - -clean: - rm -rf charts - rm -rf ${NAME}*.tgz - -release: clean - helm dependency build - helm lint - helm init --client-only - helm package . - curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts - rm -rf ${NAME}*.tgz% - -tag: -ifeq ($(OS),Darwin) - sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml - sed -i "" -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml -else ifeq ($(OS),Linux) - sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml - sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/peaqnetwork\/substrate-faucet|" values.yaml - sed -i -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml -else - echo "platfrom $(OS) not supported to release from" - exit -1 -endif - git add --all - git commit -m "chore: release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed - git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)" - git push origin v$(RELEASE_VERSION) diff --git a/charts/substrate-faucet/README.md b/charts/substrate-faucet/README.md deleted file mode 100755 index 89f8286..0000000 --- a/charts/substrate-faucet/README.md +++ /dev/null @@ -1 +0,0 @@ -# my application \ No newline at end of file diff --git a/charts/substrate-faucet/templates/NOTES.txt b/charts/substrate-faucet/templates/NOTES.txt deleted file mode 100755 index 97823be..0000000 --- a/charts/substrate-faucet/templates/NOTES.txt +++ /dev/null @@ -1,4 +0,0 @@ - -Get the application URL by running these commands: - -kubectl get ingress {{ template "fullname" . }} diff --git a/charts/substrate-faucet/templates/_helpers.tpl b/charts/substrate-faucet/templates/_helpers.tpl deleted file mode 100755 index f0d83d2..0000000 --- a/charts/substrate-faucet/templates/_helpers.tpl +++ /dev/null @@ -1,16 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "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). -*/}} -{{- define "fullname" -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/charts/substrate-faucet/templates/canary.yaml b/charts/substrate-faucet/templates/canary.yaml deleted file mode 100755 index b5f55d3..0000000 --- a/charts/substrate-faucet/templates/canary.yaml +++ /dev/null @@ -1,66 +0,0 @@ -{{- if .Values.canary.enabled }} -apiVersion: flagger.app/v1beta1 -kind: Canary -metadata: - name: {{ template "fullname" . }} - labels: - draft: {{ default "draft-app" .Values.draft }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -{{- if .Values.canary.labels }} -{{ toYaml .Values.canary.labels | indent 4 }} -{{- end }} -spec: - provider: istio - targetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "fullname" . }} - progressDeadlineSeconds: {{ .Values.canary.progressDeadlineSeconds }} - {{- if .Values.hpa.enabled }} - autoscalerRef: - apiVersion: autoscaling/v2beta1 - kind: HorizontalPodAutoscaler - name: {{ template "fullname" . }} - {{- end }} - service: - port: {{ .Values.service.externalPort }} - targetPort: {{ .Values.service.internalPort }} - gateways: - - {{ template "fullname" . }} - hosts: - - {{ .Values.canary.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain) }} - analysis: - interval: {{ .Values.canary.analysis.interval }} - threshold: {{ .Values.canary.analysis.threshold }} - maxWeight: {{ .Values.canary.analysis.maxWeight }} - stepWeight: {{ .Values.canary.analysis.stepWeight }} - metrics: - - name: latency - templateRef: - name: latency - namespace: istio-system - thresholdRange: - max: {{ .Values.canary.analysis.metrics.latency.threshold }} - interval: {{ .Values.canary.analysis.metrics.latency.interval | quote }} - ---- - -apiVersion: networking.istio.io/v1alpha3 -kind: Gateway -metadata: - name: {{ template "fullname" . }} -{{- if .Values.canary.gatewayLabels }} - labels: -{{ toYaml .Values.canary.gatewayLabels | indent 4 }} -{{- end }} -spec: - selector: - istio: ingressgateway - servers: - - port: - number: {{ .Values.service.externalPort }} - name: http - protocol: HTTP - hosts: - - {{ .Values.canary.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain) }} -{{- end }} diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml deleted file mode 100755 index d4e2339..0000000 --- a/charts/substrate-faucet/templates/deployment.yaml +++ /dev/null @@ -1,119 +0,0 @@ -{{- if .Values.knativeDeploy }} -{{- else }} -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ template "fullname" . }} - labels: - draft: {{ default "draft-app" .Values.draft }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -{{- if .Values.deploymentLabels }} -{{ toYaml .Values.deploymentLabels | indent 4 }} -{{- end }} -spec: - selector: - matchLabels: - app: {{ template "fullname" . }} -{{- if .Values.hpa.enabled }} -{{- else }} - replicas: {{ .Values.replicaCount }} -{{- end }} - template: - metadata: - labels: - draft: {{ default "draft-app" .Values.draft }} - app: {{ template "fullname" . }} -{{- if .Values.podsLabels }} -{{ toYaml .Values.podsLabels | indent 6 }} -{{- end }} -{{- if .Values.podAnnotations }} - annotations: -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: -{{- if .Values.serviceAccount.enabled }} -{{- if .Values.serviceAccount.name }} - serviceAccountName: {{ .Values.serviceAccount.name }} -{{- else }} - serviceAccountName: {{ template "fullname" . }} -{{- end }} -{{- end }} - containers: - - name: redis - image: redis:5.0.4 - ports: - - containerPort: 6379 - resources: - requests: {} - readinessProbe: - tcpSocket: - port: 6379 - initialDelaySeconds: 30 - periodSeconds: 10 - livenessProbe: - tcpSocket: - port: 6379 - initialDelaySeconds: 30 - periodSeconds: 20 - - - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - envFrom: - - configMapRef: - name: {{ .Values.envconfigmap.name }} - env: - - name: VERSION - value: {{ .Chart.Version }} - - name: DISCORD_BOT_TOKEN - valueFrom: - secretKeyRef: - name: {{ .Values.botSecrets.name }} - key: DISCORD_BOT_TOKEN - optional: false - - name: FAUCET_MNEMONIC - valueFrom: - secretKeyRef: - name: {{ .Values.botSecrets.name }} - key: FAUCET_MNEMONIC - optional: false - #- name: NODE_RPC - # value: "{{ .Values.botConfig.NODE_RPC }}" - - name: TOKENS_TO_SEND - value: "{{ .Values.botConfig.TOKENS_TO_SEND }}" - - name: TOKEN_SYMBOL - value: "{{ .Values.botConfig.TOKEN_SYMBOL }}" - - name: ISSUE_INTERVAL - value: "{{ .Values.botConfig.ISSUE_INTERVAL }}" - - name: REDIS_IP - value: "{{ .Values.botConfig.REDIS_IP }}" - - name: REDIS_PORT - value: "{{ .Values.botConfig.REDIS_PORT }}" - - name: PROMETHEUS_PORT - value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" - ports: - - name: http - containerPort: {{ .Values.service.internalPort }} - livenessProbe: - httpGet: - path: {{ .Values.livenessProbe.probePath | default .Values.probePath }} - port: {{ .Values.service.internalPort }} - initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} - periodSeconds: {{ .Values.livenessProbe.periodSeconds }} - successThreshold: {{ .Values.livenessProbe.successThreshold }} - timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} - readinessProbe: - httpGet: - path: {{ .Values.readinessProbe.probePath | default .Values.probePath }} - port: {{ .Values.service.internalPort }} - periodSeconds: {{ .Values.readinessProbe.periodSeconds }} - successThreshold: {{ .Values.readinessProbe.successThreshold }} - timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} - resources: -{{ toYaml .Values.resources | indent 12 }} - terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} - imagePullSecrets: -{{- range $pval := .Values.jx.imagePullSecrets }} - - name: {{ quote $pval }} -{{- end }} -{{- end }} diff --git a/charts/substrate-faucet/templates/hpa.yaml b/charts/substrate-faucet/templates/hpa.yaml deleted file mode 100755 index a20a001..0000000 --- a/charts/substrate-faucet/templates/hpa.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{- if .Values.hpa.enabled }} -apiVersion: autoscaling/v2beta1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ template "fullname" . }} - labels: - draft: {{ default "draft-app" .Values.draft }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -{{- if .Values.hpa.labels }} -{{ toYaml .Values.hpa.labels | indent 4 }} -{{- end }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "fullname" . }} - minReplicas: {{ .Values.hpa.minReplicas }} - maxReplicas: {{ .Values.hpa.maxReplicas }} - metrics: - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.hpa.cpuTargetAverageUtilization }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.hpa.memoryTargetAverageUtilization }} -{{- end }} \ No newline at end of file diff --git a/charts/substrate-faucet/templates/ingress.yaml b/charts/substrate-faucet/templates/ingress.yaml deleted file mode 100755 index 7c641c1..0000000 --- a/charts/substrate-faucet/templates/ingress.yaml +++ /dev/null @@ -1,48 +0,0 @@ -{{- if and (.Values.jxRequirements.ingress.domain) (not .Values.knativeDeploy) }} -{{- $annotations := dict }} -{{- $_ := merge $annotations .Values.ingress.annotations .Values.jxRequirements.ingress.annotations }} -{{- if not (hasKey $annotations "kubernetes.io/ingress.class") }} -{{- $_ := set $annotations "kubernetes.io/ingress.class" (.Values.ingress.classAnnotation | default "nginx") }} -{{- end }} -{{- if and (hasKey .Values.jxRequirements.ingress "serviceType") (.Values.jxRequirements.ingress.serviceType) (eq .Values.jxRequirements.ingress.serviceType "NodePort") (not (hasKey $annotations "jenkins.io/host")) }} -{{- $_ := set $annotations "jenkins.io/host" .Values.jxRequirements.ingress.domain }} -{{- end }} -apiVersion: {{ .Values.jxRequirements.ingress.apiVersion }} -kind: Ingress -metadata: - annotations: -{{- if $annotations }} -{{ toYaml $annotations | indent 4 }} -{{- end }} - name: {{ .Values.service.name }} -{{- if .Values.ingress.labels }} -{{ toYaml .Values.ingress.labels | indent 4 }} -{{- end }} -spec: - rules: - - http: - paths: - - pathType: {{ .Values.ingress.pathType | default "ImplementationSpecific" }} - backend: - service: - name: {{ .Values.service.name }} - port: - number: {{ .Values.service.externalPort }} -{{- if eq "NodePort" .Values.jxRequirements.ingress.serviceType }} - path: "/{{ .Release.Namespace }}/hook" -{{- else if .Values.jxRequirements.ingress.domain }} - host: {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} -{{- end }} -{{- if .Values.jxRequirements.ingress.tls.enabled }} - tls: - - hosts: - - {{ .Values.service.name }}{{ .Values.jxRequirements.ingress.namespaceSubDomain }}{{ .Values.jxRequirements.ingress.domain }} -{{- if and (hasKey .Values.jxRequirements.ingress.tls "secretName") (.Values.jxRequirements.ingress.tls.secretName) }} - secretName: "{{ .Values.jxRequirements.ingress.tls.secretName }}" -{{- else if .Values.jxRequirements.ingress.tls.production }} - secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-p" -{{- else }} - secretName: "tls-{{ .Values.jxRequirements.ingress.domain | replace "." "-" }}-s" -{{- end }} -{{- end }} -{{- end }} diff --git a/charts/substrate-faucet/templates/ksvc.yaml b/charts/substrate-faucet/templates/ksvc.yaml deleted file mode 100755 index ebf2a53..0000000 --- a/charts/substrate-faucet/templates/ksvc.yaml +++ /dev/null @@ -1,51 +0,0 @@ -{{- if .Values.knativeDeploy }} -apiVersion: serving.knative.dev/v1 -kind: Service -metadata: - {{- if .Values.service.name }} - name: {{ .Values.service.name }} - {{- else }} - name: {{ template "fullname" . }} - {{- end }} - labels: - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -{{- if .Values.service.labels }} -{{ toYaml .Values.service.labels | indent 4 }} -{{- end }} -spec: - template: - metadata: - annotations: - autoscaling.knative.dev/minScale: "0" -{{- if .Values.podsLabels }} - labels: -{{ toYaml .Values.podsLabels | indent 8 }} -{{- end }} - spec: - containers: - - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - env: - - name: VERSION - value: {{ .Chart.Version }} -{{- range $pkey, $pval := .Values.env }} - - name: {{ $pkey }} - value: {{ quote $pval }} -{{- end }} - livenessProbe: - httpGet: - path: {{ .Values.livenessProbe.probePath | default .Values.probePath }} - initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} - periodSeconds: {{ .Values.livenessProbe.periodSeconds }} - successThreshold: {{ .Values.livenessProbe.successThreshold }} - timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} - readinessProbe: - failureThreshold: {{ .Values.readinessProbe.failureThreshold }} - httpGet: - path: {{ .Values.readinessProbe.probePath | default .Values.probePath }} - periodSeconds: {{ .Values.readinessProbe.periodSeconds }} - successThreshold: {{ .Values.readinessProbe.successThreshold }} - timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} - resources: -{{ toYaml .Values.resources | indent 14 }} -{{- end }} diff --git a/charts/substrate-faucet/templates/sa.yaml b/charts/substrate-faucet/templates/sa.yaml deleted file mode 100755 index c1f9836..0000000 --- a/charts/substrate-faucet/templates/sa.yaml +++ /dev/null @@ -1,16 +0,0 @@ -{{- if .Values.serviceAccount.enabled }} -apiVersion: v1 -kind: ServiceAccount -metadata: -{{- if .Values.serviceAccount.name }} - name: {{ .Values.serviceAccount.name }} -{{- else }} - name: {{ template "fullname" . }} -{{- end }} - {{- if .Values.serviceAccount.labels }} - labels: {{- toYaml .Values.serviceAccount.labels | nindent 4 }} - {{- end }} - {{- if .Values.serviceAccount.annotations }} - annotations: {{ toYaml .Values.serviceAccount.annotations | nindent 4 }} - {{- end }} -{{- end }} diff --git a/charts/substrate-faucet/templates/service.yaml b/charts/substrate-faucet/templates/service.yaml deleted file mode 100755 index 67664f3..0000000 --- a/charts/substrate-faucet/templates/service.yaml +++ /dev/null @@ -1,29 +0,0 @@ -{{- if or .Values.knativeDeploy .Values.canary.enabled }} -{{- else }} -apiVersion: v1 -kind: Service -metadata: -{{- if .Values.service.name }} - name: {{ .Values.service.name }} -{{- else }} - name: {{ template "fullname" . }} -{{- end }} - labels: - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" -{{- if .Values.service.labels }} -{{ toYaml .Values.service.labels | indent 4 }} -{{- end }} -{{- if .Values.service.annotations }} - annotations: -{{ toYaml .Values.service.annotations | indent 4 }} -{{- end }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.externalPort }} - targetPort: {{ .Values.service.internalPort }} - protocol: TCP - name: http - selector: - app: {{ template "fullname" . }} -{{- end }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml deleted file mode 100755 index 5ddce0d..0000000 --- a/charts/substrate-faucet/values.yaml +++ /dev/null @@ -1,149 +0,0 @@ -# Default values for your projects. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. -replicaCount: 1 -# Add annotations to the pods -podAnnotations: {} -# Add labels to the pods -podsLabels: {} -# Add labels to the deployment -deploymentLabels: {} - -image: - repository: draft - tag: dev - pullPolicy: IfNotPresent - -# optional list of image pull secrets to use to pull images -jx: - # optional image pull secrets - imagePullSecrets: [] - - # whether to create a Release CRD when installing charts with Release CRDs included - releaseCRD: true - -# define environment variables here as a map of key: value -env: -envconfigmap: - name: substrate-faucet-configmap -envFrom: - - configMapRef: - name: agung-faucet-bot-config - -botConfig: - NODE_RPC: "wss://wss.agung.peaq.network" - TOKENS_TO_SEND: "1000000000000000000" - TOKEN_SYMBOL: "AGNG" - ISSUE_INTERVAL: 60 - REDIS_IP: "127.0.0.1" - REDIS_PORT: "6379" - PROMETHEUS_PORT: "8080" - -botSecrets: - name: agung-faucet-bot-secret - -service: - name: substrate-faucet - type: ClusterIP - externalPort: 80 - internalPort: 8080 - annotations: {} - # Add labels to the service - labels: {} - -# enable this flag to use knative serve to deploy the app -knativeDeploy: false - -# HorizontalPodAutoscaler -hpa: - enabled: false - minReplicas: 1 - maxReplicas: 4 - cpuTargetAverageUtilization: 80 - memoryTargetAverageUtilization: 80 - # Add labels to the HPA - labels: {} - -# Canary deployments -# If enabled, Istio and Flagger need to be installed in the cluster -canary: - enabled: false - progressDeadlineSeconds: 60 - analysis: - interval: "1m" - threshold: 5 - maxWeight: 60 - stepWeight: 20 - # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. - metrics: - latency: - threshold: 500 - interval: "1m" - # The host is using Istio Gateway or the underlying ingress mechanism - # This value is defaulted from the environments jx-requirements.yml ingress configuration - host: "" - # Add labels to the canary - labels: {} - # Add labels to the canary gateway - gatewayLabels: {} - -resources: - limits: {} - requests: {} -probePath: / -livenessProbe: - initialDelaySeconds: 60 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 1 - # Optional distinct liveness probe path, if empty the probePath is used - probePath: "" -readinessProbe: - failureThreshold: 1 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 1 - # Optional distinct readiness probe path, if empty the probePath is used - probePath: "" - -# custom ingress annotations on this service -ingress: - annotations: {} - # defaults to nginx if no other ingress class annotation specified - classAnnotation: "" - # Add labels to the ingress - labels: {} - - # ingress path type - pathType: ImplementationSpecific - -serviceAccount: - enabled: true - name: "" - annotations: {} -# iam.gke.io/gcp-service-account: my-sa-in-gke - # Add labels to the SA - labels: {} -# my-custom-label: value - -# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 -jxRequirements: - ingress: - # shared ingress annotations on all services - annotations: {} - # kubernetes.io/ingress.class: nginx - - apiVersion: "networking.k8s.io/v1" - - # the domain for hosts - domain: "" - externalDNS: false - namespaceSubDomain: -jx. - serviceType: "" - tls: - email: "" - enabled: false - production: false - secretName: "" - - diff --git a/preview/Kptfile b/preview/Kptfile deleted file mode 100644 index 6e6ae8a..0000000 --- a/preview/Kptfile +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: kpt.dev/v1alpha1 -kind: Kptfile -metadata: - name: preview -upstream: - type: git - git: - commit: b52b35506a05e046d54615c3ade97f3aef8bfb08 - repo: https://github.com/jenkins-x/jx3-pipeline-catalog - directory: /helm/preview - ref: master diff --git a/preview/helmfile.yaml b/preview/helmfile.yaml deleted file mode 100644 index 7485be5..0000000 --- a/preview/helmfile.yaml +++ /dev/null @@ -1,31 +0,0 @@ -environments: - default: - values: - - jx-values.yaml -repositories: -- name: jx3 - url: https://jenkins-x-charts.github.io/repo -releases: -- chart: jx3/jx-verify - name: jx-verify - namespace: '{{ requiredEnv "PREVIEW_NAMESPACE" }}' -- chart: '../charts/{{ requiredEnv "APP_NAME" }}' - name: preview - wait: true - createNamespace: true - namespace: '{{ requiredEnv "PREVIEW_NAMESPACE" }}' - values: - - jx-values.yaml - - values.yaml.gotmpl - hooks: - - events: ["presync"] - showlogs: true - command: "jx" - args: - - secret - - copy - - --create-namespace - - --selector - - "secret.jenkins-x.io/replica-source=true" - - --to - - '{{ requiredEnv "PREVIEW_NAMESPACE" }}' diff --git a/preview/values.yaml.gotmpl b/preview/values.yaml.gotmpl deleted file mode 100644 index 0283df2..0000000 --- a/preview/values.yaml.gotmpl +++ /dev/null @@ -1,8 +0,0 @@ -jxRequirements: - ingress: - namespaceSubDomain: "-pr{{ requiredEnv "PULL_NUMBER" }}." - -image: - repository: "{{ requiredEnv "DOCKER_REGISTRY" }}/{{ requiredEnv "DOCKER_REGISTRY_ORG" }}/{{ requiredEnv "APP_NAME" }}" - tag: "{{ requiredEnv "VERSION" }}" - pullPolicy: "Always" From 374c451f9a151123e0326858c45f652035973165 Mon Sep 17 00:00:00 2001 From: peaqbot Date: Sun, 30 Jun 2024 14:54:06 +0200 Subject: [PATCH 50/52] chore: Jenkins X build pack --- .lighthouse/jenkins-x/pullrequest.yaml | 41 ++++++ .lighthouse/jenkins-x/release.yaml | 47 ++++++ .lighthouse/jenkins-x/triggers.yaml | 16 ++ charts/substrate-faucet/.helmignore | 21 +++ charts/substrate-faucet/Chart.yaml | 5 + charts/substrate-faucet/Kptfile | 11 ++ charts/substrate-faucet/Makefile | 48 ++++++ charts/substrate-faucet/README.md | 1 + charts/substrate-faucet/templates/NOTES.txt | 4 + .../substrate-faucet/templates/_helpers.tpl | 16 ++ charts/substrate-faucet/templates/canary.yaml | 66 +++++++++ .../templates/deployment.yaml | 79 ++++++++++ charts/substrate-faucet/templates/hpa.yaml | 28 ++++ .../substrate-faucet/templates/ingress.yaml | 50 +++++++ charts/substrate-faucet/templates/ksvc.yaml | 51 +++++++ charts/substrate-faucet/templates/sa.yaml | 16 ++ .../substrate-faucet/templates/service.yaml | 29 ++++ charts/substrate-faucet/values.yaml | 137 ++++++++++++++++++ preview/Kptfile | 11 ++ preview/helmfile.yaml | 31 ++++ preview/values.yaml.gotmpl | 8 + 21 files changed, 716 insertions(+) create mode 100644 .lighthouse/jenkins-x/pullrequest.yaml create mode 100644 .lighthouse/jenkins-x/release.yaml create mode 100644 .lighthouse/jenkins-x/triggers.yaml create mode 100755 charts/substrate-faucet/.helmignore create mode 100644 charts/substrate-faucet/Chart.yaml create mode 100755 charts/substrate-faucet/Kptfile create mode 100755 charts/substrate-faucet/Makefile create mode 100755 charts/substrate-faucet/README.md create mode 100755 charts/substrate-faucet/templates/NOTES.txt create mode 100755 charts/substrate-faucet/templates/_helpers.tpl create mode 100755 charts/substrate-faucet/templates/canary.yaml create mode 100755 charts/substrate-faucet/templates/deployment.yaml create mode 100755 charts/substrate-faucet/templates/hpa.yaml create mode 100755 charts/substrate-faucet/templates/ingress.yaml create mode 100755 charts/substrate-faucet/templates/ksvc.yaml create mode 100755 charts/substrate-faucet/templates/sa.yaml create mode 100755 charts/substrate-faucet/templates/service.yaml create mode 100755 charts/substrate-faucet/values.yaml create mode 100644 preview/Kptfile create mode 100644 preview/helmfile.yaml create mode 100644 preview/values.yaml.gotmpl diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml new file mode 100644 index 0000000..f1cd198 --- /dev/null +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -0,0 +1,41 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: pullrequest +spec: + pipelineSpec: + tasks: + - name: from-build-pack + resources: {} + taskSpec: + metadata: {} + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/pullrequest.yaml@versionStream + name: "" + resources: + # override limits for all containers here + limits: {} + workingDir: /workspace/source + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone-pr.yaml@versionStream + name: "" + resources: {} + - name: jx-variables + resources: + # override requests for the pod here + requests: + cpu: 400m + memory: 512Mi + - name: build-python-unittest + resources: {} + - name: check-registry + resources: {} + - name: build-container-build + resources: {} + - name: promote-jx-preview + resources: {} + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 12h0m0s +status: {} diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml new file mode 100644 index 0000000..45a4dfc --- /dev/null +++ b/.lighthouse/jenkins-x/release.yaml @@ -0,0 +1,47 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: release +spec: + pipelineSpec: + tasks: + - name: from-build-pack + resources: {} + taskSpec: + metadata: {} + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/python/release.yaml@versionStream + name: "" + resources: + # override limits for all containers here + limits: {} + workingDir: /workspace/source + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone.yaml@versionStream + name: "" + resources: {} + - name: next-version + resources: {} + - name: jx-variables + resources: + # override requests for the pod here + requests: + cpu: 400m + memory: 512Mi + - name: build-python-unittest + resources: {} + - name: check-registry + resources: {} + - name: build-container-build + resources: {} + - name: promote-changelog + resources: {} + - name: promote-helm-release + resources: {} + - name: promote-jx-promote + resources: {} + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 12h0m0s +status: {} diff --git a/.lighthouse/jenkins-x/triggers.yaml b/.lighthouse/jenkins-x/triggers.yaml new file mode 100644 index 0000000..ae2fcfa --- /dev/null +++ b/.lighthouse/jenkins-x/triggers.yaml @@ -0,0 +1,16 @@ +apiVersion: config.lighthouse.jenkins-x.io/v1alpha1 +kind: TriggerConfig +spec: + presubmits: + - name: pr + context: "pr" + always_run: true + optional: false + source: "pullrequest.yaml" + postsubmits: + - name: release + context: "release" + source: "release.yaml" + branches: + - ^main$ + - ^master$ diff --git a/charts/substrate-faucet/.helmignore b/charts/substrate-faucet/.helmignore new file mode 100755 index 0000000..f0c1319 --- /dev/null +++ b/charts/substrate-faucet/.helmignore @@ -0,0 +1,21 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/substrate-faucet/Chart.yaml b/charts/substrate-faucet/Chart.yaml new file mode 100644 index 0000000..3be8323 --- /dev/null +++ b/charts/substrate-faucet/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +icon: https://raw.githubusercontent.com/cdfoundation/artwork/master/jenkinsx/icon/color/jenkinsx-icon-color.png +name: substrate-faucet +version: 0.1.0-SNAPSHOT diff --git a/charts/substrate-faucet/Kptfile b/charts/substrate-faucet/Kptfile new file mode 100755 index 0000000..2a814c7 --- /dev/null +++ b/charts/substrate-faucet/Kptfile @@ -0,0 +1,11 @@ +apiVersion: kpt.dev/v1alpha1 +kind: Kptfile +metadata: + name: charts +upstream: + type: git + git: + commit: b52b35506a05e046d54615c3ade97f3aef8bfb08 + repo: https://github.com/jenkins-x/jx3-pipeline-catalog + directory: /helm/charts + ref: master diff --git a/charts/substrate-faucet/Makefile b/charts/substrate-faucet/Makefile new file mode 100755 index 0000000..bdc3a42 --- /dev/null +++ b/charts/substrate-faucet/Makefile @@ -0,0 +1,48 @@ +CHART_REPO := http://jenkins-x-chartmuseum:8080 +CURRENT=$(pwd) +NAME := substrate-faucet +OS := $(shell uname) +RELEASE_VERSION := $(shell cat ../../VERSION) + +build: clean + rm -rf requirements.lock + helm dependency build + helm lint + +install: clean build + helm install . --name ${NAME} + +upgrade: clean build + helm upgrade ${NAME} . + +delete: + helm delete --purge ${NAME} + +clean: + rm -rf charts + rm -rf ${NAME}*.tgz + +release: clean + helm dependency build + helm lint + helm init --client-only + helm package . + curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts + rm -rf ${NAME}*.tgz% + +tag: +ifeq ($(OS),Darwin) + sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml + sed -i "" -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml +else ifeq ($(OS),Linux) + sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml + sed -i -e "s|repository:.*|repository: $(DOCKER_REGISTRY)\/peaqnetwork\/substrate-faucet|" values.yaml + sed -i -e "s/tag:.*/tag: $(RELEASE_VERSION)/" values.yaml +else + echo "platfrom $(OS) not supported to release from" + exit -1 +endif + git add --all + git commit -m "chore: release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed + git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)" + git push origin v$(RELEASE_VERSION) diff --git a/charts/substrate-faucet/README.md b/charts/substrate-faucet/README.md new file mode 100755 index 0000000..89f8286 --- /dev/null +++ b/charts/substrate-faucet/README.md @@ -0,0 +1 @@ +# my application \ No newline at end of file diff --git a/charts/substrate-faucet/templates/NOTES.txt b/charts/substrate-faucet/templates/NOTES.txt new file mode 100755 index 0000000..97823be --- /dev/null +++ b/charts/substrate-faucet/templates/NOTES.txt @@ -0,0 +1,4 @@ + +Get the application URL by running these commands: + +kubectl get ingress {{ template "fullname" . }} diff --git a/charts/substrate-faucet/templates/_helpers.tpl b/charts/substrate-faucet/templates/_helpers.tpl new file mode 100755 index 0000000..f0d83d2 --- /dev/null +++ b/charts/substrate-faucet/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "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). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/substrate-faucet/templates/canary.yaml b/charts/substrate-faucet/templates/canary.yaml new file mode 100755 index 0000000..b5f55d3 --- /dev/null +++ b/charts/substrate-faucet/templates/canary.yaml @@ -0,0 +1,66 @@ +{{- if .Values.canary.enabled }} +apiVersion: flagger.app/v1beta1 +kind: Canary +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.canary.labels }} +{{ toYaml .Values.canary.labels | indent 4 }} +{{- end }} +spec: + provider: istio + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + progressDeadlineSeconds: {{ .Values.canary.progressDeadlineSeconds }} + {{- if .Values.hpa.enabled }} + autoscalerRef: + apiVersion: autoscaling/v2beta1 + kind: HorizontalPodAutoscaler + name: {{ template "fullname" . }} + {{- end }} + service: + port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + gateways: + - {{ template "fullname" . }} + hosts: + - {{ .Values.canary.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain) }} + analysis: + interval: {{ .Values.canary.analysis.interval }} + threshold: {{ .Values.canary.analysis.threshold }} + maxWeight: {{ .Values.canary.analysis.maxWeight }} + stepWeight: {{ .Values.canary.analysis.stepWeight }} + metrics: + - name: latency + templateRef: + name: latency + namespace: istio-system + thresholdRange: + max: {{ .Values.canary.analysis.metrics.latency.threshold }} + interval: {{ .Values.canary.analysis.metrics.latency.interval | quote }} + +--- + +apiVersion: networking.istio.io/v1alpha3 +kind: Gateway +metadata: + name: {{ template "fullname" . }} +{{- if .Values.canary.gatewayLabels }} + labels: +{{ toYaml .Values.canary.gatewayLabels | indent 4 }} +{{- end }} +spec: + selector: + istio: ingressgateway + servers: + - port: + number: {{ .Values.service.externalPort }} + name: http + protocol: HTTP + hosts: + - {{ .Values.canary.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain) }} +{{- end }} diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml new file mode 100755 index 0000000..a5e4c62 --- /dev/null +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -0,0 +1,79 @@ +{{- if .Values.knativeDeploy }} +{{- else }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.deploymentLabels }} +{{ toYaml .Values.deploymentLabels | indent 4 }} +{{- end }} +spec: + selector: + matchLabels: + app: {{ template "fullname" . }} +{{- if .Values.hpa.enabled }} +{{- else }} + replicas: {{ .Values.replicaCount }} +{{- end }} + template: + metadata: + labels: + draft: {{ default "draft-app" .Values.draft }} + app: {{ template "fullname" . }} +{{- if .Values.podsLabels }} +{{ toYaml .Values.podsLabels | indent 6 }} +{{- end }} +{{- if .Values.podAnnotations }} + annotations: +{{ toYaml .Values.podAnnotations | indent 8 }} +{{- end }} + spec: +{{- if .Values.serviceAccount.enabled }} +{{- if .Values.serviceAccount.name }} + serviceAccountName: {{ .Values.serviceAccount.name }} +{{- else }} + serviceAccountName: {{ template "fullname" . }} +{{- end }} +{{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: VERSION + value: {{ .Chart.Version }} +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ quote $pval }} +{{- end }} + envFrom: +{{ toYaml .Values.envFrom | indent 10 }} + ports: + - name: http + containerPort: {{ .Values.service.internalPort }} + livenessProbe: + httpGet: + path: {{ .Values.livenessProbe.probePath | default .Values.probePath }} + port: {{ .Values.service.internalPort }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.readinessProbe.probePath | default .Values.probePath }} + port: {{ .Values.service.internalPort }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 12 }} + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} + imagePullSecrets: +{{- range $pval := .Values.jx.imagePullSecrets }} + - name: {{ quote $pval }} +{{- end }} +{{- end }} diff --git a/charts/substrate-faucet/templates/hpa.yaml b/charts/substrate-faucet/templates/hpa.yaml new file mode 100755 index 0000000..a20a001 --- /dev/null +++ b/charts/substrate-faucet/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.hpa.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "fullname" . }} + labels: + draft: {{ default "draft-app" .Values.draft }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.hpa.labels }} +{{ toYaml .Values.hpa.labels | indent 4 }} +{{- end }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "fullname" . }} + minReplicas: {{ .Values.hpa.minReplicas }} + maxReplicas: {{ .Values.hpa.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.hpa.cpuTargetAverageUtilization }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.hpa.memoryTargetAverageUtilization }} +{{- end }} \ No newline at end of file diff --git a/charts/substrate-faucet/templates/ingress.yaml b/charts/substrate-faucet/templates/ingress.yaml new file mode 100755 index 0000000..8f5c32e --- /dev/null +++ b/charts/substrate-faucet/templates/ingress.yaml @@ -0,0 +1,50 @@ +{{- if and (or .Values.ingress.host .Values.jxRequirements.ingress.domain) (not .Values.knativeDeploy) }} +{{- $host := (.Values.ingress.host | default (printf "%s%s%s" .Values.service.name .Values.jxRequirements.ingress.namespaceSubDomain .Values.jxRequirements.ingress.domain)) | quote }} +{{- $annotations := dict }} +{{- $_ := merge $annotations .Values.ingress.annotations .Values.jxRequirements.ingress.annotations }} +{{- if not (hasKey $annotations "kubernetes.io/ingress.class") }} +{{- $_ := set $annotations "kubernetes.io/ingress.class" (.Values.ingress.classAnnotation | default "nginx") }} +{{- end }} +{{- if and (hasKey .Values.jxRequirements.ingress "serviceType") (.Values.jxRequirements.ingress.serviceType) (eq .Values.jxRequirements.ingress.serviceType "NodePort") (not (hasKey $annotations "jenkins.io/host")) }} +{{- $_ := set $annotations "jenkins.io/host" .Values.jxRequirements.ingress.domain }} +{{- end }} +apiVersion: {{ .Values.jxRequirements.ingress.apiVersion }} +kind: Ingress +metadata: + annotations: +{{- if $annotations }} +{{ toYaml $annotations | indent 4 }} +{{- end }} + name: {{ .Values.service.name }} +{{- if .Values.ingress.labels }} + labels: +{{ toYaml .Values.ingress.labels | indent 4 }} +{{- end }} +spec: + rules: + - http: + paths: + - pathType: {{ .Values.ingress.pathType | default "ImplementationSpecific" }} + backend: + service: + name: {{ .Values.service.name }} + port: + number: {{ .Values.service.externalPort }} +{{- if eq "NodePort" .Values.jxRequirements.ingress.serviceType }} + path: "/{{ .Release.Namespace }}/hook" +{{- else if or .Values.ingress.host .Values.jxRequirements.ingress.domain }} + host: {{ $host }} +{{- end }} +{{- if .Values.jxRequirements.ingress.tls.enabled }} + tls: + - hosts: + - {{ $host }} +{{- if and (hasKey .Values.jxRequirements.ingress.tls "secretName") (.Values.jxRequirements.ingress.tls.secretName) }} + secretName: "{{ .Values.jxRequirements.ingress.tls.secretName }}" +{{- else if .Values.jxRequirements.ingress.tls.production }} + secretName: "tls-{{ .Values.ingress.host | default .Values.jxRequirements.ingress.domain | replace "." "-" }}-p" +{{- else }} + secretName: "tls-{{ .Values.ingress.host | default .Values.jxRequirements.ingress.domain | replace "." "-" }}-s" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/substrate-faucet/templates/ksvc.yaml b/charts/substrate-faucet/templates/ksvc.yaml new file mode 100755 index 0000000..ebf2a53 --- /dev/null +++ b/charts/substrate-faucet/templates/ksvc.yaml @@ -0,0 +1,51 @@ +{{- if .Values.knativeDeploy }} +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + {{- if .Values.service.name }} + name: {{ .Values.service.name }} + {{- else }} + name: {{ template "fullname" . }} + {{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.service.labels }} +{{ toYaml .Values.service.labels | indent 4 }} +{{- end }} +spec: + template: + metadata: + annotations: + autoscaling.knative.dev/minScale: "0" +{{- if .Values.podsLabels }} + labels: +{{ toYaml .Values.podsLabels | indent 8 }} +{{- end }} + spec: + containers: + - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: VERSION + value: {{ .Chart.Version }} +{{- range $pkey, $pval := .Values.env }} + - name: {{ $pkey }} + value: {{ quote $pval }} +{{- end }} + livenessProbe: + httpGet: + path: {{ .Values.livenessProbe.probePath | default .Values.probePath }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + readinessProbe: + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + httpGet: + path: {{ .Values.readinessProbe.probePath | default .Values.probePath }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + resources: +{{ toYaml .Values.resources | indent 14 }} +{{- end }} diff --git a/charts/substrate-faucet/templates/sa.yaml b/charts/substrate-faucet/templates/sa.yaml new file mode 100755 index 0000000..c1f9836 --- /dev/null +++ b/charts/substrate-faucet/templates/sa.yaml @@ -0,0 +1,16 @@ +{{- if .Values.serviceAccount.enabled }} +apiVersion: v1 +kind: ServiceAccount +metadata: +{{- if .Values.serviceAccount.name }} + name: {{ .Values.serviceAccount.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + {{- if .Values.serviceAccount.labels }} + labels: {{- toYaml .Values.serviceAccount.labels | nindent 4 }} + {{- end }} + {{- if .Values.serviceAccount.annotations }} + annotations: {{ toYaml .Values.serviceAccount.annotations | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/substrate-faucet/templates/service.yaml b/charts/substrate-faucet/templates/service.yaml new file mode 100755 index 0000000..67664f3 --- /dev/null +++ b/charts/substrate-faucet/templates/service.yaml @@ -0,0 +1,29 @@ +{{- if or .Values.knativeDeploy .Values.canary.enabled }} +{{- else }} +apiVersion: v1 +kind: Service +metadata: +{{- if .Values.service.name }} + name: {{ .Values.service.name }} +{{- else }} + name: {{ template "fullname" . }} +{{- end }} + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.service.labels }} +{{ toYaml .Values.service.labels | indent 4 }} +{{- end }} +{{- if .Values.service.annotations }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +{{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: http + selector: + app: {{ template "fullname" . }} +{{- end }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml new file mode 100755 index 0000000..8675877 --- /dev/null +++ b/charts/substrate-faucet/values.yaml @@ -0,0 +1,137 @@ +# Default values for your projects. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +# Add annotations to the pods +podAnnotations: {} +# Add labels to the pods +podsLabels: {} +# Add labels to the deployment +deploymentLabels: {} + +image: + repository: draft + tag: dev + pullPolicy: IfNotPresent + +# optional list of image pull secrets to use to pull images +jx: + # optional image pull secrets + imagePullSecrets: [] + + # whether to create a Release CRD when installing charts with Release CRDs included + releaseCRD: true + +# define environment variables here as a map of key: value +env: + +# enable this flag to use knative serve to deploy the app +knativeDeploy: false + +# HorizontalPodAutoscaler +hpa: + enabled: false + minReplicas: 2 + maxReplicas: 6 + cpuTargetAverageUtilization: 80 + memoryTargetAverageUtilization: 80 + # Add labels to the HPA + labels: {} + +# Canary deployments +# If enabled, Istio and Flagger need to be installed in the cluster +canary: + enabled: false + progressDeadlineSeconds: 60 + analysis: + interval: "1m" + threshold: 5 + maxWeight: 60 + stepWeight: 20 + # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. + metrics: + latency: + threshold: 500 + interval: "1m" + # The host is using Istio Gateway or the underlying ingress mechanism + # This value is defaulted from the environments jx-requirements.yml ingress configuration + host: "" + # Add labels to the canary + labels: {} + # Add labels to the canary gateway + gatewayLabels: {} + +service: + name: substrate-faucet + type: ClusterIP + externalPort: 80 + internalPort: 8080 + annotations: {} + # Add labels to the service + labels: {} +resources: + limits: + cpu: 400m + memory: 256Mi + requests: + cpu: 200m + memory: 128Mi +probePath: / +livenessProbe: + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + # Optional distinct liveness probe path, if empty the probePath is used + probePath: "" +readinessProbe: + failureThreshold: 1 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + # Optional distinct readiness probe path, if empty the probePath is used + probePath: "" + +# custom ingress annotations on this service +ingress: + annotations: {} + # defaults to nginx if no other ingress class annotation specified + classAnnotation: "" + # Add labels to the ingress + labels: {} + # defaults to .service.name + jxRequirements.ingress.namespaceSubDomain + jxRequirements.ingress.domain + host: "" + + # ingress path type + pathType: ImplementationSpecific + +serviceAccount: + enabled: true + name: "" + annotations: {} +# iam.gke.io/gcp-service-account: my-sa-in-gke + # Add labels to the SA + labels: {} +# my-custom-label: value + +# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 +jxRequirements: + ingress: + # shared ingress annotations on all services + annotations: {} + # kubernetes.io/ingress.class: nginx + + apiVersion: "networking.k8s.io/v1" + + # the domain for hosts + domain: "" + externalDNS: false + namespaceSubDomain: -jx. + serviceType: "" + tls: + email: "" + enabled: false + production: false + secretName: "" + + diff --git a/preview/Kptfile b/preview/Kptfile new file mode 100644 index 0000000..6e6ae8a --- /dev/null +++ b/preview/Kptfile @@ -0,0 +1,11 @@ +apiVersion: kpt.dev/v1alpha1 +kind: Kptfile +metadata: + name: preview +upstream: + type: git + git: + commit: b52b35506a05e046d54615c3ade97f3aef8bfb08 + repo: https://github.com/jenkins-x/jx3-pipeline-catalog + directory: /helm/preview + ref: master diff --git a/preview/helmfile.yaml b/preview/helmfile.yaml new file mode 100644 index 0000000..7485be5 --- /dev/null +++ b/preview/helmfile.yaml @@ -0,0 +1,31 @@ +environments: + default: + values: + - jx-values.yaml +repositories: +- name: jx3 + url: https://jenkins-x-charts.github.io/repo +releases: +- chart: jx3/jx-verify + name: jx-verify + namespace: '{{ requiredEnv "PREVIEW_NAMESPACE" }}' +- chart: '../charts/{{ requiredEnv "APP_NAME" }}' + name: preview + wait: true + createNamespace: true + namespace: '{{ requiredEnv "PREVIEW_NAMESPACE" }}' + values: + - jx-values.yaml + - values.yaml.gotmpl + hooks: + - events: ["presync"] + showlogs: true + command: "jx" + args: + - secret + - copy + - --create-namespace + - --selector + - "secret.jenkins-x.io/replica-source=true" + - --to + - '{{ requiredEnv "PREVIEW_NAMESPACE" }}' diff --git a/preview/values.yaml.gotmpl b/preview/values.yaml.gotmpl new file mode 100644 index 0000000..0283df2 --- /dev/null +++ b/preview/values.yaml.gotmpl @@ -0,0 +1,8 @@ +jxRequirements: + ingress: + namespaceSubDomain: "-pr{{ requiredEnv "PULL_NUMBER" }}." + +image: + repository: "{{ requiredEnv "DOCKER_REGISTRY" }}/{{ requiredEnv "DOCKER_REGISTRY_ORG" }}/{{ requiredEnv "APP_NAME" }}" + tag: "{{ requiredEnv "VERSION" }}" + pullPolicy: "Always" From 27b44a663d8e5897be1e965c542f761a6be85362 Mon Sep 17 00:00:00 2001 From: hussain Date: Sun, 30 Jun 2024 15:28:11 +0200 Subject: [PATCH 51/52] ci-fix: pipelines re-configuration --- .lighthouse/jenkins-x/pullrequest.yaml | 10 ++--- .lighthouse/jenkins-x/release.yaml | 8 ++-- .../templates/deployment.yaml | 45 +++++++++++++++++++ charts/substrate-faucet/values.yaml | 32 ++++++++++--- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/.lighthouse/jenkins-x/pullrequest.yaml b/.lighthouse/jenkins-x/pullrequest.yaml index f1cd198..0719262 100644 --- a/.lighthouse/jenkins-x/pullrequest.yaml +++ b/.lighthouse/jenkins-x/pullrequest.yaml @@ -22,11 +22,11 @@ spec: name: "" resources: {} - name: jx-variables - resources: - # override requests for the pod here - requests: - cpu: 400m - memory: 512Mi + resources: {} + # # override requests for the pod here + # requests: + # cpu: 400m + # memory: 512Mi - name: build-python-unittest resources: {} - name: check-registry diff --git a/.lighthouse/jenkins-x/release.yaml b/.lighthouse/jenkins-x/release.yaml index 45a4dfc..a23b973 100644 --- a/.lighthouse/jenkins-x/release.yaml +++ b/.lighthouse/jenkins-x/release.yaml @@ -24,11 +24,11 @@ spec: - name: next-version resources: {} - name: jx-variables - resources: + resources: {} # override requests for the pod here - requests: - cpu: 400m - memory: 512Mi + # requests: + # cpu: 400m + # memory: 512Mi - name: build-python-unittest resources: {} - name: check-registry diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index a5e4c62..ead6511 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -39,12 +39,57 @@ spec: {{- end }} {{- end }} containers: + - name: redis + image: redis:5.0.4 + ports: + - containerPort: 6379 + resources: + requests: {} + readinessProbe: + tcpSocket: + port: 6379 + initialDelaySeconds: 30 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: 6379 + initialDelaySeconds: 30 + periodSeconds: 20 - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + envFrom: + - configMapRef: + name: {{ .Values.envconfigmap.name }} env: - name: VERSION value: {{ .Chart.Version }} + - name: DISCORD_BOT_TOKEN + valueFrom: + secretKeyRef: + name: {{ .Values.botSecrets.name }} + key: DISCORD_BOT_TOKEN + optional: false + - name: FAUCET_MNEMONIC + valueFrom: + secretKeyRef: + name: {{ .Values.botSecrets.name }} + key: FAUCET_MNEMONIC + optional: false + #- name: NODE_RPC + # value: "{{ .Values.botConfig.NODE_RPC }}" + - name: TOKENS_TO_SEND + value: "{{ .Values.botConfig.TOKENS_TO_SEND }}" + - name: TOKEN_SYMBOL + value: "{{ .Values.botConfig.TOKEN_SYMBOL }}" + - name: ISSUE_INTERVAL + value: "{{ .Values.botConfig.ISSUE_INTERVAL }}" + - name: REDIS_IP + value: "{{ .Values.botConfig.REDIS_IP }}" + - name: REDIS_PORT + value: "{{ .Values.botConfig.REDIS_PORT }}" + - name: PROMETHEUS_PORT + value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" {{- range $pkey, $pval := .Values.env }} - name: {{ $pkey }} value: {{ quote $pval }} diff --git a/charts/substrate-faucet/values.yaml b/charts/substrate-faucet/values.yaml index 8675877..834a49e 100755 --- a/charts/substrate-faucet/values.yaml +++ b/charts/substrate-faucet/values.yaml @@ -23,7 +23,25 @@ jx: releaseCRD: true # define environment variables here as a map of key: value + env: +envconfigmap: + name: substrate-faucet-configmap +envFrom: + - configMapRef: + name: agung-faucet-bot-config + +botConfig: + NODE_RPC: "wss://wss.agung.peaq.network" + TOKENS_TO_SEND: "1000000000000000000" + TOKEN_SYMBOL: "AGNG" + ISSUE_INTERVAL: 60 + REDIS_IP: "127.0.0.1" + REDIS_PORT: "6379" + PROMETHEUS_PORT: "8080" + +botSecrets: + name: agung-faucet-bot-secret # enable this flag to use knative serve to deploy the app knativeDeploy: false @@ -69,13 +87,13 @@ service: annotations: {} # Add labels to the service labels: {} -resources: - limits: - cpu: 400m - memory: 256Mi - requests: - cpu: 200m - memory: 128Mi +# resources: +# limits: +# cpu: 400m +# memory: 256Mi +# requests: +# cpu: 200m +# memory: 128Mi probePath: / livenessProbe: initialDelaySeconds: 60 From 9eb03b06c7b217b6ac6be5d013f3bef2935d6ec1 Mon Sep 17 00:00:00 2001 From: hussain Date: Sun, 30 Jun 2024 16:04:48 +0200 Subject: [PATCH 52/52] ci-fix: configmap fix --- charts/substrate-faucet/templates/deployment.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/charts/substrate-faucet/templates/deployment.yaml b/charts/substrate-faucet/templates/deployment.yaml index ead6511..b5a9802 100755 --- a/charts/substrate-faucet/templates/deployment.yaml +++ b/charts/substrate-faucet/templates/deployment.yaml @@ -90,12 +90,6 @@ spec: value: "{{ .Values.botConfig.REDIS_PORT }}" - name: PROMETHEUS_PORT value: "{{ .Values.botConfig.PROMETHEUS_PORT }}" -{{- range $pkey, $pval := .Values.env }} - - name: {{ $pkey }} - value: {{ quote $pval }} -{{- end }} - envFrom: -{{ toYaml .Values.envFrom | indent 10 }} ports: - name: http containerPort: {{ .Values.service.internalPort }}