adding front to the CI

adding frontend configmaps and envVars

optimizing docker-compose and DockerfIle
This commit is contained in:
Arsham Teymourı
2021-08-10 20:07:07 +03:00
parent ac20d3d845
commit 72311d9b61
12 changed files with 203 additions and 32 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:
+6 -5
View File
@@ -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;\""]
+7
View File
@@ -35,6 +35,13 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }}
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 }}
+21
View File
@@ -35,6 +35,13 @@ spec:
{{- 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 }}
command:
- "telemetry_frontend"
args:
@@ -52,8 +59,22 @@ spec:
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 }}
+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 }}
@@ -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;
}
+7
View File
@@ -35,6 +35,13 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }}
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 }}
+7
View File
@@ -23,6 +23,13 @@ imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
envVars:
shard: {}
core: {}
frontend:
SUBSTRATE_TELEMETRY_URL: telemetry-core
serviceAccount:
# Specifies whether a service account should be created
create: true