Merge pull request #361 from arshamparity/frontend-helm

Frontend helm
This commit is contained in:
arshamparity
2021-08-11 13:32:48 +03:00
committed by GitHub
14 changed files with 382 additions and 75 deletions
+40 -20
View File
@@ -1,8 +1,10 @@
variables:
CONTAINER_REGISTRY: "docker.io/parity"
CONTAINER_REPO: "substrate-telemetry-backend"
KUBE_NAMESPACE: "substrate-telemetry"
IMAGE_FULL_NAME: "${CONTAINER_REGISTRY}/${CONTAINER_REPO}:${CI_COMMIT_SHORT_SHA}"
CONTAINER_REGISTRY: "docker.io/parity"
BACKEND_CONTAINER_REPO: "substrate-telemetry-backend"
FRONTEND_CONTAINER_REPO: "substrate-telemetry-frontend"
KUBE_NAMESPACE: "substrate-telemetry"
BACKEND_IMAGE_FULL_NAME: "${CONTAINER_REGISTRY}/${BACKEND_CONTAINER_REPO}:${CI_COMMIT_SHORT_SHA}"
FRONTEND_IMAGE_FULL_NAME: "${CONTAINER_REGISTRY}/${FRONTEND_CONTAINER_REPO}:${CI_COMMIT_SHORT_SHA}"
stages:
- dockerize
@@ -11,10 +13,19 @@ stages:
#.delete_deployment: &delete_deployment
# - helm uninstall -n "$KUBE_NAMESPACE" "$KUBE_NAMESPACE"
.dockerize: &dockerize
stage: dockerize
image: quay.io/buildah/stable
rules:
- if: '$CI_COMMIT_BRANCH == "jsdw-sharding"'
when: manual
tags:
- kubernetes-parity-build
.deploy-k8s: &deploy-k8s
image: paritytech/kubetools:3.5.3
script:
- echo "Deploying using image $IMAGE_FULL_NAME"
- echo "Deploying using image $BACKEND_IMAGE_FULL_NAME"
- echo "Using Helm `helm version --short`"
- export KUBERNETES_VERSION_TAG="$CI_PIPELINE_ID"
- |-
@@ -25,8 +36,10 @@ stages:
- helm --debug template
--create-namespace
--namespace $KUBE_NAMESPACE
--set image.repository="${CONTAINER_REGISTRY}/${CONTAINER_REPO}"
--set image.tag="${CI_COMMIT_SHORT_SHA}"
--set image.backend.repository="${CONTAINER_REGISTRY}/${BACKEND_CONTAINER_REPO}"
--set image.backend.tag="${CI_COMMIT_SHORT_SHA}"
--set image.frontend.repository="${CONTAINER_REGISTRY}/${FRONTEND_CONTAINER_REPO}"
--set image.frontend.tag="${CI_COMMIT_SHORT_SHA}"
$KUBE_NAMESPACE ./helm/
# install the chart into the relevant cluster
- helm --debug upgrade
@@ -35,8 +48,10 @@ stages:
--timeout 120s
--create-namespace
--namespace $KUBE_NAMESPACE
--set image.repository="${CONTAINER_REGISTRY}/${CONTAINER_REPO}"
--set image.tag="${CI_COMMIT_SHORT_SHA}"
--set image.backend.repository="${CONTAINER_REGISTRY}/${BACKEND_CONTAINER_REPO}"
--set image.backend.tag="${CI_COMMIT_SHORT_SHA}"
--set image.frontend.repository="${CONTAINER_REGISTRY}/${FRONTEND_CONTAINER_REPO}"
--set image.frontend.tag="${CI_COMMIT_SHORT_SHA}"
$KUBE_NAMESPACE ./helm/
rules:
- if: '$CI_COMMIT_BRANCH == "jsdw-sharding"'
@@ -44,22 +59,27 @@ stages:
tags:
- kubernetes-parity-build
dockerize:
stage: dockerize
image: quay.io/buildah/stable
dockerize-backend:
<<: &dockerize
script:
- echo "Building image $IMAGE_FULL_NAME"
- echo "Building image $BACKEND_IMAGE_FULL_NAME"
- buildah bud
--format=docker
--tag "$IMAGE_FULL_NAME" ./backend/
--tag "$BACKEND_IMAGE_FULL_NAME" ./backend/
- echo ${Docker_Hub_Pass_Parity} |
buildah login --username ${Docker_Hub_User_Parity} --password-stdin docker.io
- buildah push --format=v2s2 "$IMAGE_FULL_NAME"
rules:
- if: '$CI_COMMIT_BRANCH == "jsdw-sharding"'
when: manual
tags:
- kubernetes-parity-build
- buildah push --format=v2s2 "$BACKEND_IMAGE_FULL_NAME"
dockerize-frontend:
<<: &dockerize
script:
- echo "Building image $FRONTEND_IMAGE_FULL_NAME"
- buildah bud
--format=docker
--tag "$FRONTEND_IMAGE_FULL_NAME" ./frontend/
- echo ${Docker_Hub_Pass_Parity} |
buildah login --username ${Docker_Hub_User_Parity} --password-stdin docker.io
- buildah push --format=v2s2 "$FRONTEND_IMAGE_FULL_NAME"
deploy-parity-stg:
stage: staging
+3
View File
@@ -9,6 +9,9 @@ services:
volumes:
- /app/node_modules
- ./packages:/app/packages
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/default:/etc/nginx/sites-available/default
- ./env-config.js:/usr/share/nginx/html/env-config.js
ports:
- 3000:80
expose:
+8 -7
View File
@@ -1,5 +1,5 @@
#### BUILDER IMAGE ####
FROM node:12 as builder
FROM docker.io/node:12 as builder
LABEL maintainer="Chevdor <chevdor@gmail.com>"
LABEL description="Polkadot Telemetry frontend builder image"
@@ -11,7 +11,7 @@ RUN yarn install && \
yarn cache clean
#### OUTPUT IMAGE ####
FROM nginx:stable-alpine
FROM docker.io/nginx:stable-alpine
LABEL maintainer="Chevdor <chevdor@gmail.com>"
LABEL description="Polkadot Telemetry frontend"
@@ -19,13 +19,14 @@ ENV SUBSTRATE_TELEMETRY_URL=
WORKDIR /usr/share/nginx/html
COPY --from=builder /opt/builder/env.sh /usr/bin/
RUN apk add --no-cache bash; chmod +x /usr/bin/env.sh
#COPY --from=builder /opt/builder/env.sh /usr/bin/
#RUN apk add --no-cache bash; chmod +x /usr/bin/env.sh
COPY --from=builder /opt/builder/nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /opt/builder/nginx/default /etc/nginx/sites-available/default
#COPY --from=builder /opt/builder/nginx/nginx.conf /etc/nginx/nginx.conf
#COPY --from=builder /opt/builder/nginx/default /etc/nginx/sites-available/default
COPY --from=builder /opt/builder/build /usr/share/nginx/html
EXPOSE 80
CMD ["/bin/bash", "-c", "/usr/bin/env.sh && nginx -g \"daemon off;\""]
#CMD ["/bin/bash", "-c", "/usr/bin/env.sh && nginx -g \"daemon off;\""]
CMD [ "nginx", "-g" ,"daemon off;"]
+10 -3
View File
@@ -6,7 +6,7 @@ metadata:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
telemetry-component: core
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if not .Values.autoscaling.core.enabled }}
replicas: {{ .Values.replicaCount.core }}
{{- end }}
selector:
@@ -33,8 +33,15 @@ spec:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
image: "{{ .Values.image.backend.repository }}:{{ .Values.image.backend.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.backend.pullPolicy }}
{{- if .Values.envVars.core }}
env:
{{- range $key, $val := .Values.envVars.core }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- end }}
command:
- "telemetry_core"
args:
+29
View File
@@ -0,0 +1,29 @@
{{- if .Values.autoscaling.core.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: telemetry-core
labels:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
telemetry-component: core
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: telemetry-core
minReplicas: {{ .Values.autoscaling.core.minReplicas }}
maxReplicas: {{ .Values.autoscaling.core.maxReplicas }}
metrics:
{{- if .Values.autoscaling.core.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.core.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.core.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.core.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
+84
View File
@@ -0,0 +1,84 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: telemetry-frontend
labels:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
telemetry-component: frontend
spec:
{{- if not .Values.autoscaling.frontend.enabled }}
replicas: {{ .Values.replicaCount.frontend }}
{{- end }}
selector:
matchLabels:
{{- include "substrate-telemetry.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "substrate-telemetry.selectorLabels" . | nindent 8 }}
telemetry-component: frontend
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "substrate-telemetry.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.envVars.frontend }}
env:
{{- range $key, $val := .Values.envVars.frontend }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.frontend.targetPort }}
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: http
readinessProbe:
httpGet:
path: /health
port: http
volumeMounts:
- name: nginx
mountPath: "/etc/nginx/nginx.conf"
readOnly: true
- name: env-config
mountPath: "/usr/share/nginx/html/env-config.js"
readOnly: true
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: nginx
configMap:
name: frontend-nginx
- name: env-config
configMap:
name: frontend-env-config
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
+10
View File
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-env-config
data:
env-config.js: |
window.process_env = {
SUBSTRATE_TELEMETRY_URL: "ws://feed.telemetry.parity-stg.parity.io/feed",
SUBSTRATE_TELEMETRY_SAMPLE: "",
}
+29
View File
@@ -0,0 +1,29 @@
{{- if .Values.autoscaling.frontend.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: telemetry-frontend
labels:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
telemetry-component: frontend
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: telemetry-frontend
minReplicas: {{ .Values.autoscaling.frontend.minReplicas }}
maxReplicas: {{ .Values.autoscaling.frontend.maxReplicas }}
metrics:
{{- if .Values.autoscaling.frontend.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.frontend.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.frontend.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.frontend.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
@@ -1,9 +1,9 @@
{{- if .Values.ingress.enabled -}}
{{- if .Values.ingress.frontend.enabled -}}
{{- $fullName := include "substrate-telemetry.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- $svcPort := .Values.service.frontend.port -}}
{{- if and .Values.ingress.frontend.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.frontend.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.frontend.annotations "kubernetes.io/ingress.class" .Values.ingress.frontend.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
@@ -15,20 +15,21 @@ apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
name: telemetry-frontend
labels:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
telemetry-component: frontend
{{- with .Values.ingress.frontend.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- if and .Values.ingress.frontend.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.frontend.className }}
{{- end }}
{{- if .Values.ingress.tls }}
{{- if .Values.ingress.frontend.tls }}
tls:
{{- range .Values.ingress.tls }}
{{- range .Values.ingress.frontend.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
@@ -37,7 +38,7 @@ spec:
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
{{- range .Values.ingress.frontend.hosts }}
- host: {{ .host | quote }}
http:
paths:
@@ -49,11 +50,11 @@ spec:
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
name: telemetry-frontend
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
serviceName: telemetry-frontend
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
@@ -0,0 +1,37 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-nginx
data:
nginx.conf: |
user nginx;
worker_processes auto;
worker_rlimit_nofile 30000;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
server {
root /usr/share/nginx/html;
index index.html;
listen 80;
listen [::]:80;
server_name _;
}
events {
worker_connections 8000;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
include /etc/nginx/conf.d/*.conf;
}
+19
View File
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: telemetry-frontend
labels:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
telemetry-component: frontend
annotations:
{{- toYaml .Values.service.frontend.annotations | nindent 4 }}
spec:
type: {{ .Values.service.frontend.type }}
ports:
- port: {{ .Values.service.frontend.port }}
targetPort: {{ .Values.service.frontend.targetPort }}
protocol: TCP
name: http
selector:
{{- include "substrate-telemetry.selectorLabels" . | nindent 4 }}
telemetry-component: frontend
+10 -3
View File
@@ -6,7 +6,7 @@ metadata:
{{- include "substrate-telemetry.labels" . | nindent 4 }}
telemetry-component: shard
spec:
{{- if not .Values.autoscaling.enabled }}
{{- if not .Values.autoscaling.shard.enabled }}
replicas: {{ .Values.replicaCount.shard }}
{{- end }}
selector:
@@ -33,8 +33,15 @@ spec:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
image: "{{ .Values.image.backend.repository }}:{{ .Values.image.backend.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.backend.pullPolicy }}
{{- if .Values.envVars.shard }}
env:
{{- range $key, $val := .Values.envVars.shard }}
- name: {{ $key }}
value: {{ $val | quote }}
{{- end }}
{{- end }}
command:
- "telemetry_shard"
args:
+7 -7
View File
@@ -1,4 +1,4 @@
{{- if .Values.autoscaling.enabled }}
{{- if .Values.autoscaling.shard.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
@@ -11,19 +11,19 @@ spec:
apiVersion: apps/v1
kind: Deployment
name: telemetry-shard
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
minReplicas: {{ .Values.autoscaling.shard.minReplicas }}
maxReplicas: {{ .Values.autoscaling.shard.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- if .Values.autoscaling.shard.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
targetAverageUtilization: {{ .Values.autoscaling.shard.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- if .Values.autoscaling.shard.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
targetAverageUtilization: {{ .Values.autoscaling.shard.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
+81 -21
View File
@@ -5,17 +5,31 @@
replicaCount:
shard: 3
core: 1
frontend: 1
image:
repository: docker.io/parity/substrate-telemetry-backend
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: master-b4117d3a
backend:
repository: docker.io/parity/substrate-telemetry-backend
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: master-b4117d3a
frontend:
repository: docker.io/parity/substrate-telemetry-frontend
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: master-b4117d3a
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
envVars:
shard: {}
core: {}
frontend:
SUBSTRATE_TELEMETRY_URL: telemetry-core
serviceAccount:
# Specifies whether a service account should be created
create: true
@@ -44,7 +58,7 @@ service:
port: 80
targetPort: 8000
annotations:
external-dns.alpha.kubernetes.io/hostname: substrate-telemetry.parity-stg.parity.io.
external-dns.alpha.kubernetes.io/hostname: submit.telemetry.parity-stg.parity.io.
core:
type: LoadBalancer
port: 80
@@ -52,24 +66,63 @@ service:
annotations:
cloud.google.com/load-balancer-type: Internal
networking.gke.io/internal-load-balancer-allow-global-access: "true"
external-dns.alpha.kubernetes.io/hostname: substrate-telemetry-core.parity-stg.parity.io.
external-dns.alpha.kubernetes.io/hostname: feed.telemetry.parity-stg.parity.io.
frontend:
type: ClusterIP
port: 80
targetPort: 8000
annotations: {}
ingress:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
shard:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
core:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
frontend:
enabled: true
className: "traefik-internal"
annotations:
kubernetes.io/ingress.class: traefik-internal
traefik.ingress.kubernetes.io/router.entrypoints: web,websecure
cert-manager.io/cluster-issuer: letsencrypt-dns01
external-dns.alpha.kubernetes.io/target: traefik-internal.parity-stg.parity.io.
hosts:
- host: telemetry.parity-stg.parity.io
paths:
- path: /
pathType: ImplementationSpecific
tls:
- secretName: telemetry.parity-stg.parity.io
hosts:
- telemetry.parity-stg.parity.io
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
@@ -97,6 +150,13 @@ autoscaling:
maxReplicas: 6
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
frontend:
enabled: true
minReplicas: 3
maxReplicas: 6
targetCPUUtilizationPercentage: 80
targetMemoryUtilizationPercentage: 80
nodeSelector: {}