From 8793d0fd5bd1ec7b1d5bf45ac1d6823801b8096d Mon Sep 17 00:00:00 2001 From: James Wilson Date: Sat, 14 Aug 2021 11:32:48 +0100 Subject: [PATCH 1/4] pass the feed URL via env var rather than config map so that standalone Docker usage is simplified --- README.md | 2 +- frontend/Dockerfile | 13 +++++++------ helm/templates/frontend-deployment.yaml | 7 ------- helm/templates/frontend-env-config.yaml | 10 ---------- helm/values.yaml | 5 ++++- 5 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 helm/templates/frontend-env-config.yaml diff --git a/README.md b/README.md index e23b043..e105df7 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ If you started the backend binaries with their default arguments, you can connec polkadot --dev --telemetry-url 'ws://localhost:8001/submit 0' ``` -**Note:** The "0" at the end of the URL is a verbosity level, and not part of the URL itself. Verbosity levels range from 0-9, with 0 denoting the lowest verbosity. +**Note:** The "0" at the end of the URL is a verbosity level, and not part of the URL itself. Verbosity levels range from 0-9, with 0 denoting the lowest verbosity. The URL and this verbosity level are parts of a single argument and must therefore be surrounded in quotes (as seen above) in order to be treated as such by your shell. ## Docker diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 69986e8..ae7d6ca 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -15,18 +15,19 @@ FROM docker.io/nginx:stable-alpine LABEL maintainer="Chevdor " LABEL description="Polkadot Telemetry frontend" +# When we run the built docker image, the default command uses this +# env var to tell the UI where to look to get feed info. 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 [ "nginx", "-g" ,"daemon off;"] +CMD ["/bin/bash", "-c", "/usr/bin/env.sh && nginx -g \"daemon off;\""] diff --git a/helm/templates/frontend-deployment.yaml b/helm/templates/frontend-deployment.yaml index 8bb737f..5bb4039 100644 --- a/helm/templates/frontend-deployment.yaml +++ b/helm/templates/frontend-deployment.yaml @@ -59,19 +59,12 @@ spec: mountPath: /etc/nginx/nginx.conf subPath: nginx.conf readOnly: true - - name: env-config - mountPath: /usr/share/nginx/html/env-config.js - subPath: 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 }} diff --git a/helm/templates/frontend-env-config.yaml b/helm/templates/frontend-env-config.yaml deleted file mode 100644 index 4d2a563..0000000 --- a/helm/templates/frontend-env-config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: frontend-env-config -data: - env-config.js: | - window.process_env = { - SUBSTRATE_TELEMETRY_URL: "wss://feed.telemetry.parity-stg.parity.io/feed", - SUBSTRATE_TELEMETRY_SAMPLE: "", - } diff --git a/helm/values.yaml b/helm/values.yaml index fcd55ed..28fe64b 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -26,7 +26,10 @@ fullnameOverride: "" envVars: shard: {} core: {} - frontend: {} + frontend: + # The frontend docker container makes this available to the UI, + # so that it knows where to look for feed information: + SUBSTRATE_TELEMETRY_URL: wss://feed.telemetry.parity-stg.parity.io/feed From 53f776914616e3e2bbf39b10b6a0b3e80de88da9 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Sat, 14 Aug 2021 11:57:52 +0100 Subject: [PATCH 2/4] Make frontend nginx conf suitable for k8s or local deployment (no need for 'old' deployment bits) --- README.md | 2 +- docker-compose.yml | 9 +--- frontend/Dockerfile | 3 +- frontend/nginx/default | 48 -------------------- frontend/nginx/nginx.conf | 12 +++-- helm/templates/frontend-deployment.yaml | 9 ---- helm/templates/frontend-nginx-configmap.yaml | 41 ----------------- 7 files changed, 12 insertions(+), 112 deletions(-) delete mode 100644 frontend/nginx/default delete mode 100644 helm/templates/frontend-nginx-configmap.yaml diff --git a/README.md b/README.md index e105df7..8b86c1f 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ If you'd like to get things runing manually using Docker, you can do the followi ``` docker run --rm -it --network=telemetry \ --name frontend \ - -p 3000:80 \ + -p 3000:8000 \ -e SUBSTRATE_TELEMETRY_URL=ws://localhost:8000/feed \ substrate-telemetry-frontend ``` diff --git a/docker-compose.yml b/docker-compose.yml index 1f0db07..7c10a7d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,15 +5,8 @@ services: build: dockerfile: Dockerfile context: ./frontend/ - # Copy in changes to the ui, so no need to rebuild the images. - 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 + - 3000:8000 expose: - 3000 telemetry-backend-shard: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index ae7d6ca..52d0a00 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -25,9 +25,8 @@ 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/build /usr/share/nginx/html -EXPOSE 80 +EXPOSE 8000 CMD ["/bin/bash", "-c", "/usr/bin/env.sh && nginx -g \"daemon off;\""] diff --git a/frontend/nginx/default b/frontend/nginx/default deleted file mode 100644 index 26e9e04..0000000 --- a/frontend/nginx/default +++ /dev/null @@ -1,48 +0,0 @@ - -## -# You should look at the following URL's in order to grasp a solid understanding -# of Nginx configuration files in order to fully unleash the power of Nginx. -# http://wiki.nginx.org/Pitfalls -# http://wiki.nginx.org/QuickStart -# http://wiki.nginx.org/Configuration -# -# Generally, you will want to move this file somewhere, and start with a clean -# file but keep this around for reference. Or just disable in sites-enabled. -# -# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. -## - -server { - root /usr/share/nginx/html; - - index index.html; - - listen 3000; - listen [::]:3000; - server_name telemetry.polkadot.io localhost; - - location /feed/ { - proxy_pass http://127.0.0.1:8000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - limit_req zone=zone burst=5; - } - - location /submit/ { - proxy_pass http://127.0.0.1:8000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - limit_req zone=zone burst=5; - } - - location /health/ { - proxy_pass http://127.0.0.1:8000; - proxy_http_version 1.1; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - limit_req zone=zone burst=5; - } -} diff --git a/frontend/nginx/nginx.conf b/frontend/nginx/nginx.conf index b04791f..e203744 100644 --- a/frontend/nginx/nginx.conf +++ b/frontend/nginx/nginx.conf @@ -10,19 +10,25 @@ events { } http { - include /etc/nginx/mime.types; default_type application/octet-stream; + include /etc/nginx/mime.types; 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; + + server { + root /usr/share/nginx/html; + index index.html; + listen 8000; + listen [::]:8000; + server_name telemetry.polkadot.io localhost; + } } diff --git a/helm/templates/frontend-deployment.yaml b/helm/templates/frontend-deployment.yaml index 5bb4039..a0a6110 100644 --- a/helm/templates/frontend-deployment.yaml +++ b/helm/templates/frontend-deployment.yaml @@ -54,17 +54,8 @@ spec: httpGet: path: / port: http - volumeMounts: - - name: nginx - mountPath: /etc/nginx/nginx.conf - subPath: nginx.conf - readOnly: true resources: {{- toYaml .Values.resources | nindent 12 }} - volumes: - - name: nginx - configMap: - name: frontend-nginx {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/helm/templates/frontend-nginx-configmap.yaml b/helm/templates/frontend-nginx-configmap.yaml deleted file mode 100644 index 15dbb01..0000000 --- a/helm/templates/frontend-nginx-configmap.yaml +++ /dev/null @@ -1,41 +0,0 @@ -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; - - events { - worker_connections 8000; - } - - http { - default_type application/octet-stream; - include /etc/nginx/mime.types; - 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; - #server_tokens off; - - server { - root /usr/share/nginx/html; - index index.html; - listen 8000; - server_name _; - - location = /favicon.ico { - return 204; - } - } - } From 65eac5c3e8f76d67f65ad9ad5c6b3a1df999cda3 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Sat, 14 Aug 2021 12:15:49 +0100 Subject: [PATCH 3/4] Add env to frontend image of docker-compose (since it doesnt proxy internally now) --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 7c10a7d..3ce81c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,8 @@ services: build: dockerfile: Dockerfile context: ./frontend/ + environment: + SUBSTRATE_TELEMETRY_URL: ws://localhost:8000/feed ports: - 3000:8000 expose: From 701a431ac19897286cff39dfd1961b97db92c37d Mon Sep 17 00:00:00 2001 From: James Wilson Date: Mon, 16 Aug 2021 14:08:28 +0100 Subject: [PATCH 4/4] Remove parity specific bit in nginx file (not needed anyway), name default network, tweak a dockerfile comment --- docker-compose.yml | 5 +++++ frontend/Dockerfile | 4 ++-- frontend/nginx/nginx.conf | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3ce81c9..4b5b629 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,10 @@ version: "3" +networks: + default: + # Give the default network created below a sensible name: + name: substrate-telemetry + services: telemetry-frontend: build: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 52d0a00..d049181 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -15,8 +15,8 @@ FROM docker.io/nginx:stable-alpine LABEL maintainer="Chevdor " LABEL description="Polkadot Telemetry frontend" -# When we run the built docker image, the default command uses this -# env var to tell the UI where to look to get feed info. +# Each time this container is ran, the value that's provided for this env var +# determines where the frontend will try to request feed information from: ENV SUBSTRATE_TELEMETRY_URL= WORKDIR /usr/share/nginx/html diff --git a/frontend/nginx/nginx.conf b/frontend/nginx/nginx.conf index e203744..fedd2e2 100644 --- a/frontend/nginx/nginx.conf +++ b/frontend/nginx/nginx.conf @@ -29,6 +29,5 @@ http { index index.html; listen 8000; listen [::]:8000; - server_name telemetry.polkadot.io localhost; } }