From 8ef88e9f3974563eade08d3557f24cd672175125 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 8 Oct 2022 13:47:33 -0700 Subject: [PATCH 01/11] Ignore the new config files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 687e9e8cb..b41b0db08 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ data docker-compose.yml backend/mempool-config.json *.swp +frontend/src/resources/config.template.js +frontend/src/resources/config.js From 5d21a61840aeac10524e6bd8e2db481d3576527b Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 8 Oct 2022 13:48:29 -0700 Subject: [PATCH 02/11] Serve the frontend config from resources, stop bundling the generated file --- frontend/angular.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/angular.json b/frontend/angular.json index 1ed29cad9..672b84417 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -152,15 +152,14 @@ "assets": [ "src/favicon.ico", "src/resources", - "src/robots.txt" + "src/robots.txt", + "src/config.js", + "src/config.template.js" ], "styles": [ "src/styles.scss", "node_modules/@fortawesome/fontawesome-svg-core/styles.css" ], - "scripts": [ - "generated-config.js" - ], "vendorChunk": true, "extractLicenses": false, "buildOptimizer": false, From 71e00f66c950c63e4324d33b5025c2ac05c9151e Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:51:32 -0700 Subject: [PATCH 03/11] Update config generator to output the template and new config file --- frontend/generate-config.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/frontend/generate-config.js b/frontend/generate-config.js index 1f37953b7..4b7f80cd8 100644 --- a/frontend/generate-config.js +++ b/frontend/generate-config.js @@ -2,7 +2,8 @@ var fs = require('fs'); const { spawnSync } = require('child_process'); const CONFIG_FILE_NAME = 'mempool-frontend-config.json'; -const GENERATED_CONFIG_FILE_NAME = 'generated-config.js'; +const GENERATED_CONFIG_FILE_NAME = 'src/resources/config.js'; +const GENERATED_TEMPLATE_CONFIG_FILE_NAME = 'src/resources/config.template.js'; let settings = []; let configContent = {}; @@ -67,10 +68,17 @@ if (process.env.DOCKER_COMMIT_HASH) { const newConfig = `(function (window) { window.__env = window.__env || {};${settings.reduce((str, obj) => `${str} - window.__env.${obj.key} = ${ typeof obj.value === 'string' ? `'${obj.value}'` : obj.value };`, '')} + window.__env.${obj.key} = ${typeof obj.value === 'string' ? `'${obj.value}'` : obj.value};`, '')} window.__env.GIT_COMMIT_HASH = '${gitCommitHash}'; window.__env.PACKAGE_JSON_VERSION = '${packetJsonVersion}'; - }(global || this));`; + }(this));`; + +const newConfigTemplate = `(function (window) { + window.__env = window.__env || {};${settings.reduce((str, obj) => `${str} + window.__env.${obj.key} = ${typeof obj.value === 'string' ? `'\${${obj.key}}'` : `\${${obj.key}}`};`, '')} + window.__env.GIT_COMMIT_HASH = '${gitCommitHash}'; + window.__env.PACKAGE_JSON_VERSION = '${packetJsonVersion}'; + }(this));`; function readConfig(path) { try { @@ -89,6 +97,16 @@ function writeConfig(path, config) { } } +function writeConfigTemplate(path, config) { + try { + fs.writeFileSync(path, config, 'utf8'); + } catch (e) { + throw new Error(e); + } +} + +writeConfigTemplate(GENERATED_TEMPLATE_CONFIG_FILE_NAME, newConfigTemplate); + const currentConfig = readConfig(GENERATED_CONFIG_FILE_NAME); if (currentConfig && currentConfig === newConfig) { @@ -106,4 +124,4 @@ if (currentConfig && currentConfig === newConfig) { console.log('NEW CONFIG: ', newConfig); writeConfig(GENERATED_CONFIG_FILE_NAME, newConfig); console.log(`${GENERATED_CONFIG_FILE_NAME} file updated`); -}; +} From ad7e7795f9809df1c37c12d37f3112e00a6b2f63 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:58:09 -0700 Subject: [PATCH 04/11] Update index files to read the new config file --- frontend/src/index.bisq.html | 9 ++++++++- frontend/src/index.liquid.html | 9 ++++++++- frontend/src/index.mempool.html | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/frontend/src/index.bisq.html b/frontend/src/index.bisq.html index 8da1e77e0..82f491d50 100644 --- a/frontend/src/index.bisq.html +++ b/frontend/src/index.bisq.html @@ -1,10 +1,15 @@ + mempool - Bisq Markets + + @@ -31,11 +36,13 @@ - + + + diff --git a/frontend/src/index.liquid.html b/frontend/src/index.liquid.html index 89a6984ba..78a78aaf2 100644 --- a/frontend/src/index.liquid.html +++ b/frontend/src/index.liquid.html @@ -1,10 +1,15 @@ + mempool - Liquid Network + + @@ -17,7 +22,7 @@ - + @@ -33,7 +38,9 @@ + + diff --git a/frontend/src/index.mempool.html b/frontend/src/index.mempool.html index 1176a3da2..b6514ed9a 100644 --- a/frontend/src/index.mempool.html +++ b/frontend/src/index.mempool.html @@ -1,10 +1,15 @@ + mempool - Bitcoin Explorer + + @@ -17,7 +22,7 @@ - + @@ -32,7 +37,9 @@ + + From 81d35d9401f102f9de9455953014272151a99f80 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:44:34 -0700 Subject: [PATCH 05/11] Update nginx cache settings for the frontend config files --- nginx-mempool.conf | 7 +++++++ production/nginx/server-common.conf | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/nginx-mempool.conf b/nginx-mempool.conf index a6f701478..d4f111d49 100644 --- a/nginx-mempool.conf +++ b/nginx-mempool.conf @@ -21,6 +21,13 @@ try_files $uri @index-redirect; expires 1h; } + + # only cache /resources/config.* for 5 minutes since it changes often + location /resources/config. { + try_files $uri =404; + expires 5m; + } + location @index-redirect { rewrite (.*) /$lang/index.html; } diff --git a/production/nginx/server-common.conf b/production/nginx/server-common.conf index dedd36411..1d1bcbcd1 100644 --- a/production/nginx/server-common.conf +++ b/production/nginx/server-common.conf @@ -81,6 +81,13 @@ location /resources { try_files $uri /en-US/index.html; expires 1w; } + +# only cache /resources/config.* for 5 minutes since it changes often +location /resources/config. { + try_files $uri =404; + expires 5m; +} + # cache /main.f40e91d908a068a2.js forever since they never change location ~* ^/.+\..+\.(js|css) { try_files /$lang/$uri /en-US/$uri =404; From b77fe0dca202e5c113a8cb2848702adddf8f859a Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:45:15 -0700 Subject: [PATCH 06/11] Change template keys in generate-config script --- frontend/generate-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/generate-config.js b/frontend/generate-config.js index 4b7f80cd8..3cc173e00 100644 --- a/frontend/generate-config.js +++ b/frontend/generate-config.js @@ -75,7 +75,7 @@ const newConfig = `(function (window) { const newConfigTemplate = `(function (window) { window.__env = window.__env || {};${settings.reduce((str, obj) => `${str} - window.__env.${obj.key} = ${typeof obj.value === 'string' ? `'\${${obj.key}}'` : `\${${obj.key}}`};`, '')} + window.__env.${obj.key} = ${typeof obj.value === 'string' ? `'\${__${obj.key}__}'` : `\${__${obj.key}__}`};`, '')} window.__env.GIT_COMMIT_HASH = '${gitCommitHash}'; window.__env.PACKAGE_JSON_VERSION = '${packetJsonVersion}'; }(this));`; From cfa8a9a7d6cd70f1e690b065a1c4353b89a18a19 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:46:30 -0700 Subject: [PATCH 07/11] Update the Docker frontend startup script to read and replace runtime config values --- docker/frontend/entrypoint.sh | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh index 7ebe5632c..29064a396 100644 --- a/docker/frontend/entrypoint.sh +++ b/docker/frontend/entrypoint.sh @@ -10,4 +10,60 @@ cp /etc/nginx/nginx.conf /patch/nginx.conf sed -i "s/__MEMPOOL_FRONTEND_HTTP_PORT__/${__MEMPOOL_FRONTEND_HTTP_PORT__}/g" /patch/nginx.conf cat /patch/nginx.conf > /etc/nginx/nginx.conf +# Runtime overrides - read env vars defined in docker compose + +__TESTNET_ENABLED__=${TESTNET_ENABLED:=false} +__SIGNET_ENABLED__=${SIGNET_ENABLED:=false} +__LIQUID_ENABLED__=${LIQUID_EANBLED:=false} +__LIQUID_TESTNET_ENABLED__=${LIQUID_TESTNET_ENABLED:=false} +__BISQ_ENABLED__=${BISQ_ENABLED:=false} +__BISQ_SEPARATE_BACKEND__=${BISQ_SEPARATE_BACKEND:=false} +__ITEMS_PER_PAGE__=${ITEMS_PER_PAGE:=10} +__KEEP_BLOCKS_AMOUNT__=${KEEP_BLOCKS_AMOUNT:=8} +__NGINX_PROTOCOL__=${NGINX_PROTOCOL:=http} +__NGINX_HOSTNAME__=${NGINX_HOSTNAME:=localhost} +__NGINX_PORT__=${NGINX_PORT:=8999} +__BLOCK_WEIGHT_UNITS__=${BLOCK_WEIGHT_UNITS:=4000000} +__MEMPOOL_BLOCKS_AMOUNT__=${MEMPOOL_BLOCKS_AMOUNT:=8} +__BASE_MODULE__=${BASE_MODULE:=mempool} +__MEMPOOL_WEBSITE_URL__=${MEMPOOL_WEBSITE_URL:=https://mempool.space} +__LIQUID_WEBSITE_URL__=${LIQUID_WEBSITE_URL:=https://liquid.network} +__BISQ_WEBSITE_URL__=${BISQ_WEBSITE_URL:=https://bisq.markets} +__MINING_DASHBOARD__=${MINING_DASHBOARD:=true} +__LIGHTNING__=${LIGHTNING:=false} + +# Export as environment variables to be used by envsubst +export __TESTNET_ENABLED__ +export __SIGNET_ENABLED__ +export __LIQUID_ENABLED__ +export __LIQUID_TESTNET_ENABLED__ +export __BISQ_ENABLED__ +export __BISQ_SEPARATE_BACKEND__ +export __ITEMS_PER_PAGE__ +export __KEEP_BLOCKS_AMOUNT__ +export __NGINX_PROTOCOL__ +export __NGINX_HOSTNAME__ +export __NGINX_PORT__ +export __BLOCK_WEIGHT_UNITS__ +export __MEMPOOL_BLOCKS_AMOUNT__ +export __BASE_MODULE__ +export __MEMPOOL_WEBSITE_URL__ +export __LIQUID_WEBSITE_URL__ +export __BISQ_WEBSITE_URL__ +export __MINING_DASHBOARD__ +export __LIGHTNING__ + +# This is not an array right now but that might change in the future +files=() +while IFS= read -r -d $'\0'; do + files+=("$REPLY") +done < <(find /var/www/mempool -name "config.js" -print0) + +for file in "${files[@]}" +do + folder=$(dirname ${file}) + echo ${folder} + envsubst < ${folder}/config.template.js > ${folder}/config.js +done + exec "$@" From 670f85b1f5e578188853d3b0e3b8dee7b9e86110 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sun, 16 Oct 2022 08:39:44 -0700 Subject: [PATCH 08/11] Copy the sample config before building the frontend --- docker/frontend/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile index d144d5882..14d79c407 100644 --- a/docker/frontend/Dockerfile +++ b/docker/frontend/Dockerfile @@ -8,7 +8,9 @@ WORKDIR /build COPY . . RUN apt-get update RUN apt-get install -y build-essential rsync +RUN cp mempool-frontend-config.sample.json mempool-frontend-config.json RUN npm install --omit=dev --omit=optional + RUN npm run build FROM nginx:1.17.8-alpine From 5bfc8a9d584037b2baf58e9044ee8deb160ae59a Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sun, 16 Oct 2022 08:40:22 -0700 Subject: [PATCH 09/11] Use a single command to find the config path --- docker/frontend/entrypoint.sh | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh index 29064a396..6a263de99 100644 --- a/docker/frontend/entrypoint.sh +++ b/docker/frontend/entrypoint.sh @@ -53,17 +53,8 @@ export __BISQ_WEBSITE_URL__ export __MINING_DASHBOARD__ export __LIGHTNING__ -# This is not an array right now but that might change in the future -files=() -while IFS= read -r -d $'\0'; do - files+=("$REPLY") -done < <(find /var/www/mempool -name "config.js" -print0) - -for file in "${files[@]}" -do - folder=$(dirname ${file}) - echo ${folder} - envsubst < ${folder}/config.template.js > ${folder}/config.js -done +folder=$(find /var/www/mempool -name "config.js" | xargs dirname) +echo ${folder} +envsubst < ${folder}/config.template.js > ${folder}/config.js exec "$@" From f27abb1421e6c2a2096c28d92367cf6961b4af7f Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sun, 16 Oct 2022 14:41:39 -0700 Subject: [PATCH 10/11] Change ownership of /var/www/mempool to the Docker user --- docker/frontend/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile index 14d79c407..b54612e3d 100644 --- a/docker/frontend/Dockerfile +++ b/docker/frontend/Dockerfile @@ -30,7 +30,9 @@ RUN chown -R 1000:1000 /patch && chmod -R 755 /patch && \ chown -R 1000:1000 /var/cache/nginx && \ chown -R 1000:1000 /var/log/nginx && \ chown -R 1000:1000 /etc/nginx/nginx.conf && \ - chown -R 1000:1000 /etc/nginx/conf.d + chown -R 1000:1000 /etc/nginx/conf.d && \ + chown -R 1000:1000 /var/www/mempool + RUN touch /var/run/nginx.pid && \ chown -R 1000:1000 /var/run/nginx.pid From 9964f1ab1454a06bb84b62f604cd384f777e2195 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sun, 16 Oct 2022 15:19:44 -0700 Subject: [PATCH 11/11] Stop using the cache busting config loader --- frontend/src/index.bisq.html | 5 +---- frontend/src/index.liquid.html | 5 +---- frontend/src/index.mempool.html | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/frontend/src/index.bisq.html b/frontend/src/index.bisq.html index 82f491d50..43c85b404 100644 --- a/frontend/src/index.bisq.html +++ b/frontend/src/index.bisq.html @@ -4,12 +4,9 @@ mempool - Bisq Markets + - - diff --git a/frontend/src/index.liquid.html b/frontend/src/index.liquid.html index 78a78aaf2..630f6a2ab 100644 --- a/frontend/src/index.liquid.html +++ b/frontend/src/index.liquid.html @@ -4,12 +4,9 @@ mempool - Liquid Network + - - diff --git a/frontend/src/index.mempool.html b/frontend/src/index.mempool.html index b6514ed9a..60f1b4421 100644 --- a/frontend/src/index.mempool.html +++ b/frontend/src/index.mempool.html @@ -4,12 +4,9 @@ mempool - Bitcoin Explorer + - -