From b2b383487f54150a25f123eb6ae8b55d7bbb59e8 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 21 May 2025 23:32:38 +0200 Subject: [PATCH 01/26] CRLF->LF --- Dockerfile | 202 ++++++++++++++++++++++++------------------------- apps/blog/.env | 48 ------------ 2 files changed, 101 insertions(+), 149 deletions(-) delete mode 100644 apps/blog/.env diff --git a/Dockerfile b/Dockerfile index be8a2c107..d5eb70cc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,102 +1,102 @@ -# syntax=docker/dockerfile:1.5 -FROM node:20.17-alpine AS base -ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" -ENV TURBO_VERSION=2.1.1 - -# Install and configure corepack/pnpm -RUN apk add --no-cache libc6-compat && \ - corepack enable && \ - corepack prepare pnpm@9.6.0 --activate && \ - pnpm config set store-dir /pnpm/store - -FROM base AS builder -ARG TURBO_APP_SCOPE -RUN apk add --no-cache libc6-compat -RUN apk update - -## Set working directory for an App -WORKDIR /app -COPY . . -## prepare files only for docker and optimise -RUN pnpm dlx turbo prune --scope=${TURBO_APP_SCOPE} --docker - -# Add lockfile and package.json's of isolated subworkspace -# TODO: Remove python3 installation after getting rid of dhive -FROM base AS installer -ARG TURBO_APP_SCOPE -RUN apk add --no-cache libc6-compat -RUN apk update -WORKDIR /app - -# First install the dependencies (as they change less often) -COPY --from=builder /app/out/json/ . -COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile - -# Build the project -COPY --from=builder /app/out/full/ . -RUN pnpm run lint -RUN pnpm dlx turbo run build --filter=${TURBO_APP_SCOPE} - -FROM base AS runner -ARG TURBO_APP_PATH -ARG TURBO_APP_NAME -ARG BUILD_TIME -ARG GIT_COMMIT_SHA -ARG GIT_CURRENT_BRANCH -ARG GIT_LAST_LOG_MESSAGE -ARG GIT_LAST_COMMITTER -ARG GIT_LAST_COMMIT_DATE -LABEL org.opencontainers.image.created="$BUILD_TIME" -LABEL org.opencontainers.image.url="https://hive.io/" -LABEL org.opencontainers.image.documentation="https://gitlab.syncad.com/hive/denser" -LABEL org.opencontainers.image.source="https://gitlab.syncad.com/hive/denser" -#LABEL org.opencontainers.image.version="${VERSION}" -LABEL org.opencontainers.image.revision="$GIT_COMMIT_SHA" -LABEL org.opencontainers.image.licenses="MIT" -LABEL org.opencontainers.image.ref.name="Denser $TURBO_APP_NAME" -LABEL org.opencontainers.image.title="Denser $TURBO_APP_NAME Image" -LABEL org.opencontainers.image.description="Runs Denser $TURBO_APP_NAME application" -LABEL io.hive.image.branch="$GIT_CURRENT_BRANCH" -LABEL io.hive.image.commit.log_message="$GIT_LAST_LOG_MESSAGE" -LABEL io.hive.image.commit.author="$GIT_LAST_COMMITTER" -LABEL io.hive.image.commit.date="$GIT_LAST_COMMIT_DATE" - -WORKDIR /app -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm add -g @beam-australia/react-env@3.1.1 -RUN apk add --no-cache tini -# COPY --from=trajano/alpine-libfaketime:latest /faketime.so /lib/faketime.so - -# Don't run production as root -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs -USER nextjs - -COPY --from=builder /app/docker/docker-entrypoint.sh . -COPY --from=installer /app${TURBO_APP_PATH}/next.config.js . -COPY --from=installer /app${TURBO_APP_PATH}/package.json . -COPY --from=installer /app/node_modules ./node_modules -COPY --from=installer /app/node_modules/@beam-australia/react-env ./node_modules/@beam-australia/react-env -ENV PATH="/app/node_modules/.bin:$PATH" - -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/public .${TURBO_APP_PATH}/public -COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/standalone ./ -COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/static .${TURBO_APP_PATH}/.next/static -COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.env* ./ -COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/li[b]/markdown[s]/ .${TURBO_APP_PATH}/lib/markdowns/ - -ENV BLOG_PORT=3000 -ENV WALLET_PORT=4000 -ENV AUTH_PORT=5000 - -# Expose ports 3000 and 4000 for the sake of GitLab CI healthcheck -EXPOSE 3000 4000 -EXPOSE $BLOG_PORT -EXPOSE $WALLET_PORT -EXPOSE $AUTH_PORT - -ENTRYPOINT ["/sbin/tini", "--", "/app/docker-entrypoint.sh"] +# syntax=docker/dockerfile:1.5 +FROM node:20.17-alpine AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +ENV TURBO_VERSION=2.1.1 + +# Install and configure corepack/pnpm +RUN apk add --no-cache libc6-compat && \ + corepack enable && \ + corepack prepare pnpm@9.6.0 --activate && \ + pnpm config set store-dir /pnpm/store + +FROM base AS builder +ARG TURBO_APP_SCOPE +RUN apk add --no-cache libc6-compat +RUN apk update + +## Set working directory for an App +WORKDIR /app +COPY . . +## prepare files only for docker and optimise +RUN pnpm dlx turbo prune --scope=${TURBO_APP_SCOPE} --docker + +# Add lockfile and package.json's of isolated subworkspace +# TODO: Remove python3 installation after getting rid of dhive +FROM base AS installer +ARG TURBO_APP_SCOPE +RUN apk add --no-cache libc6-compat +RUN apk update +WORKDIR /app + +# First install the dependencies (as they change less often) +COPY --from=builder /app/out/json/ . +COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile + +# Build the project +COPY --from=builder /app/out/full/ . +RUN pnpm run lint +RUN pnpm dlx turbo run build --filter=${TURBO_APP_SCOPE} + +FROM base AS runner +ARG TURBO_APP_PATH +ARG TURBO_APP_NAME +ARG BUILD_TIME +ARG GIT_COMMIT_SHA +ARG GIT_CURRENT_BRANCH +ARG GIT_LAST_LOG_MESSAGE +ARG GIT_LAST_COMMITTER +ARG GIT_LAST_COMMIT_DATE +LABEL org.opencontainers.image.created="$BUILD_TIME" +LABEL org.opencontainers.image.url="https://hive.io/" +LABEL org.opencontainers.image.documentation="https://gitlab.syncad.com/hive/denser" +LABEL org.opencontainers.image.source="https://gitlab.syncad.com/hive/denser" +#LABEL org.opencontainers.image.version="${VERSION}" +LABEL org.opencontainers.image.revision="$GIT_COMMIT_SHA" +LABEL org.opencontainers.image.licenses="MIT" +LABEL org.opencontainers.image.ref.name="Denser $TURBO_APP_NAME" +LABEL org.opencontainers.image.title="Denser $TURBO_APP_NAME Image" +LABEL org.opencontainers.image.description="Runs Denser $TURBO_APP_NAME application" +LABEL io.hive.image.branch="$GIT_CURRENT_BRANCH" +LABEL io.hive.image.commit.log_message="$GIT_LAST_LOG_MESSAGE" +LABEL io.hive.image.commit.author="$GIT_LAST_COMMITTER" +LABEL io.hive.image.commit.date="$GIT_LAST_COMMIT_DATE" + +WORKDIR /app +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm add -g @beam-australia/react-env@3.1.1 +RUN apk add --no-cache tini +# COPY --from=trajano/alpine-libfaketime:latest /faketime.so /lib/faketime.so + +# Don't run production as root +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +USER nextjs + +COPY --from=builder /app/docker/docker-entrypoint.sh . +COPY --from=installer /app${TURBO_APP_PATH}/next.config.js . +COPY --from=installer /app${TURBO_APP_PATH}/package.json . +COPY --from=installer /app/node_modules ./node_modules +COPY --from=installer /app/node_modules/@beam-australia/react-env ./node_modules/@beam-australia/react-env +ENV PATH="/app/node_modules/.bin:$PATH" + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/public .${TURBO_APP_PATH}/public +COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/standalone ./ +COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/static .${TURBO_APP_PATH}/.next/static +COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.env* ./ +COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/li[b]/markdown[s]/ .${TURBO_APP_PATH}/lib/markdowns/ + +ENV BLOG_PORT=3000 +ENV WALLET_PORT=4000 +ENV AUTH_PORT=5000 + +# Expose ports 3000 and 4000 for the sake of GitLab CI healthcheck +EXPOSE 3000 4000 +EXPOSE $BLOG_PORT +EXPOSE $WALLET_PORT +EXPOSE $AUTH_PORT + +ENTRYPOINT ["/sbin/tini", "--", "/app/docker-entrypoint.sh"] CMD node .${TURBO_APP_PATH}/server.js \ No newline at end of file diff --git a/apps/blog/.env b/apps/blog/.env deleted file mode 100644 index 10aa54aa9..000000000 --- a/apps/blog/.env +++ /dev/null @@ -1,48 +0,0 @@ -# -# Main environment file for application. -# -# See [README](https://gitlab.syncad.com/hive/denser#passing-environment-variables-to-application) -# - -# -# Server and browser (use prefix `REACT_APP_`). -# Server only (use prefix `DENSER_SERVER_`). -# - -REACT_APP_APP_NAME="blog" -REACT_APP_API_ENDPOINT="https://api.hive.blog" -REACT_APP_CHAIN_ID="beeab0de00000000000000000000000000000000000000000000000000000000" -REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" -REACT_APP_LOGGING_BROWSER_ENABLED="false" -REACT_APP_LOGGING_LOG_LEVEL="debug" -REACT_APP_WALLET_ENDPOINT="https://wallet.openhive.network" -REACT_APP_SITE_DOMAIN="https://blog.openhive.network" -REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' -REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' - -REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" -REACT_APP_LOGIN_AUTHENTICATE_ON_BACKEND="no" - -DENSER_SERVER_COOKIE_NAME_PREFIX="auth_" -DENSER_SERVER_SECRET_COOKIE_PASSWORD="2gyZ3GDw3LHZKCMEPmPDL3sjREVRXPr1" - - -#### OAUTH (OIDC) server #### - -DENSER_SERVER_OIDC_ENABLED="yes" -DENSER_SERVER_OIDC_COOKIES_KEYS="secret-devel-key" -DENSER_SERVER_OIDC_CLIENTS='[{"client_id":"foo","client_secret":"bar","token_endpoint_auth_method":"none","client_name":"Foo Application","client_uri":"https://rocket-chat.local.angala.pl","logo_uri":"https://rocket-chat.local.angala.pl/images/logo/logo.svg","policy_uri":"https://rocket-chat.local.angala.pl/privacy-policy","tos_uri":"https://rocket-chat.local.angala.pl/terms-of-service","redirect_uris":["https://oidcdebugger.com/debug"],"grant_types":["authorization_code"],"scope":"openid","urn:custom:client:allowed-cors-origins":["https://oidcdebugger.com"]},{"client_id":"openhive_chat","client_secret":"openhive_chat_secret","client_name":"OpenHive.Chat","client_uri":"https://rocket-chat.local.angala.pl","logo_uri":"https://rocket-chat.local.angala.pl/images/logo/logo.svg","policy_uri":"https://rocket-chat.local.angala.pl/privacy-policy","tos_uri":"https://rocket-chat.local.angala.pl/terms-of-service","redirect_uris":["https://rocket-chat.local.angala.pl/_oauth/denserblog"],"grant_types":["authorization_code"],"scope":"openid profile","urn:custom:client:allowed-cors-origins":["https://rocket-chat.local.angala.pl"],"urn:custom:client:allow-non-strict-login":false}]' -DENSER_SERVER_OIDC_JWKS_KEYS='[{"p":"8rFZLdP0vHjdMuWPE0A_haq1FqcgdRVBTgVTbrx1B3z6UqRmLTt-Ok_9JaMlRdahurZ1KE_3z6aZH44MVzMmB_tpxQs6W49T8TIyxbzW4VxIB-kkTdxS7qnTUZed3DL2kx-t6kNFy1yP2DhZcHkIe7zM-R7NTGQzh1uuK7uWgjM","kty":"RSA","q":"udbJFJEbcgBwOOnekc8AjGpZ8YR1vlrcmM6AG9SucIBPRvUKyXf8khaEY8ldTBjkkHnUFsgZ6vO2PLVfciwbLoHKEAtCDpDKqi-x88sLpUyvvC9tYenhJcnR-NpuDlwKyKs0YPL0VfcWROZuBuDii8pfOaL_yTTXCE8wd1uqm2k","d":"Baiiy5MOJQ_AJ70_GBwm-_hs7s_p6R-zJNHfX0k8GARd8JnSpHaWlTGWPfYTf_bnp7OxIx-u4uNzsKavHqLf4qV59ReIDhABueyrQR0MwZlfmVCdg_xIhVDD6BeND_xwy35V9G-Bee23pUw9YYUminfxiPNbBZDcww6AQyXrotft5RXRIsNbLWfESf9tZQEl49WkuGdyVKRiT3k29nGwJxF0QKA-9r1pz5ML4x-5ynzp28nI1SidYRo26SqT9i6XPt8zMksZQMM72iyDQGRQhAy5lLGI04cU2GnehQaYeAc9X9v2tzPC7UHvfhMhH6sbBTPY6JAu6iDWKj1p0I_r0Q","e":"AQAB","use":"sig","kid":"mShU1yBPX9yrb8m96VMb-7Bhh6HtXl_SHf9ToNtcjzk","qi":"mu3j_sQaYfAB2li2zOEAp3gn1tJ1ICqaQWFSSktwsHaLGBF5_h85iPSnVieX8RSaQbJyZ7QDYAFFdsDRxK0mQIvY0ahd5X2TlY312_crXli00fRXhcEJhTz21xm0MUJ60LsAsj8WydKxil8O26oP4qIIpRrhDmPXw8qodCUMpYQ","dp":"rx4rJDdR3AE2UzhzgceVTmT8ICld8T3yDlMnfbr8kveqRKGdnLvV_EuldVgAWCFkN67aYMk7HhmvWaaM3wroQVA3ZNgSNuj4AA1ht27oelq1GwguiwQUz2O5OKG3ZaFcbJKqUmRSY0gZ_0HBv7eF2ItGN-fy6VFQITaVObc1BiM","alg":"RS256","dq":"WR8E_YT9OXW2W8TkRN6Vr8EM80MHyEsAwZM-YppjMXaHDktTafzNti1wPf6CbIz_h721FVvO-hr4STLd2_4E5w-9HGaZvix31Jfc6kJ0ikg1erTv6uXjYGDh_kqaPu6rCUL5cojw3g0Js-8h0tCkNE_PzO87ZX2epdB8OLFQJwk","n":"sC3IU2jrdhNc-T0H06Py4WceMIF8id1AJ4blBU2i_rfgf2yCpkap_dThLShurL4o777qksSICQpoW75MxzR6xelz9-lGm-sOdr6Xv9L8jVUnm9CryzHNW_nTG0wmX8W4PTA20hXhSL_bZUqh9lXeJQephMpdRPEUyU4doaYZodLR_bNfiAbPV3ySFyWTHO_p01RriSENoF0DogcovzAwczTXwSX_surffhT9lkxw4d4kW2qF3f3ZdWlEG7ZaL8U3o88FjPmff2dJOFhuudDhbeRiXkTEdNTmipiie2zIN6Zweqi31ZnbZnuEnbMPGjg3mn5NUa7cO7ts5RJzqG5H6w"}]' - -#### Rocket Chat Widget #### - -REACT_APP_OPENHIVE_CHAT_CLIENT_ID="openhive_chat" -REACT_APP_OPENHIVE_CHAT_API_URI="https://your-chat/api/v1" -REACT_APP_OPENHIVE_CHAT_URI="https://your-chat" -REACT_APP_OPENHIVE_CHAT_IFRAME_INTEGRATION_ENABLE="no" -REACT_APP_OPENHIVE_CHAT_IFRAME_VISIBLE="yes" -REACT_APP_OPENHIVE_CHAT_ALLOW_NON_STRICT_LOGIN="no" -DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_ID="your-admin-user-id" -DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_TOKEN="your-admin-user-token" - -ESLINT_USE_FLAT_CONFIG=false -- GitLab From b403c5f3a49ff2e2a21a72bf4c4cd6b2a237f82d Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 21 May 2025 23:33:32 +0200 Subject: [PATCH 02/26] - pnpm version installed inside docker image matches package.json spec - TURBO_APP_PATH and TURBO_APP_NAME docker build parameters are also defined as environment variables, to avoid need to redefine them during startup (what is bad since image is already built for specific app) - added creation of symbolic link pointing .env file overriden at container startup --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d5eb70cc3..b1905ea9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ENV TURBO_VERSION=2.1.1 # Install and configure corepack/pnpm RUN apk add --no-cache libc6-compat && \ corepack enable && \ - corepack prepare pnpm@9.6.0 --activate && \ + corepack prepare pnpm@10.0.0 --activate && \ pnpm config set store-dir /pnpm/store FROM base AS builder @@ -42,6 +42,9 @@ RUN pnpm dlx turbo run build --filter=${TURBO_APP_SCOPE} FROM base AS runner ARG TURBO_APP_PATH ARG TURBO_APP_NAME +ENV TURBO_APP_PATH=${TURBO_APP_PATH} +ENV TURBO_APP_NAME=${TURBO_APP_NAME} + ARG BUILD_TIME ARG GIT_COMMIT_SHA ARG GIT_CURRENT_BRANCH @@ -85,9 +88,11 @@ ENV PATH="/app/node_modules/.bin:$PATH" COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/public .${TURBO_APP_PATH}/public COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/standalone ./ COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/static .${TURBO_APP_PATH}/.next/static -COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.env* ./ COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/li[b]/markdown[s]/ .${TURBO_APP_PATH}/lib/markdowns/ +RUN touch /app/apps/.env && \ + ln -sf /app/apps/.env /app${TURBO_APP_PATH}/.env + ENV BLOG_PORT=3000 ENV WALLET_PORT=4000 ENV AUTH_PORT=5000 -- GitLab From e341c4ca42bd4bd033fe9b3420a7e2f0b8e104e9 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 21 May 2025 23:57:29 +0200 Subject: [PATCH 03/26] Defined list of public env. variables (visible to the browser) having set hardcoded defaults to allow successfull build --- packages/ui/config/public-vars.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/ui/config/public-vars.ts diff --git a/packages/ui/config/public-vars.ts b/packages/ui/config/public-vars.ts new file mode 100644 index 000000000..9d06b3140 --- /dev/null +++ b/packages/ui/config/public-vars.ts @@ -0,0 +1,7 @@ +import env from '@beam-australia/react-env'; + +/// Contains list of public variables which can have safely set defaults and allow application build without explicit env. definition + +export const configuredSiteDomain = env('SITE_DOMAIN') ?? 'https://hive.blog/'; +export const configuredImagesEndpoint = env('IMAGES_ENDPOINT') ?? 'https://images.hive.blog/'; +export const configuredApiEndpoint = env('API_ENDPOINT') ?? 'https://api.hive.blog/'; -- GitLab From 28df3fba4c9c2847d3fc1ac73c90e6ee498e84ed Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 21 May 2025 23:58:58 +0200 Subject: [PATCH 04/26] blog app dumps environment variables at server startup (can be disabled) --- apps/blog/instrumentation.ts | 34 ++++++++++++++++++++++++++++++++++ apps/blog/next.config.js | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 apps/blog/instrumentation.ts diff --git a/apps/blog/instrumentation.ts b/apps/blog/instrumentation.ts new file mode 100644 index 000000000..0a921b76f --- /dev/null +++ b/apps/blog/instrumentation.ts @@ -0,0 +1,34 @@ +const dumpStartupEnvironment = () => { + const executionEnv = process.env.NODE_ENV ?? 'test'; + const isProduction = executionEnv === 'production'; + const doDump = (process.env.DENSER_SERVER_ENV_DUMP ?? 'false') === 'true' ; + + if (isProduction && doDump === false) { + console.log('Missing DENSER_SERVER_ENV_DUMP variable or set to false, skipping environment dump in production mode.'); + return; + } + + console.log('Attempting to dump Denser specific environment variables (you can skip it by unsetting DENSER_SERVER_ENV_DUMP variable or set it to false'); + + const vars = Object.keys(process.env); + const filteredVars = vars.filter((key) => { + return key.startsWith('DENSER_') || key.startsWith('HIVE_') || key.startsWith('NEXT_PUBLIC_') || key.startsWith('REACT_APP_'); + }); + + const env = filteredVars.sort().forEach((key) => { + const value = process.env[key]; + if (value) { + console.log(`${key}: ${value}`); + } else { + console.log(`Variable ${key} is !!!`); + } + }); + + console.log('Denser startup environment variables dump finsihed'); +}; + +export async function register() { + console.log('Starting up an application server...'); + dumpStartupEnvironment(); +} + diff --git a/apps/blog/next.config.js b/apps/blog/next.config.js index 563fdb2db..19528014b 100644 --- a/apps/blog/next.config.js +++ b/apps/blog/next.config.js @@ -13,7 +13,8 @@ const nextConfig = { output: 'standalone', swcMinify: false, experimental: { - outputFileTracingRoot: path.join(__dirname, '../..') + outputFileTracingRoot: path.join(__dirname, '../..'), + instrumentationHook: true }, /// According to notes: https://nextjs.org/docs/app/guides/progressive-web-apps#8-securing-your-application async headers() { -- GitLab From e955a68bddc96f316ace4efe05355b4a98aeb711 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 26 May 2025 22:34:28 +0200 Subject: [PATCH 05/26] blog/middleware.ts and blog/instrumentation.ts moved into apps level to be shared across apps --- .../ui/lib/common-instrumentation.ts | 0 apps/blog/middleware.ts => packages/ui/lib/common-middleware.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename apps/blog/instrumentation.ts => packages/ui/lib/common-instrumentation.ts (100%) rename apps/blog/middleware.ts => packages/ui/lib/common-middleware.ts (100%) diff --git a/apps/blog/instrumentation.ts b/packages/ui/lib/common-instrumentation.ts similarity index 100% rename from apps/blog/instrumentation.ts rename to packages/ui/lib/common-instrumentation.ts diff --git a/apps/blog/middleware.ts b/packages/ui/lib/common-middleware.ts similarity index 100% rename from apps/blog/middleware.ts rename to packages/ui/lib/common-middleware.ts -- GitLab From 10212da3f158f23170ed9486e83de0eb424b841f Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Thu, 22 May 2025 00:00:23 +0200 Subject: [PATCH 06/26] run_instance.sh allows to specify env-file to override deployment variables. Also removed overriding of TURBO_APP_PATH and TURBO_APP_NAME which are already specified by built image --- Dockerfile | 7 ++++--- docker/docker-entrypoint.sh | 6 ++++++ scripts/run_instance.sh | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index b1905ea9b..4578eadc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -90,8 +90,9 @@ COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/standalo COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/static .${TURBO_APP_PATH}/.next/static COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/li[b]/markdown[s]/ .${TURBO_APP_PATH}/lib/markdowns/ -RUN touch /app/apps/.env && \ - ln -sf /app/apps/.env /app${TURBO_APP_PATH}/.env +ENV APP_ENV_FILE_PATH=/app/apps/.env + +RUN touch "${APP_ENV_FILE_PATH}" ENV BLOG_PORT=3000 ENV WALLET_PORT=4000 @@ -104,4 +105,4 @@ EXPOSE $WALLET_PORT EXPOSE $AUTH_PORT ENTRYPOINT ["/sbin/tini", "--", "/app/docker-entrypoint.sh"] -CMD node .${TURBO_APP_PATH}/server.js \ No newline at end of file +CMD node .${TURBO_APP_PATH}/server.js diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 8944e81c8..03ea3c6c6 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -2,6 +2,12 @@ set -e +# point default .env file +ln -sf "${APP_ENV_FILE_PATH}" /app${TURBO_APP_PATH}/.env + +echo "Contents of /app${TURBO_APP_PATH}/.env" +cat "/app${TURBO_APP_PATH}/.env" + echo "Setting environment..." DIR=$(pwd) cd ".${TURBO_APP_PATH}" diff --git a/scripts/run_instance.sh b/scripts/run_instance.sh index 78d071483..d5fe3c511 100755 --- a/scripts/run_instance.sh +++ b/scripts/run_instance.sh @@ -22,6 +22,7 @@ OPTIONS: --app-path=PATH App path (eg. '/apps/auth) --port=PORT Port to be exposed (default: 3000) --name=NAME Container name to be used (default: denser) + --env-file=overriden.env Path to a file containing environment variables to override i.e. deployment secrets --detach Run in detached mode --help|-h|-? Display this help screen and exit EOF @@ -43,6 +44,8 @@ PORT=${PORT:-"3000"} CONTAINER_NAME=${CONTAINER_NAME:-"denser"} DETACH=${DETACH:-false} +CUSTOM_ENV_FILE='' + while [ $# -gt 0 ]; do case "$1" in --image=*) @@ -103,7 +106,16 @@ while [ $# -gt 0 ]; do ;; --detach) DETACH=true - ;; + ;; + --env-file=*) + arg="${1#*=}" + if [ -f "${arg}" ]; then + CUSTOM_ENV_FILE="${arg}" + else + echo "ERROR: File '${arg}' not found" + exit 2 + fi + ;; --help|-?) print_help exit 0 @@ -133,11 +145,13 @@ RUN_OPTIONS=( "--env" "REACT_APP_OPENHIVE_CHAT_URI=$OPENHIVE_CHAT_URI" "--env" "REACT_APP_SITE_DOMAIN=$SITE_DOMAIN" "--env" "REACT_APP_CHAIN_ID=$CHAIN_ID" - "--env" "TURBO_APP_SCOPE=$TURBO_APP_SCOPE" - "--env" "TURBO_APP_PATH=$TURBO_APP_PATH" "--name" "$CONTAINER_NAME" ) +if [ -n "${CUSTOM_ENV_FILE}" ]; then + RUN_OPTIONS+=("-v" "${CUSTOM_ENV_FILE}:/app/apps/.env") +fi + if [[ "$DETACH" == "true" ]]; then RUN_OPTIONS+=("--detach") fi -- GitLab From 58c66468735d5123d8d19054bd3b80d74774e381 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Thu, 22 May 2025 00:09:42 +0200 Subject: [PATCH 07/26] Eliminated direct usage of env. variables to provide some default values and avoid need to specify them in .env file --- apps/blog/components/md-editor.tsx | 5 +- .../components/notification-list-item.tsx | 6 +- apps/blog/components/site-header.tsx | 5 +- apps/blog/lib/proxify-images.ts | 5 +- apps/blog/lib/renderer.ts | 14 +- apps/blog/pages/[param]/settings.tsx | 5 +- apps/wallet/lib/utils.ts | 3 +- packages/ui/config/public-vars.ts | 1 + packages/ui/config/site.ts | 6 +- packages/ui/lib/common-middleware.ts | 180 ++++++------------ packages/ui/lib/old-profixy.ts | 8 +- 11 files changed, 96 insertions(+), 142 deletions(-) diff --git a/apps/blog/components/md-editor.tsx b/apps/blog/components/md-editor.tsx index 900c26c52..f776fc067 100644 --- a/apps/blog/components/md-editor.tsx +++ b/apps/blog/components/md-editor.tsx @@ -11,11 +11,12 @@ import { useState } from 'react'; import * as commands from '@uiw/react-md-editor/commands'; -import env from '@beam-australia/react-env'; import { useUser } from '@smart-signer/lib/auth/use-user'; import { Signer } from '@smart-signer/lib/signer/signer'; import { ICommand, TextAreaTextApi } from '@uiw/react-md-editor'; import { getLogger } from '@ui/lib/logging'; +import { configuredImagesEndpoint } from '@hive/ui/config/public-vars'; + import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@ui/components/tooltip'; import { useTranslation } from 'next-i18next'; import imageUserBlocklist from '@ui/config/lists/image-user-blocklist'; @@ -69,7 +70,7 @@ const uploadImg = async (file: File, username: string, signer: Signer): Promise< const imageOwner = signer.authorityUsername || signer.username; - const postUrl = `${env('IMAGES_ENDPOINT')}${imageOwner}/${sig}`; + const postUrl = `${configuredImagesEndpoint}${imageOwner}/${sig}`; const response = await fetch(postUrl, { method: 'POST', body: formData }); const resJSON = await response.json(); diff --git a/apps/blog/components/notification-list-item.tsx b/apps/blog/components/notification-list-item.tsx index b28d4ef80..180da045f 100644 --- a/apps/blog/components/notification-list-item.tsx +++ b/apps/blog/components/notification-list-item.tsx @@ -7,8 +7,10 @@ import { useTranslation } from 'next-i18next'; import { useSiteParams } from '@ui/components/hooks/use-site-params'; import { useUser } from '@smart-signer/lib/auth/use-user'; import { getLogger } from '@ui/lib/logging'; +import { configuredImagesEndpoint } from '@hive/ui/config/public-vars'; + import { Avatar, AvatarFallback, AvatarImage } from '@ui/components'; -import env from '@beam-australia/react-env'; + import Image from 'next/image'; import TimeAgo from '@hive/ui/components/time-ago'; @@ -40,7 +42,7 @@ const NotificationListItem = ({ date, msg, score, type, url, lastRead }: IAccoun default: icon = ; } - const imageHosterUrl = env('IMAGES_ENDPOINT'); + const imageHosterUrl = configuredImagesEndpoint; const participants = mentions ? mentions.map((m: string) => ( diff --git a/apps/blog/components/site-header.tsx b/apps/blog/components/site-header.tsx index 78cebdb76..8685c168b 100644 --- a/apps/blog/components/site-header.tsx +++ b/apps/blog/components/site-header.tsx @@ -4,6 +4,7 @@ import Sidebar from './sidebar'; import { MainNav } from './main-nav'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@ui/components/tooltip'; import { siteConfig } from '@ui/config/site'; +import { configuredImagesEndpoint } from '@hive/ui/config/public-vars'; import Link from 'next/link'; import React, { useState, FC, useEffect } from 'react'; import clsx from 'clsx'; @@ -19,7 +20,7 @@ import LangToggle from './lang-toggle'; import { PieChart, Pie } from 'recharts'; import useManabars from './hooks/useManabars'; import { hoursAndMinutes } from '../lib/utils'; -import env from '@beam-australia/react-env'; + import { getAccount } from '@transaction/lib/hive'; import TooltipContainer from '@ui/components/tooltip-container'; import { ModeSwitchInput } from '@ui/components/mode-switch-input'; @@ -232,7 +233,7 @@ const SiteHeader: FC = () => { className="h-full w-full object-cover" src={ profile?.profile?.profile_image || - `${env('IMAGES_ENDPOINT')}/u/${user.username}/avatar` + `${configuredImagesEndpoint}/u/${user.username}/avatar` } alt="Profile picture" /> diff --git a/apps/blog/lib/proxify-images.ts b/apps/blog/lib/proxify-images.ts index 8d59a43cc..5cf1f95f7 100644 --- a/apps/blog/lib/proxify-images.ts +++ b/apps/blog/lib/proxify-images.ts @@ -1,9 +1,10 @@ import querystring from 'querystring'; import multihash from 'multihashes'; -import env from '@beam-australia/react-env'; + +import { configuredImagesEndpoint } from '@hive/ui/config/public-vars'; // Change this when we have images.hive.blog working -let proxyBase = `${env('IMAGES_ENDPOINT')}`; +let proxyBase = `${configuredImagesEndpoint}`; export function setProxyBase(p: string): void { proxyBase = p; diff --git a/apps/blog/lib/renderer.ts b/apps/blog/lib/renderer.ts index 1554fbcfe..265c57cb7 100644 --- a/apps/blog/lib/renderer.ts +++ b/apps/blog/lib/renderer.ts @@ -1,11 +1,13 @@ import { DefaultRenderer, InstagramPlugin, TablePlugin, TwitterPlugin } from '@hive/renderer'; import { getDoubleSize, proxifyImageUrl } from '@ui/lib/old-profixy'; -import env from '@beam-australia/react-env'; + import imageUserBlocklist from '@hive/ui/config/lists/image-user-blocklist'; import { isUrlWhitelisted } from '@hive/ui/config/lists/phishing'; +import { configuredSiteDomain, configuredImagesEndpoint } from '@hive/ui/config/public-vars'; + const renderDefaultOptions = { - baseUrl: `${env('SITE_DOMAIN')}/`, + baseUrl: `${configuredSiteDomain}/`, breaks: true, skipSanitization: false, allowInsecureScriptTags: false, @@ -22,14 +24,14 @@ const renderDefaultOptions = { usertagUrlFn: (account: string) => '/@' + account, hashtagUrlFn: (hashtag: string) => '/trending/' + hashtag, isLinkSafeFn: (url: string) => - !!url.match(`^(/(?!/)|${env('IMAGES_ENDPOINT')})`) || - !!url.match(`^(/(?!/)|${env('SITE_DOMAIN')})`) || + !!url.match(`^(/(?!/)|${configuredImagesEndpoint})`) || + !!url.match(`^(/(?!/)|${configuredSiteDomain})`) || !!url.match(`^(/(?!/)|#)`) || isUrlWhitelisted(url), addExternalCssClassToMatchingLinksFn: (url: string) => - !url.match(`^(/(?!/)|${env('IMAGES_ENDPOINT')})`) && - !url.match(`^(/(?!/)|${env('SITE_DOMAIN')})`) && + !url.match(`^(/(?!/)|${configuredImagesEndpoint})`) && + !url.match(`^(/(?!/)|${configuredSiteDomain})`) && !url.match(`^(/(?!/)|#)`) && !isUrlWhitelisted(url) }; diff --git a/apps/blog/pages/[param]/settings.tsx b/apps/blog/pages/[param]/settings.tsx index 1a1342334..df8309bd8 100644 --- a/apps/blog/pages/[param]/settings.tsx +++ b/apps/blog/pages/[param]/settings.tsx @@ -18,6 +18,7 @@ import { GetServerSideProps } from 'next'; import { useParams } from 'next/navigation'; import { useUser } from '@smart-signer/lib/auth/use-user'; import { cn } from '@ui/lib/utils'; +import { configuredImagesEndpoint } from '@hive/ui/config/public-vars'; import { hiveChainService } from '@transaction/lib/hive-chain-service'; import { useFollowListQuery } from '@/blog/components/hooks/use-follow-list'; import { hbauthService } from '@smart-signer/lib/hbauth-service'; @@ -26,7 +27,7 @@ import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'next-i18next'; import { TFunction } from 'i18next'; import { MutableRefObject, useEffect, useRef, useState } from 'react'; -import env from '@beam-australia/react-env'; + import { Signer } from '@smart-signer/lib/signer/signer'; import { getLogger } from '@ui/lib/logging'; import { toast } from '@ui/components/hooks/use-toast'; @@ -117,7 +118,7 @@ const uploadImg = async (file: File, username: string, signer: Signer): Promise< password: '' }); - const postUrl = `${env('IMAGES_ENDPOINT')}${username}/${sig}`; + const postUrl = `${configuredImagesEndpoint}${username}/${sig}`; const response = await fetch(postUrl, { method: 'POST', body: formData }); const resJSON = await response.json(); diff --git a/apps/wallet/lib/utils.ts b/apps/wallet/lib/utils.ts index 30f36b7df..bdbb2eb29 100644 --- a/apps/wallet/lib/utils.ts +++ b/apps/wallet/lib/utils.ts @@ -5,6 +5,7 @@ import { TransferFilters } from '@/wallet/components/transfers-history-filter'; import { useUpdateAuthorityOperationMutation } from '../components/hooks/use-update-authority-mutation'; import { SavingsWithdrawals, IFollow, IDynamicGlobalProperties } from '@transaction/lib/extended-hive.chain'; import { numberWithCommas } from '@ui/lib/utils'; +import { configuredBlogDomain } from '@ui/config/public-vars'; import Big from 'big.js'; import { HIVE_NAI_STRING, VESTS_PRECISION } from '@transaction/lib/utils'; @@ -123,7 +124,7 @@ export const getAmountFromWithdrawal = (withdrawal: SavingsWithdrawals['withdraw // The default is the blog domain export const getExternalLink = (path: string, baseUrl?: string) => { if (!baseUrl) { - const envBlogUrl = (window as any).__ENV?.REACT_APP_BLOG_DOMAIN; + const envBlogUrl = configuredBlogDomain; if (!envBlogUrl) { throw new Error('No default blog domain found'); diff --git a/packages/ui/config/public-vars.ts b/packages/ui/config/public-vars.ts index 9d06b3140..7a721963f 100644 --- a/packages/ui/config/public-vars.ts +++ b/packages/ui/config/public-vars.ts @@ -5,3 +5,4 @@ import env from '@beam-australia/react-env'; export const configuredSiteDomain = env('SITE_DOMAIN') ?? 'https://hive.blog/'; export const configuredImagesEndpoint = env('IMAGES_ENDPOINT') ?? 'https://images.hive.blog/'; export const configuredApiEndpoint = env('API_ENDPOINT') ?? 'https://api.hive.blog/'; +export const configuredBlogDomain = env('BLOG_DOMAIN') ?? 'https://hive.blog/'; \ No newline at end of file diff --git a/packages/ui/config/site.ts b/packages/ui/config/site.ts index bac304fe1..358f2345a 100644 --- a/packages/ui/config/site.ts +++ b/packages/ui/config/site.ts @@ -1,5 +1,7 @@ import env from '@beam-australia/react-env'; +import { configuredApiEndpoint, configuredSiteDomain } from '@hive/ui/config/public-vars'; + const SERVER_VAR_PREFIX = 'DENSER_SERVER_'; const MAINNET_CHAIN_ID = 'beeab0de00000000000000000000000000000000000000000000000000000000'; @@ -16,8 +18,8 @@ const chainEnv: Record = { const chainId = env('CHAIN_ID') ? env('CHAIN_ID') : MAINNET_CHAIN_ID; export const siteConfig = { name: 'Hive Blog', - url: env('SITE_DOMAIN') || 'https://hive.blog', - endpoint: `${env('API_ENDPOINT') ? env('API_ENDPOINT') : 'https://api.hive.blog'}`, + url: configuredSiteDomain, + endpoint: configuredApiEndpoint, chainId, chainEnv: chainEnv[chainId] || chainEnv['testnet'], ogImage: '', diff --git a/packages/ui/lib/common-middleware.ts b/packages/ui/lib/common-middleware.ts index fe7381e34..ea4f3b096 100644 --- a/packages/ui/lib/common-middleware.ts +++ b/packages/ui/lib/common-middleware.ts @@ -1,119 +1,61 @@ -import { NextResponse } from 'next/server'; -import type { NextRequest } from 'next/server'; -import { setLoginChallengeCookies } from '@smart-signer/lib/middleware-challenge-cookies'; -import { createWaxFoundation } from '@hiveio/wax'; - -export const config = { - runtime: 'nodejs' -}; - -// Initialize WAX lazily only when needed -let waxInstance: any = null; -const getWax = async () => { - if (!waxInstance) { - try { - waxInstance = await createWaxFoundation(); - } catch (error) { - console.error('Failed to initialize WAX:', error); - return null; - } - } - return waxInstance; -}; - -const parseAuthCookie = async (cookie: string) => { - if (!cookie) return null; - - const wax = await getWax(); - if (!wax) return null; - - try { - const binary = Buffer.from(cookie, 'base64').toString('utf-8'); - return wax.convertTransactionFromBinaryForm(binary); - } catch (error) { - console.error('Failed to parse auth cookie:', error); - return null; - } -}; - -export async function middleware(request: NextRequest) { - const { pathname } = request.nextUrl; - - // Early return for static files and API routes - if ( - pathname.startsWith('/_next') || - pathname.startsWith('/api') || - pathname.startsWith('/static') || - pathname.includes('favicon.ico') - ) { - return NextResponse.next(); - } - - // Handle root redirect - if (pathname === '/') { - return NextResponse.redirect(new URL('/trending', request.url)); - } - - const res = NextResponse.next(); - - // Handle auth cookie parsing - try { - const authCookie = request.cookies.get('data')?.value; - if (authCookie) { - const tx = await parseAuthCookie(authCookie); - console.log('tx:', tx); - } - } catch (error) { - console.error('Auth cookie parsing error:', error); - } - - // Handle @username/permlink redirects - const tempArr = pathname.split('/'); - if (tempArr.length === 3 && tempArr[1].startsWith('@')) { - const author = tempArr[1].slice(1); - const permlink = tempArr[2]; - - try { - const resp = await fetch('https://api.hive.blog', { - method: 'POST', - body: JSON.stringify({ - jsonrpc: '2.0', - method: 'bridge.get_post', - params: { author, permlink, observer: '' }, - id: 1 - }) - }); - - const entry = await resp.json(); - if (entry?.result?.community) { - const newUrl = new URL(`/${entry.result.community}/@${entry.result.author}/${entry.result.permlink}`, request.url); - // Check if we're not already at the target URL to prevent loops - if (newUrl.pathname !== pathname) { - return NextResponse.redirect(newUrl); - } - } - } catch (error) { - console.error('Failed to fetch post:', error); - } - } - - // Set login challenge cookies for non-excluded paths - if (pathname.match('/((?!api|_next/static|_next/image|favicon.ico).*)')) { - setLoginChallengeCookies(request, res); - } - - return res; -} - -// export const config = { -// matcher: [ -// /* -// * Match all paths except for: -// * 1. /api routes -// * 2. /_next (Next.js internals) -// * 3. /_static (inside /public) -// * 4. all root files inside /public (e.g. /favicon.ico) -// */ -// '/((?!api/|_next/|_static/|_vercel|[\\w-]+.\\w+).*)' -// ] -// }; +import { NextResponse } from 'next/server'; +import type { NextRequest } from 'next/server'; +import { setLoginChallengeCookies } from '@smart-signer/lib/middleware-challenge-cookies'; +import { configuredApiEndpoint } from '@hive/ui/config/public-vars'; + +export async function commonMiddleware(request: NextRequest) { + + const { pathname } = request.nextUrl; + const res = NextResponse.next(); + + const tempArr = pathname.split('/'); + let entry: any = null; + if (tempArr.length === 3 && tempArr[1].startsWith('@')) { + let author = tempArr[1].slice(1); + let permlink = tempArr[2]; + try { + const resp = await fetch(configuredApiEndpoint, { + method: 'POST', + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'bridge.get_post', + params: { author: author, permlink: permlink, observer: '' }, + id: 1 + }) + }); + entry = await resp.json(); + return NextResponse.redirect( + new URL(`/${entry.result.community}/@${entry.result.author}/${entry.result.permlink}`, request.url) + ); + } catch (e: any) { + console.log(e.message); + } + } + + /* + Set cookies with loginChallenge value set to random string (UID). + * Match all request paths except for the ones starting with: + * - api (API routes) + * - _next/static (static files) + * - _next/image (image optimization files) + * - favicon.ico (favicon file) + */ + if (pathname.match('/((?!api|_next/static|_next/image|favicon.ico).*)')) { + setLoginChallengeCookies(request, res); + } + + return res; +} + +// export const config = { +// matcher: [ +// /* +// * Match all paths except for: +// * 1. /api routes +// * 2. /_next (Next.js internals) +// * 3. /_static (inside /public) +// * 4. all root files inside /public (e.g. /favicon.ico) +// */ +// '/((?!api/|_next/|_static/|_vercel|[\\w-]+.\\w+).*)' +// ] +// }; diff --git a/packages/ui/lib/old-profixy.ts b/packages/ui/lib/old-profixy.ts index 5001cff36..ce52289dc 100644 --- a/packages/ui/lib/old-profixy.ts +++ b/packages/ui/lib/old-profixy.ts @@ -1,4 +1,4 @@ -import env from '@beam-australia/react-env'; +import { configuredImagesEndpoint } from '@hive/ui/config/public-vars'; /** * this regular expression should capture all possible proxy domains @@ -15,7 +15,7 @@ const NATURAL_SIZE = '0x0/'; const CAPPED_SIZE = '768x0/'; const DOUBLE_CAPPED_SIZE = '1536x0/'; -export const imageProxy = () => `${env('IMAGES_ENDPOINT')}`; +export const imageProxy = () => `${configuredImagesEndpoint}`; export const defaultSrcSet = (url: string) => { return `${url} 1x, ${url.replace(CAPPED_SIZE, DOUBLE_CAPPED_SIZE)} 2x`; }; @@ -46,7 +46,7 @@ export const proxifyImageUrl = (url: string, dimensions: string | boolean) => { const lastProxy = proxyList[proxyList.length - 1]; respUrl = url.substring(url.lastIndexOf(lastProxy) + lastProxy.length); } - if (dimensions && `${env('IMAGES_ENDPOINT')}`) { + if (dimensions && `${configuredImagesEndpoint}`) { let dims = dimensions + '/'; if (typeof dimensions !== 'string') { // @ts-ignore @@ -60,7 +60,7 @@ export const proxifyImageUrl = (url: string, dimensions: string | boolean) => { } if ((NATURAL_SIZE !== dims && CAPPED_SIZE !== dims) || !rProxyDomain.test(respUrl)) { - return `${env('IMAGES_ENDPOINT')}` + dims + respUrl; + return `${configuredImagesEndpoint}` + dims + respUrl; } } return respUrl; -- GitLab From 3035e54f4e0450b25a782c0db3b3bb9bdd56e220 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 26 May 2025 22:59:05 +0200 Subject: [PATCH 08/26] Removed wallet/.env file --- apps/wallet/.env | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 apps/wallet/.env diff --git a/apps/wallet/.env b/apps/wallet/.env deleted file mode 100644 index 098365327..000000000 --- a/apps/wallet/.env +++ /dev/null @@ -1,28 +0,0 @@ -# -# Main environment file for application. -# -# See [README](https://gitlab.syncad.com/hive/denser#passing-environment-variables-to-application) -# - -# -# Server and browser (use prefix `REACT_APP_`). -# - -REACT_APP_APP_NAME="wallet" -REACT_APP_API_ENDPOINT="https://api.hive.blog" -REACT_APP_CHAIN_ID="beeab0de00000000000000000000000000000000000000000000000000000000" -REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" -REACT_APP_SITE_DOMAIN="https://wallet.openhive.network" -REACT_APP_BLOG_DOMAIN="https://blog.openhive.network" -REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' -REACT_APP_LOGGING_BROWSER_ENABLED="false" -REACT_APP_LOGGING_LOG_LEVEL="info" - -# -# Server only (use prefix `DENSER_SERVER_`). -# - -# DENSER_SERVER_HIDDEN_SECRET=hidden_secret -DENSER_SERVER_SECRET_COOKIE_PASSWORD="2gyZ3GDw3LHZKCMEPmPDL3sjREVRXPr3" - -ESLINT_USE_FLAT_CONFIG=false \ No newline at end of file -- GitLab From f71480cae4305b2deda1f34dde71077e40b4ef5c Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 26 May 2025 23:00:01 +0200 Subject: [PATCH 09/26] Implemented common functions for handling middleware requests and performing application server registration --- packages/ui/lib/common-instrumentation.ts | 4 ++-- packages/ui/lib/common-middleware.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ui/lib/common-instrumentation.ts b/packages/ui/lib/common-instrumentation.ts index 0a921b76f..7b4c0dcda 100644 --- a/packages/ui/lib/common-instrumentation.ts +++ b/packages/ui/lib/common-instrumentation.ts @@ -27,8 +27,8 @@ const dumpStartupEnvironment = () => { console.log('Denser startup environment variables dump finsihed'); }; -export async function register() { - console.log('Starting up an application server...'); +export async function commonRegister(appName: string): Promise { + console.log(`Starting up the '${appName}' application server...`); dumpStartupEnvironment(); } diff --git a/packages/ui/lib/common-middleware.ts b/packages/ui/lib/common-middleware.ts index ea4f3b096..e07a15e7c 100644 --- a/packages/ui/lib/common-middleware.ts +++ b/packages/ui/lib/common-middleware.ts @@ -32,6 +32,10 @@ export async function commonMiddleware(request: NextRequest) { } } + if (pathname === '/') { + return NextResponse.redirect(new URL('/trending', request.url)); + } + /* Set cookies with loginChallenge value set to random string (UID). * Match all request paths except for the ones starting with: -- GitLab From 1e06e2d9c3aed1a0fcaa842108f8db00d8d0bd49 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 26 May 2025 23:01:07 +0200 Subject: [PATCH 10/26] blog and wallet apps use common functions to perform middleware request processing and server registration --- apps/blog/instrumentation.ts | 5 ++ apps/blog/middleware.ts | 14 +++ apps/wallet/instrumentation.ts | 5 ++ apps/wallet/middleware.ts | 62 +------------ packages/ui/lib/common-middleware.ts | 126 +++++++++++++-------------- 5 files changed, 89 insertions(+), 123 deletions(-) create mode 100644 apps/blog/instrumentation.ts create mode 100644 apps/blog/middleware.ts create mode 100644 apps/wallet/instrumentation.ts diff --git a/apps/blog/instrumentation.ts b/apps/blog/instrumentation.ts new file mode 100644 index 000000000..018446c9b --- /dev/null +++ b/apps/blog/instrumentation.ts @@ -0,0 +1,5 @@ +import {commonRegister} from '@hive/ui/lib/common-instrumentation'; + +export async function register(): Promise { + await commonRegister('blog'); +} diff --git a/apps/blog/middleware.ts b/apps/blog/middleware.ts new file mode 100644 index 000000000..bb1866f9a --- /dev/null +++ b/apps/blog/middleware.ts @@ -0,0 +1,14 @@ +import {commonMiddleware} from '@hive/ui/lib/common-middleware'; +import { type NextRequest, NextResponse } from 'next/server'; + +export async function middleware(request: NextRequest): Promise { + const { pathname } = request.nextUrl; + + const result = await commonMiddleware(request); + + /// In blog, let's redirect root path to /trending + if (pathname === '/') + return NextResponse.redirect(new URL('/trending', request.url)); + + return result; +} diff --git a/apps/wallet/instrumentation.ts b/apps/wallet/instrumentation.ts new file mode 100644 index 000000000..3b2cbf0ae --- /dev/null +++ b/apps/wallet/instrumentation.ts @@ -0,0 +1,5 @@ +import {commonRegister} from '@hive/ui/lib/common-instrumentation'; + +export async function register(): Promise { + await commonRegister('wallet'); +} diff --git a/apps/wallet/middleware.ts b/apps/wallet/middleware.ts index a4ee84d3a..f45054559 100644 --- a/apps/wallet/middleware.ts +++ b/apps/wallet/middleware.ts @@ -1,60 +1,6 @@ -import { NextResponse } from 'next/server'; -import type { NextRequest } from 'next/server'; -import { setLoginChallengeCookies } from '@smart-signer/lib/middleware-challenge-cookies'; +import {commonMiddleware} from '@hive/ui/lib/common-middleware'; +import type { NextRequest, NextResponse } from 'next/server'; -export async function middleware(request: NextRequest) { - - const { pathname } = request.nextUrl; - const res = NextResponse.next(); - - const tempArr = pathname.split('/'); - let entry: any = null; - if (tempArr.length === 3 && tempArr[1].startsWith('@')) { - let author = tempArr[1].slice(1); - let permlink = tempArr[2]; - try { - const resp = await fetch('https://api.hive.blog', { - method: 'POST', - body: JSON.stringify({ - jsonrpc: '2.0', - method: 'bridge.get_post', - params: { author: author, permlink: permlink, observer: '' }, - id: 1 - }) - }); - entry = await resp.json(); - return NextResponse.redirect( - new URL(`/${entry.result.community}/@${entry.result.author}/${entry.result.permlink}`, request.url) - ); - } catch (e: any) { - console.log(e.message); - } - } - - /* - Set cookies with loginChallenge value set to random string (UID). - * Match all request paths except for the ones starting with: - * - api (API routes) - * - _next/static (static files) - * - _next/image (image optimization files) - * - favicon.ico (favicon file) - */ - if (pathname.match('/((?!api|_next/static|_next/image|favicon.ico).*)')) { - setLoginChallengeCookies(request, res); - } - - return res; +export async function middleware(request: NextRequest): Promise { + return await commonMiddleware(request); } - -// export const config = { -// matcher: [ -// /* -// * Match all paths except for: -// * 1. /api routes -// * 2. /_next (Next.js internals) -// * 3. /_static (inside /public) -// * 4. all root files inside /public (e.g. /favicon.ico) -// */ -// '/((?!api/|_next/|_static/|_vercel|[\\w-]+.\\w+).*)' -// ] -// }; diff --git a/packages/ui/lib/common-middleware.ts b/packages/ui/lib/common-middleware.ts index e07a15e7c..3681e7f90 100644 --- a/packages/ui/lib/common-middleware.ts +++ b/packages/ui/lib/common-middleware.ts @@ -1,65 +1,61 @@ -import { NextResponse } from 'next/server'; -import type { NextRequest } from 'next/server'; -import { setLoginChallengeCookies } from '@smart-signer/lib/middleware-challenge-cookies'; -import { configuredApiEndpoint } from '@hive/ui/config/public-vars'; - -export async function commonMiddleware(request: NextRequest) { - - const { pathname } = request.nextUrl; - const res = NextResponse.next(); - - const tempArr = pathname.split('/'); - let entry: any = null; - if (tempArr.length === 3 && tempArr[1].startsWith('@')) { - let author = tempArr[1].slice(1); - let permlink = tempArr[2]; - try { - const resp = await fetch(configuredApiEndpoint, { - method: 'POST', - body: JSON.stringify({ - jsonrpc: '2.0', - method: 'bridge.get_post', - params: { author: author, permlink: permlink, observer: '' }, - id: 1 - }) - }); - entry = await resp.json(); - return NextResponse.redirect( - new URL(`/${entry.result.community}/@${entry.result.author}/${entry.result.permlink}`, request.url) - ); - } catch (e: any) { - console.log(e.message); - } - } - - if (pathname === '/') { - return NextResponse.redirect(new URL('/trending', request.url)); - } - - /* - Set cookies with loginChallenge value set to random string (UID). - * Match all request paths except for the ones starting with: - * - api (API routes) - * - _next/static (static files) - * - _next/image (image optimization files) - * - favicon.ico (favicon file) - */ - if (pathname.match('/((?!api|_next/static|_next/image|favicon.ico).*)')) { - setLoginChallengeCookies(request, res); - } - - return res; -} - -// export const config = { -// matcher: [ -// /* -// * Match all paths except for: -// * 1. /api routes -// * 2. /_next (Next.js internals) -// * 3. /_static (inside /public) -// * 4. all root files inside /public (e.g. /favicon.ico) -// */ -// '/((?!api/|_next/|_static/|_vercel|[\\w-]+.\\w+).*)' -// ] -// }; +import { NextResponse } from 'next/server'; +import type { NextRequest } from 'next/server'; +import { setLoginChallengeCookies } from '@smart-signer/lib/middleware-challenge-cookies'; +import { configuredApiEndpoint } from '@hive/ui/config/public-vars'; + +export async function commonMiddleware(request: NextRequest) { + + const { pathname } = request.nextUrl; + const res = NextResponse.next(); + + const tempArr = pathname.split('/'); + let entry: any = null; + if (tempArr.length === 3 && tempArr[1].startsWith('@')) { + let author = tempArr[1].slice(1); + let permlink = tempArr[2]; + try { + const resp = await fetch(configuredApiEndpoint, { + method: 'POST', + body: JSON.stringify({ + jsonrpc: '2.0', + method: 'bridge.get_post', + params: { author: author, permlink: permlink, observer: '' }, + id: 1 + }) + }); + entry = await resp.json(); + return NextResponse.redirect( + new URL(`/${entry.result.community}/@${entry.result.author}/${entry.result.permlink}`, request.url) + ); + } catch (e: any) { + console.log(e.message); + } + } + + /* + Set cookies with loginChallenge value set to random string (UID). + * Match all request paths except for the ones starting with: + * - api (API routes) + * - _next/static (static files) + * - _next/image (image optimization files) + * - favicon.ico (favicon file) + */ + if (pathname.match('/((?!api|_next/static|_next/image|favicon.ico).*)')) { + setLoginChallengeCookies(request, res); + } + + return res; +} + +// export const config = { +// matcher: [ +// /* +// * Match all paths except for: +// * 1. /api routes +// * 2. /_next (Next.js internals) +// * 3. /_static (inside /public) +// * 4. all root files inside /public (e.g. /favicon.ico) +// */ +// '/((?!api/|_next/|_static/|_vercel|[\\w-]+.\\w+).*)' +// ] +// }; -- GitLab From e7aef81087e870530155f9f1f6fa7c7aee732858 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 3 Jun 2025 13:11:43 +0200 Subject: [PATCH 11/26] Removed auth app build & deployment since it is not used anymore --- .gitlab-ci.yml | 144 ------------------------------------------------- 1 file changed, 144 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f90b1db81..cc27e0d72 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -97,13 +97,6 @@ mirrornet-haf-binaries-extraction: - public-runner-docker - hived-for-tests -docker-build-auth: - extends: .docker_build_template - variables: - TURBO_APP_SCOPE: '@hive/auth' - TURBO_APP_PATH: '/apps/auth' - TURBO_APP_NAME: 'auth' - docker-build-blog: extends: .docker_build_template variables: @@ -288,7 +281,6 @@ mirrornet-based-tests: - .node-job needs: - mirrornet-haf-binaries-extraction - - docker-build-auth - docker-build-blog - docker-build-wallet - mirrornet-replay-data-copy @@ -532,26 +524,6 @@ publish: --detach # Main branch deployments (manual) -main:deploy-auth-mainnet: - extends: .deploy_template_mainnet - needs: - - docker-build-auth - variables: - CONTAINER_NAME: denser-main-auth - PORT: 9133 - TURBO_APP_SCOPE: '@hive/auth' - TURBO_APP_PATH: '/apps/auth' - SITE_DOMAIN: https://auth.openhive.network - EXPLORER_DOMAIN: https://explore.openhive.network - IMAGE_NAME: $AUTH_IMAGE_NAME - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: manual - environment: - name: main-auth-mainnet - url: https://auth.openhive.network - on_stop: main:stop-auth-mainnet - main:deploy-blog-mainnet: extends: .deploy_template_mainnet needs: @@ -596,26 +568,6 @@ main:deploy-wallet-mainnet: url: https://wallet.openhive.network on_stop: main:stop-wallet-mainnet -main:deploy-auth-mirrornet: - extends: .deploy_template_mirrornet - needs: - - docker-build-auth - variables: - CONTAINER_NAME: denser-main-auth-mirror - PORT: 9233 - TURBO_APP_SCOPE: '@hive/auth' - TURBO_APP_PATH: '/apps/auth' - SITE_DOMAIN: https://auth.fake.openhive.network - EXPLORER_DOMAIN: https://testexplorer.openhive.network - IMAGE_NAME: $AUTH_IMAGE_NAME - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: manual - environment: - name: main-auth-mirrornet - url: https://auth.fake.openhive.network - on_stop: main:stop-auth-mirrornet - main:deploy-blog-mirrornet: extends: .deploy_template_mirrornet needs: @@ -674,21 +626,6 @@ main:deploy-wallet-mirrornet: - hs-denser # Stop jobs for main deployments -main:stop-auth-mainnet: - extends: .stop_template - needs: - - job: main:deploy-auth-mainnet - optional: true - variables: - CONTAINER_NAME: denser-main-auth - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: manual - allow_failure: true - environment: - name: main-auth-mainnet - action: stop - main:stop-blog-mainnet: extends: .stop_template needs: @@ -719,21 +656,6 @@ main:stop-wallet-mainnet: name: main-wallet-mainnet action: stop -main:stop-auth-mirrornet: - extends: .stop_template - needs: - - job: main:deploy-auth-mirrornet - optional: true - variables: - CONTAINER_NAME: denser-main-auth-mirror - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: manual - allow_failure: true - environment: - name: main-auth-mirrornet - action: stop - main:stop-blog-mirrornet: extends: .stop_template needs: @@ -765,24 +687,6 @@ main:stop-wallet-mirrornet: action: stop # Develop branch deployments -develop:deploy-auth-mainnet: - extends: .deploy_template_mainnet - needs: - - docker-build-auth - variables: - CONTAINER_NAME: denser-dev-auth - PORT: 8133 - TURBO_APP_SCOPE: '@hive/auth' - TURBO_APP_PATH: '/apps/auth' - SITE_DOMAIN: https://auth.dev.openhive.network - EXPLORER_DOMAIN: https://explore.openhive.network - IMAGE_NAME: $AUTH_IMAGE_NAME - rules: - - if: $CI_COMMIT_BRANCH == "develop" - environment: - name: develop-auth-mainnet - url: https://auth.dev.openhive.network - on_stop: develop:stop-auth-mainnet develop:deploy-blog-mainnet: extends: .deploy_template_mainnet @@ -826,25 +730,6 @@ develop:deploy-wallet-mainnet: url: https://wallet.dev.openhive.network on_stop: develop:stop-wallet-mainnet -develop:deploy-auth-mirrornet: - extends: .deploy_template_mirrornet - needs: - - docker-build-auth - variables: - CONTAINER_NAME: denser-dev-auth-mirror - PORT: 8233 - TURBO_APP_SCOPE: '@hive/auth' - TURBO_APP_PATH: '/apps/auth' - SITE_DOMAIN: https://auth.dev.fake.openhive.network - EXPLORER_DOMAIN: https://testexplorer.openhive.network - IMAGE_NAME: $AUTH_IMAGE_NAME - rules: - - if: $CI_COMMIT_BRANCH == "develop" - environment: - name: develop-auth-mirrornet - url: https://auth.dev.fake.openhive.network - on_stop: develop:stop-auth-mirrornet - develop:deploy-blog-mirrornet: extends: .deploy_template_mirrornet needs: @@ -888,20 +773,6 @@ develop:deploy-wallet-mirrornet: on_stop: develop:stop-wallet-mirrornet # Stop jobs for develop deployments -develop:stop-auth-mainnet: - extends: .stop_template - needs: - - job: develop:deploy-auth-mainnet - optional: true - variables: - CONTAINER_NAME: denser-dev-auth - rules: - - if: $CI_COMMIT_BRANCH == "develop" - when: manual - allow_failure: true - environment: - name: develop-auth-mainnet - action: stop develop:stop-blog-mainnet: extends: .stop_template @@ -933,21 +804,6 @@ develop:stop-wallet-mainnet: name: develop-wallet-mainnet action: stop -develop:stop-auth-mirrornet: - extends: .stop_template - needs: - - job: develop:deploy-auth-mirrornet - optional: true - variables: - CONTAINER_NAME: denser-dev-auth-mirror - rules: - - if: $CI_COMMIT_BRANCH == "develop" - when: manual - allow_failure: true - environment: - name: develop-auth-mirrornet - action: stop - develop:stop-blog-mirrornet: extends: .stop_template needs: -- GitLab From 0f1155b3b7490fbdd14da50d885b23ae6f401930 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 3 Jun 2025 22:23:43 +0200 Subject: [PATCH 12/26] Defined testing environment for blog e2e tests --- apps/blog/.env.testing | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 apps/blog/.env.testing diff --git a/apps/blog/.env.testing b/apps/blog/.env.testing new file mode 100644 index 000000000..bbc031de7 --- /dev/null +++ b/apps/blog/.env.testing @@ -0,0 +1,26 @@ +DENSER_SERVER_ENV_DUMP=true +REACT_APP_APP_NAME="blog" +REACT_APP_API_ENDPOINT="https://api.hive.blog" +REACT_APP_CHAIN_ID="beeab0de00000000000000000000000000000000000000000000000000000000" +REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" +REACT_APP_LOGGING_BROWSER_ENABLED="false" +REACT_APP_LOGGING_LOG_LEVEL="debug" +REACT_APP_WALLET_ENDPOINT="https://wallet.openhive.network" +REACT_APP_SITE_DOMAIN="https://blog.openhive.network" +REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' +REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' +REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" +REACT_APP_LOGIN_AUTHENTICATE_ON_BACKEND="no" +DENSER_SERVER_COOKIE_NAME_PREFIX="auth_" +DENSER_SERVER_SECRET_COOKIE_PASSWORD="SomeValueForTestingPurposesOnly" +DENSER_SERVER_OIDC_ENABLED="yes" +DENSER_SERVER_OIDC_COOKIES_KEYS="secret-devel-key" +REACT_APP_OPENHIVE_CHAT_CLIENT_ID="openhive_chat" +REACT_APP_OPENHIVE_CHAT_API_URI="https://your-chat/api/v1" +REACT_APP_OPENHIVE_CHAT_URI="https://your-chat" +REACT_APP_OPENHIVE_CHAT_IFRAME_INTEGRATION_ENABLE="no" +REACT_APP_OPENHIVE_CHAT_IFRAME_VISIBLE="yes" +REACT_APP_OPENHIVE_CHAT_ALLOW_NON_STRICT_LOGIN="no" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_ID="your-admin-user-id" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_TOKEN="your-admin-user-token" +ESLINT_USE_FLAT_CONFIG=false \ No newline at end of file -- GitLab From ec583ab0bb00e4a8e2e85f3db4eed736243f12e2 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 3 Jun 2025 22:25:30 +0200 Subject: [PATCH 13/26] Defined testing environment for wallet app --- apps/wallet/.env.testing | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 apps/wallet/.env.testing diff --git a/apps/wallet/.env.testing b/apps/wallet/.env.testing new file mode 100644 index 000000000..5084c75a4 --- /dev/null +++ b/apps/wallet/.env.testing @@ -0,0 +1,25 @@ +DENSER_SERVER_ENV_DUMP=true +REACT_APP_APP_NAME="wallet" +REACT_APP_API_ENDPOINT="https://api.hive.blog" +REACT_APP_CHAIN_ID="beeab0de00000000000000000000000000000000000000000000000000000000" +REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" +REACT_APP_LOGGING_BROWSER_ENABLED="false" +REACT_APP_LOGGING_LOG_LEVEL="debug" +REACT_APP_SITE_DOMAIN="https://wallet.openhive.network" +REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' +REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' +REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" +REACT_APP_LOGIN_AUTHENTICATE_ON_BACKEND="no" +DENSER_SERVER_COOKIE_NAME_PREFIX="auth_" +DENSER_SERVER_SECRET_COOKIE_PASSWORD="SomeValueForTestingPurposesOnly" +DENSER_SERVER_OIDC_ENABLED="yes" +DENSER_SERVER_OIDC_COOKIES_KEYS="secret-devel-key" +REACT_APP_OPENHIVE_CHAT_CLIENT_ID="openhive_chat" +REACT_APP_OPENHIVE_CHAT_API_URI="https://your-chat/api/v1" +REACT_APP_OPENHIVE_CHAT_URI="https://your-chat" +REACT_APP_OPENHIVE_CHAT_IFRAME_INTEGRATION_ENABLE="no" +REACT_APP_OPENHIVE_CHAT_IFRAME_VISIBLE="yes" +REACT_APP_OPENHIVE_CHAT_ALLOW_NON_STRICT_LOGIN="no" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_ID="your-admin-user-id" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_TOKEN="your-admin-user-token" +ESLINT_USE_FLAT_CONFIG=false -- GitLab From d21298d053237f9e1e0fe82d19ef8af262dcdac8 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 3 Jun 2025 22:26:44 +0200 Subject: [PATCH 14/26] Added environment setup before starting e2e tests --- .gitlab-ci.yml | 58 ++++++++++++++++++++++++++++++++++--- Dockerfile | 4 --- apps/blog/.env.testing | 1 + apps/wallet/.env.testing | 1 + docker/docker-entrypoint.sh | 5 +--- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cc27e0d72..5e812ddb4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -97,6 +97,35 @@ mirrornet-haf-binaries-extraction: - public-runner-docker - hived-for-tests +# helper job just to prepare extended version of production image additionally holding .env file specific to test environment +.docker-build-testenv-image: + extends: .docker_image_builder_job_template + variables: + TURBO_APP_NAME: "" + BASE_IMAGE_NAME: "" + + script: + - | + echo -e "\e[0Ksection_start:$(date +%s):login[collapsed=true]\r\e[0KLogging to Docker registry..." + docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + echo -e "\e[0Ksection_end:$(date +%s):login\r\e[0K" + docker buildx build \ + --push \ + -t "${CI_REGISTRY_IMAGE}/${TURBO_APP_NAME}-testenv:${CI_COMMIT_SHA}" -f- . << EOF + FROM $BASE_IMAGE_NAME AS production + COPY ./apps/${TURBO_APP_NAME}/.env.testing /app/apps/.env + EOF + echo "DENSER_IMAGE_NAME=${CI_REGISTRY_IMAGE}/${TURBO_APP_NAME}-testenv:${CI_COMMIT_SHA}" > docker-build-testenv-image.env + artifacts: + paths: + - docker-build-testenv-image.env + reports: + dotenv: docker-build-testenv-image.env + when: always # This ensures artifacts are created even if job fails + tags: + - public-runner-docker + - hived-for-tests + docker-build-blog: extends: .docker_build_template variables: @@ -111,6 +140,22 @@ docker-build-wallet: TURBO_APP_PATH: '/apps/wallet' TURBO_APP_NAME: 'wallet' +docker-build-blog-testenv: + extends: .docker-build-testenv-image + needs: + - docker-build-blog + variables: + TURBO_APP_NAME: 'blog' + BASE_IMAGE_NAME: ${BLOG_IMAGE_NAME} + +docker-build-wallet-testenv: + extends: .docker-build-testenv-image + needs: + - docker-build-wallet + variables: + TURBO_APP_NAME: 'wallet' + BASE_IMAGE_NAME: ${WALLET_IMAGE_NAME} + # Hived binary built as a part of HAF requires an additional # library to function. This library has to be extracted from # the image and passed to job extended_block_log_creation. @@ -246,6 +291,7 @@ mirrornet-haf-node-replay: FF_NETWORK_PER_BUILD: 1 REACT_APP_API_ENDPOINT: https://api.hive.blog REACT_APP_IMAGES_ENDPOINT: https://images.hive.blog/ + DENSER_SERVER_ENV_DUMP: true DENSER_URL: https://caddy parallel: matrix: @@ -375,12 +421,14 @@ mirrornet-based-tests: e2e-tests-blog: extends: .e2e_tests_template needs: - - docker-build-blog + - docker-build-blog-testenv + services: - - name: $BLOG_IMAGE_NAME + - name: $DENSER_IMAGE_NAME alias: denser variables: HEALTHCHECK_TCP_PORT: '3000' + - name: caddy:${CADDY_TAG} command: - caddy @@ -396,12 +444,14 @@ e2e-tests-blog: e2e-tests-wallet: extends: .e2e_tests_template needs: - - docker-build-wallet + - docker-build-wallet-testenv + services: - - name: $WALLET_IMAGE_NAME + - name: $DENSER_IMAGE_NAME alias: denser variables: HEALTHCHECK_TCP_PORT: '4000' + - name: caddy:${CADDY_TAG} command: - caddy diff --git a/Dockerfile b/Dockerfile index 4578eadc9..0239bdf93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -90,10 +90,6 @@ COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/standalo COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/.next/static .${TURBO_APP_PATH}/.next/static COPY --from=installer --chown=nextjs:nodejs /app${TURBO_APP_PATH}/li[b]/markdown[s]/ .${TURBO_APP_PATH}/lib/markdowns/ -ENV APP_ENV_FILE_PATH=/app/apps/.env - -RUN touch "${APP_ENV_FILE_PATH}" - ENV BLOG_PORT=3000 ENV WALLET_PORT=4000 ENV AUTH_PORT=5000 diff --git a/apps/blog/.env.testing b/apps/blog/.env.testing index bbc031de7..320975812 100644 --- a/apps/blog/.env.testing +++ b/apps/blog/.env.testing @@ -7,6 +7,7 @@ REACT_APP_LOGGING_BROWSER_ENABLED="false" REACT_APP_LOGGING_LOG_LEVEL="debug" REACT_APP_WALLET_ENDPOINT="https://wallet.openhive.network" REACT_APP_SITE_DOMAIN="https://blog.openhive.network" +REACT_APP_BLOG_DOMAIN="https://blog.openhive.network" REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" diff --git a/apps/wallet/.env.testing b/apps/wallet/.env.testing index 5084c75a4..a528937f6 100644 --- a/apps/wallet/.env.testing +++ b/apps/wallet/.env.testing @@ -6,6 +6,7 @@ REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" REACT_APP_LOGGING_BROWSER_ENABLED="false" REACT_APP_LOGGING_LOG_LEVEL="debug" REACT_APP_SITE_DOMAIN="https://wallet.openhive.network" +REACT_APP_BLOG_DOMAIN="https://blog.openhive.network" REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 03ea3c6c6..60d634b25 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -3,10 +3,7 @@ set -e # point default .env file -ln -sf "${APP_ENV_FILE_PATH}" /app${TURBO_APP_PATH}/.env - -echo "Contents of /app${TURBO_APP_PATH}/.env" -cat "/app${TURBO_APP_PATH}/.env" +ln -sf "${APP_ENV_FILE_PATH:-"/app/apps/.env"}" /app${TURBO_APP_PATH}/.env echo "Setting environment..." DIR=$(pwd) -- GitLab From 14df5d4f3aee3f3130c41c489a589ed5391d1100 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 10 Jun 2025 19:00:11 +0200 Subject: [PATCH 15/26] Adjusting automatic deployment of develop-main to new environment definition done using .env file --- .gitlab-ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5e812ddb4..ca039e03f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -544,6 +544,10 @@ publish: echo -e "\e[0Ksection_end:$(date +%s):login\r\e[0K" script: - | + export DEPLOYMENT_ENV_FILE=${!DEPLOYMENT_ENV_FILE} + cat "${DEPLOYMENT_ENV_FILE}" + echo -e "\nValue of DEPLOYMENT_ENV_FILE is ${DEPLOYMENT_ENV_FILE}" + scripts/run_instance.sh \ --image="$IMAGE_NAME" \ --app-scope="$TURBO_APP_SCOPE" \ @@ -553,6 +557,7 @@ publish: --images-endpoint="https://images.hive.blog/" \ --name="$CONTAINER_NAME" \ --port=$PORT \ + --env-file="${DEPLOYMENT_ENV_FILE}" \ --detach tags: - hs-denser @@ -746,12 +751,8 @@ develop:deploy-blog-mainnet: variables: CONTAINER_NAME: denser-dev-blog PORT: 8111 - TURBO_APP_SCOPE: '@hive/blog' - TURBO_APP_PATH: '/apps/blog' - SITE_DOMAIN: https://blog.dev.openhive.network - WALLET_ENDPOINT: https://wallet.dev.openhive.network - EXPLORER_DOMAIN: https://explore.openhive.network IMAGE_NAME: $BLOG_IMAGE_NAME + DEPLOYMENT_ENV_FILE: "MAINNET_DEV_DEPLOYMENT_ENV" rules: - if: $CI_COMMIT_BRANCH == "develop" environment: -- GitLab From aa63ea48e678d4398a22614305db09607e128f7f Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 10 Jun 2025 23:13:32 +0200 Subject: [PATCH 16/26] run_instance should take .env file as obligatory option. Also removed additional parameters conflicting to .env file. --- .gitlab-ci.yml | 10 ++--- scripts/run_instance.sh | 82 +++-------------------------------------- 2 files changed, 8 insertions(+), 84 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca039e03f..e35cd2004 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -544,17 +544,13 @@ publish: echo -e "\e[0Ksection_end:$(date +%s):login\r\e[0K" script: - | + # credits of solution for gitlab bug: https://gitlab.com/gitlab-org/gitlab/-/issues/294292#note_1070210709 export DEPLOYMENT_ENV_FILE=${!DEPLOYMENT_ENV_FILE} - cat "${DEPLOYMENT_ENV_FILE}" - echo -e "\nValue of DEPLOYMENT_ENV_FILE is ${DEPLOYMENT_ENV_FILE}" + # Make visible all vars in the bash env + source "${DEPLOYMENT_ENV_FILE}" scripts/run_instance.sh \ --image="$IMAGE_NAME" \ - --app-scope="$TURBO_APP_SCOPE" \ - --app-path="$TURBO_APP_PATH" \ - --api-endpoint="https://api.hive.blog" \ - --chain-id="beeab0de00000000000000000000000000000000000000000000000000000000" \ - --images-endpoint="https://images.hive.blog/" \ --name="$CONTAINER_NAME" \ --port=$PORT \ --env-file="${DEPLOYMENT_ENV_FILE}" \ diff --git a/scripts/run_instance.sh b/scripts/run_instance.sh index d5fe3c511..3ea698cfe 100755 --- a/scripts/run_instance.sh +++ b/scripts/run_instance.sh @@ -9,37 +9,15 @@ Usage: $0 [OPTION[=VALUE]]... Run a Denser Docker instance OPTIONS: --image=IMAGE Docker image to run (default: 'registry.gitlab.syncad.com/hive/denser:latest') - --api-endpoint=URL API endpoint to be used by the new instance (default: 'https://api.hive.blog') - --wallet-endpoint=WALLET_ENDPOINT Wallet endpoint to be used by the new instance (default: 'https://wallet.hive.blog') - --site-domain=SITE_DOMAIN Site domain to be used by the new instance (default: 'https://blog.hive.blog') - --blog-domain=BLOG_DOMAIN Blog domain to be used by the new instance (default: 'https://blog.hive.blog') - --explorer-domain=EXPLORER_DOMAIN Explorer domain to be used by the new instance (default: 'https://explore.hive.blog') - --ai-domain=AI_DOMAIN AI domain to be used by the new instance (default: 'https://api.dev.openhive.network') - --openhive-chat-uri=OPENHIVE_CHAT_URI Chat URI to be used by the new instance (default: 'http://openhive.chat') - --chain-id=CHAIN_ID Chain ID to be used by the new instance (default: 'beeab0de00000000000000000000000000000000000000000000000000000000') - --images-endpoint=URL IMAGES endpoint to be used by the new instance (default: 'https://images.hive.blog/') - --app-scope=SCOPE App scope (eg. '@hive/auth') - --app-path=PATH App path (eg. '/apps/auth) --port=PORT Port to be exposed (default: 3000) --name=NAME Container name to be used (default: denser) - --env-file=overriden.env Path to a file containing environment variables to override i.e. deployment secrets + --env-file=deployment.env Obligatory path to a file containing environment variables to override i.e. deployment secrets --detach Run in detached mode --help|-h|-? Display this help screen and exit EOF } IMAGE_NAME=${IMAGE_NAME:-"registry.gitlab.syncad.com/hive/denser:latest"} -API_ENDPOINT=${API_ENDPOINT:-"https://api.hive.blog"} -WALLET_ENDPOINT=${WALLET_ENDPOINT:-"https://wallet.hive.blog"} -SITE_DOMAIN=${SITE_DOMAIN:-"https://blog.hive.blog"} -BLOG_DOMAIN=${BLOG_DOMAIN:-"https://blog.hive.blog"} -EXPLORER_DOMAIN=${EXPLORER_DOMAIN:-"https://explore.openhive.network"} -AI_DOMAIN=${AI_DOMAIN:-"https://api.dev.openhive.network"} -OPENHIVE_CHAT_URI=${OPENHIVE_CHAT_URI:-"http://openhive.chat"} -CHAIN_ID=${CHAIN_ID:-"beeab0de00000000000000000000000000000000000000000000000000000000"} -IMAGES_ENDPOINT=${IMAGES_ENDPOINT:="https://images.hive.blog/"} -TURBO_APP_SCOPE=${TURBO_APP_SCOPE:-} -TURBO_APP_PATH=${TURBO_APP_PATH:-} PORT=${PORT:-"3000"} CONTAINER_NAME=${CONTAINER_NAME:-"denser"} DETACH=${DETACH:-false} @@ -52,50 +30,6 @@ while [ $# -gt 0 ]; do arg="${1#*=}" IMAGE_NAME="$arg" ;; - --api-endpoint=*) - arg="${1#*=}" - API_ENDPOINT="$arg" - ;; - --wallet-endpoint=*) - arg="${1#*=}" - WALLET_ENDPOINT="$arg" - ;; - --site-domain=*) - arg="${1#*=}" - SITE_DOMAIN="$arg" - ;; - --blog-domain=*) - arg="${1#*=}" - BLOG_DOMAIN="$arg" - ;; - --openhive-chat-uri=*) - arg="${1#*=}" - OPENHIVE_CHAT_URI="$arg" - ;; - --explorer-domain=*) - arg="${1#*=}" - EXPLORER_DOMAIN="$arg" - ;; - --ai-domain=*) - arg="${1#*=}" - AI_DOMAIN="$arg" - ;; - --chain-id=*) - arg="${1#*=}" - CHAIN_ID="$arg" - ;; - --images-endpoint=*) - arg="${1#*=}" - IMAGES_ENDPOINT="$arg" - ;; - --app-scope=*) - arg="${1#*=}" - TURBO_APP_SCOPE="$arg" - ;; - --app-path=*) - arg="${1#*=}" - TURBO_APP_PATH="$arg" - ;; --port=*) arg="${1#*=}" PORT="$arg" @@ -136,24 +70,18 @@ RUN_OPTIONS=( "--rm" "--publish" "$PORT:$PORT" "--env" "PORT=$PORT" - "--env" "REACT_APP_API_ENDPOINT=$API_ENDPOINT" - "--env" "REACT_APP_BLOG_DOMAIN=$BLOG_DOMAIN" - "--env" "REACT_APP_IMAGES_ENDPOINT=$IMAGES_ENDPOINT" - "--env" "REACT_APP_WALLET_ENDPOINT=$WALLET_ENDPOINT" - "--env" "REACT_APP_EXPLORER_DOMAIN=$EXPLORER_DOMAIN" - "--env" "REACT_APP_AI_DOMAIN=$AI_DOMAIN" - "--env" "REACT_APP_OPENHIVE_CHAT_URI=$OPENHIVE_CHAT_URI" - "--env" "REACT_APP_SITE_DOMAIN=$SITE_DOMAIN" - "--env" "REACT_APP_CHAIN_ID=$CHAIN_ID" "--name" "$CONTAINER_NAME" ) if [ -n "${CUSTOM_ENV_FILE}" ]; then RUN_OPTIONS+=("-v" "${CUSTOM_ENV_FILE}:/app/apps/.env") +else + echo "ERROR: Env file must be specified at command line using option: --env-file" + exit 2 fi if [[ "$DETACH" == "true" ]]; then RUN_OPTIONS+=("--detach") fi -docker run "${RUN_OPTIONS[@]}" "$IMAGE_NAME" \ No newline at end of file +docker run "${RUN_OPTIONS[@]}" "$IMAGE_NAME" -- GitLab From 05d7b5f6f7cbcce97023d306e0a04f58f2fb4c96 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 11 Jun 2025 15:56:42 +0200 Subject: [PATCH 17/26] Adjusted definition of develop:deploy-wallet-mainnet to new environment definition (by file variable) --- .gitlab-ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e35cd2004..c8f4fb219 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -764,12 +764,8 @@ develop:deploy-wallet-mainnet: variables: CONTAINER_NAME: denser-dev-wallet PORT: 8122 - TURBO_APP_SCOPE: '@hive/wallet' - TURBO_APP_PATH: '/apps/wallet' - SITE_DOMAIN: https://wallet.dev.openhive.network - BLOG_DOMAIN: https://blog.dev.openhive.network - EXPLORER_DOMAIN: https://explore.openhive.network IMAGE_NAME: $WALLET_IMAGE_NAME + DEPLOYMENT_ENV_FILE: "MAINNET_DEV_DEPLOYMENT_ENV" rules: - if: $CI_COMMIT_BRANCH == "develop" environment: -- GitLab From 04b109d48bb08fe87c87463e132f72aa4887ba62 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 11 Jun 2025 15:58:35 +0200 Subject: [PATCH 18/26] Unified mainnet & mirrornet deployments. Also develop-mirrornet specific deployments adjusted to new env. specification using file variable --- .gitlab-ci.yml | 51 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8f4fb219..e8e5ae3cd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,8 +3,7 @@ stages: - replay-and-sync - test - test-report-aggregate - - deploy-mainnet - - deploy-mirrornet + - deploy - publish - cleanup @@ -534,9 +533,9 @@ publish: tags: - public-runner-docker -.deploy_template_mainnet: +.deploy_template: extends: .job-defaults - stage: deploy-mainnet + stage: deploy before_script: - | echo -e "\e[0Ksection_start:$(date +%s):login[collapsed=true]\r\e[0KLogging to Docker registry..." @@ -558,25 +557,9 @@ publish: tags: - hs-denser -.deploy_template_mirrornet: - extends: .deploy_template_mainnet - stage: deploy-mirrornet - script: - - | - scripts/run_instance.sh \ - --image="$IMAGE_NAME" \ - --app-scope="$TURBO_APP_SCOPE" \ - --app-path="$TURBO_APP_PATH" \ - --api-endpoint="https://api.fake.openhive.network/" \ - --chain-id="42" \ - --images-endpoint="https://images.hive.blog/" \ - --name="$CONTAINER_NAME" \ - --port=$PORT \ - --detach - # Main branch deployments (manual) main:deploy-blog-mainnet: - extends: .deploy_template_mainnet + extends: .deploy_template needs: - docker-build-blog - e2e-tests-blog @@ -598,7 +581,7 @@ main:deploy-blog-mainnet: on_stop: main:stop-blog-mainnet main:deploy-wallet-mainnet: - extends: .deploy_template_mainnet + extends: .deploy_template needs: - docker-build-wallet - e2e-tests-wallet @@ -620,7 +603,7 @@ main:deploy-wallet-mainnet: on_stop: main:stop-wallet-mainnet main:deploy-blog-mirrornet: - extends: .deploy_template_mirrornet + extends: .deploy_template needs: - docker-build-blog - e2e-tests-blog @@ -642,7 +625,7 @@ main:deploy-blog-mirrornet: on_stop: main:stop-blog-mirrornet main:deploy-wallet-mirrornet: - extends: .deploy_template_mirrornet + extends: .deploy_template needs: - docker-build-wallet - e2e-tests-wallet @@ -740,7 +723,7 @@ main:stop-wallet-mirrornet: # Develop branch deployments develop:deploy-blog-mainnet: - extends: .deploy_template_mainnet + extends: .deploy_template needs: - docker-build-blog - e2e-tests-blog @@ -757,7 +740,7 @@ develop:deploy-blog-mainnet: on_stop: develop:stop-blog-mainnet develop:deploy-wallet-mainnet: - extends: .deploy_template_mainnet + extends: .deploy_template needs: - docker-build-wallet - e2e-tests-wallet @@ -774,19 +757,15 @@ develop:deploy-wallet-mainnet: on_stop: develop:stop-wallet-mainnet develop:deploy-blog-mirrornet: - extends: .deploy_template_mirrornet + extends: .deploy_template needs: - docker-build-blog - e2e-tests-blog variables: CONTAINER_NAME: denser-dev-blog-mirror PORT: 8211 - TURBO_APP_SCOPE: '@hive/blog' - TURBO_APP_PATH: '/apps/blog' - SITE_DOMAIN: https://blog.dev.fake.openhive.network - WALLET_ENDPOINT: https://wallet.dev.fake.openhive.network - EXPLORER_DOMAIN: https://testexplorer.openhive.network IMAGE_NAME: $BLOG_IMAGE_NAME + DEPLOYMENT_ENV_FILE: "MIRRORNET_DEV_DEPLOYMENT_ENV" rules: - if: $CI_COMMIT_BRANCH == "develop" environment: @@ -795,19 +774,15 @@ develop:deploy-blog-mirrornet: on_stop: develop:stop-blog-mirrornet develop:deploy-wallet-mirrornet: - extends: .deploy_template_mirrornet + extends: .deploy_template needs: - docker-build-wallet - e2e-tests-wallet variables: CONTAINER_NAME: denser-dev-wallet-mirror PORT: 8222 - TURBO_APP_SCOPE: '@hive/wallet' - TURBO_APP_PATH: '/apps/wallet' - SITE_DOMAIN: https://wallet.dev.fake.openhive.network - BLOG_DOMAIN: https://blog.dev.fake.openhive.network - EXPLORER_DOMAIN: https://testexplorer.openhive.network IMAGE_NAME: $WALLET_IMAGE_NAME + DEPLOYMENT_ENV_FILE: "MIRRORNET_DEV_DEPLOYMENT_ENV" rules: - if: $CI_COMMIT_BRANCH == "develop" environment: -- GitLab From 624292523efc2e16c6a3f07a2115eb92755663a1 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 11 Jun 2025 16:00:19 +0200 Subject: [PATCH 19/26] mainnet production (main) specific deployments adjusted to new env. specification using file variable --- .gitlab-ci.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e8e5ae3cd..152f534e6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -566,12 +566,8 @@ main:deploy-blog-mainnet: variables: CONTAINER_NAME: denser-main-blog PORT: 9111 - TURBO_APP_SCOPE: '@hive/blog' - TURBO_APP_PATH: '/apps/blog' - SITE_DOMAIN: https://blog.openhive.network - WALLET_ENDPOINT: https://wallet.openhive.network - EXPLORER_DOMAIN: https://explore.openhive.network IMAGE_NAME: $BLOG_IMAGE_NAME + DEPLOYMENT_ENV_FILE: "MAINNET_PROD_DEPLOYMENT_ENV" rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH when: manual @@ -588,12 +584,8 @@ main:deploy-wallet-mainnet: variables: CONTAINER_NAME: denser-main-wallet PORT: 9122 - TURBO_APP_SCOPE: '@hive/wallet' - TURBO_APP_PATH: '/apps/wallet' - SITE_DOMAIN: https://wallet.openhive.network - BLOG_DOMAIN: https://blog.openhive.network - EXPLORER_DOMAIN: https://explore.openhive.network IMAGE_NAME: $WALLET_IMAGE_NAME + DEPLOYMENT_ENV_FILE: "MAINNET_PROD_DEPLOYMENT_ENV" rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH when: manual -- GitLab From e67fb086fc29a6c930011b7103fe47c95f8b8546 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 11 Jun 2025 12:39:01 +0200 Subject: [PATCH 20/26] WIP: temp. switched deployment branch --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 152f534e6..e8ef7920a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -725,7 +725,7 @@ develop:deploy-blog-mainnet: IMAGE_NAME: $BLOG_IMAGE_NAME DEPLOYMENT_ENV_FILE: "MAINNET_DEV_DEPLOYMENT_ENV" rules: - - if: $CI_COMMIT_BRANCH == "develop" + - if: $CI_COMMIT_BRANCH == "bw_eliminate_private_secrets" environment: name: develop-blog-mainnet url: https://blog.dev.openhive.network @@ -759,7 +759,7 @@ develop:deploy-blog-mirrornet: IMAGE_NAME: $BLOG_IMAGE_NAME DEPLOYMENT_ENV_FILE: "MIRRORNET_DEV_DEPLOYMENT_ENV" rules: - - if: $CI_COMMIT_BRANCH == "develop" + - if: $CI_COMMIT_BRANCH == "bw_eliminate_private_secrets" environment: name: develop-blog-mirrornet url: https://blog.dev.fake.openhive.network @@ -792,7 +792,7 @@ develop:stop-blog-mainnet: variables: CONTAINER_NAME: denser-dev-blog rules: - - if: $CI_COMMIT_BRANCH == "develop" + - if: $CI_COMMIT_BRANCH == "bw_eliminate_private_secrets" when: manual allow_failure: true environment: -- GitLab From e001a743ba00b0042e3809126ca0aa9846294c09 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Wed, 11 Jun 2025 17:57:38 +0200 Subject: [PATCH 21/26] run_instance.sh script also removes already existing container to avoid failure during respawn. --- scripts/run_instance.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/run_instance.sh b/scripts/run_instance.sh index 3ea698cfe..5fa25bc7d 100755 --- a/scripts/run_instance.sh +++ b/scripts/run_instance.sh @@ -66,6 +66,8 @@ done (docker ps -q --filter "name=$CONTAINER_NAME" | grep -q . && docker stop "$CONTAINER_NAME") || true +docker container rm --force "$CONTAINER_NAME" || true + RUN_OPTIONS=( "--rm" "--publish" "$PORT:$PORT" -- GitLab From 251aff8c49db0fcd2b054fdfe6d8682444e65c9b Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Mon, 16 Jun 2025 21:33:55 +0200 Subject: [PATCH 22/26] Removed unused auth app (and service definition) from mirrornet-based-tests job. --- .gitlab-ci.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e8ef7920a..c9aade5a3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -368,22 +368,6 @@ mirrornet-based-tests: - --from=https://caddy-wallet - --to=denser-wallet:4000 - --internal-certs - - name: $AUTH_IMAGE_NAME - alias: denser-auth - variables: - HEALTHCHECK_TCP_PORT: '5000' - PORT: '5000' - REACT_APP_SITE_DOMAIN: 'https://caddy-auth.local' - TURBO_APP_SCOPE: '@hive/auth' - TURBO_APP_PATH: '/apps/auth' - - name: caddy:${CADDY_TAG} - alias: caddy-auth - command: - - caddy - - reverse-proxy - - --from=https://caddy-auth - - --to=denser-auth:5000 - - --internal-certs variables: GIT_STRATEGY: 'clone' CI_DEBUG_SERVICES: 'false' -- GitLab From 410caee067df5cbde5f90b2345dd65c08f5a329b Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 17 Jun 2025 09:47:49 +0200 Subject: [PATCH 23/26] CI jobs adjusted to the .env files passed for mirrornet regression testing needs. --- .gitlab-ci.yml | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c9aade5a3..e5d95b045 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -102,24 +102,28 @@ mirrornet-haf-binaries-extraction: variables: TURBO_APP_NAME: "" BASE_IMAGE_NAME: "" - + ENV_FILE_PATHNAME: "./apps/${TURBO_APP_NAME}/.env.testing" + IMAGE_SUFFIX: "testenv" script: - | echo -e "\e[0Ksection_start:$(date +%s):login[collapsed=true]\r\e[0KLogging to Docker registry..." docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY echo -e "\e[0Ksection_end:$(date +%s):login\r\e[0K" + + export NEW_IMAGE_TAGNAME="${CI_REGISTRY_IMAGE}/${TURBO_APP_NAME}-${IMAGE_SUFFIX}:${CI_COMMIT_SHA}" + docker buildx build \ --push \ - -t "${CI_REGISTRY_IMAGE}/${TURBO_APP_NAME}-testenv:${CI_COMMIT_SHA}" -f- . << EOF + -t "${NEW_IMAGE_TAGNAME}" -f- . << EOF FROM $BASE_IMAGE_NAME AS production - COPY ./apps/${TURBO_APP_NAME}/.env.testing /app/apps/.env + COPY "${ENV_FILE_PATHNAME}" /app/apps/.env EOF - echo "DENSER_IMAGE_NAME=${CI_REGISTRY_IMAGE}/${TURBO_APP_NAME}-testenv:${CI_COMMIT_SHA}" > docker-build-testenv-image.env + echo "DENSER_${TURBO_APP_NAME^^}_IMAGE_NAME=${NEW_IMAGE_TAGNAME}" > docker-build-testenv-${TURBO_APP_NAME}-image.env artifacts: paths: - - docker-build-testenv-image.env + - docker-build-testenv-${TURBO_APP_NAME}-image.env reports: - dotenv: docker-build-testenv-image.env + dotenv: docker-build-testenv-${TURBO_APP_NAME}-image.env when: always # This ensures artifacts are created even if job fails tags: - public-runner-docker @@ -155,6 +159,26 @@ docker-build-wallet-testenv: TURBO_APP_NAME: 'wallet' BASE_IMAGE_NAME: ${WALLET_IMAGE_NAME} +docker-build-blog-mirrornet-testenv: + extends: .docker-build-testenv-image + needs: + - docker-build-blog + variables: + TURBO_APP_NAME: 'blog' + BASE_IMAGE_NAME: ${BLOG_IMAGE_NAME} + ENV_FILE_PATHNAME: "./apps/${TURBO_APP_NAME}/.env.mirrornet-testing" + IMAGE_SUFFIX: "mirrornet-testenv" + +docker-build-wallet-mirrornet-testenv: + extends: .docker-build-testenv-image + needs: + - docker-build-wallet + variables: + TURBO_APP_NAME: 'wallet' + BASE_IMAGE_NAME: ${WALLET_IMAGE_NAME} + ENV_FILE_PATHNAME: "./apps/${TURBO_APP_NAME}/.env.mirrornet-testing" + IMAGE_SUFFIX: "mirrornet-testenv" + # Hived binary built as a part of HAF requires an additional # library to function. This library has to be extracted from # the image and passed to job extended_block_log_creation. @@ -326,15 +350,15 @@ mirrornet-based-tests: - .node-job needs: - mirrornet-haf-binaries-extraction - - docker-build-blog - - docker-build-wallet + - docker-build-blog-mirrornet-testenv + - docker-build-wallet-mirrornet-testenv - mirrornet-replay-data-copy - block_log_processing image: 'mcr.microsoft.com/playwright:${PLAYWRIGHT_TAG}' allow_failure: true services: - !reference [.haf_api_node_test, services] - - name: $BLOG_IMAGE_NAME + - name: $DENSER_BLOG_IMAGE_NAME alias: denser-blog variables: HEALTHCHECK_TCP_PORT: '3000' @@ -351,7 +375,7 @@ mirrornet-based-tests: - --from=https://caddy-blog - --to=denser-blog:3000 - --internal-certs - - name: $WALLET_IMAGE_NAME + - name: $DENSER_WALLET_IMAGE_NAME alias: denser-wallet variables: HEALTHCHECK_TCP_PORT: '4000' @@ -407,7 +431,7 @@ e2e-tests-blog: - docker-build-blog-testenv services: - - name: $DENSER_IMAGE_NAME + - name: $DENSER_BLOG_IMAGE_NAME alias: denser variables: HEALTHCHECK_TCP_PORT: '3000' @@ -430,7 +454,7 @@ e2e-tests-wallet: - docker-build-wallet-testenv services: - - name: $DENSER_IMAGE_NAME + - name: $DENSER_WALLET_IMAGE_NAME alias: denser variables: HEALTHCHECK_TCP_PORT: '4000' -- GitLab From ea3046760fc80b624b27459ae985f2a9308b4c48 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 17 Jun 2025 09:48:29 +0200 Subject: [PATCH 24/26] Added .env file specific to blog mirrornet regression testing. --- apps/blog/.env.mirrornet-testing | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 apps/blog/.env.mirrornet-testing diff --git a/apps/blog/.env.mirrornet-testing b/apps/blog/.env.mirrornet-testing new file mode 100644 index 000000000..01ee5ca8c --- /dev/null +++ b/apps/blog/.env.mirrornet-testing @@ -0,0 +1,27 @@ +DENSER_SERVER_ENV_DUMP=true +REACT_APP_APP_NAME="blog" +REACT_APP_API_ENDPOINT="https://dind/" +REACT_APP_CHAIN_ID="44" +REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" +REACT_APP_LOGGING_BROWSER_ENABLED="true" +REACT_APP_LOGGING_LOG_LEVEL="debug" +REACT_APP_WALLET_ENDPOINT="https://caddy-wallet" +REACT_APP_SITE_DOMAIN="https://caddy-blog.local" +REACT_APP_BLOG_DOMAIN="https://caddy-blog" +REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' +REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' +REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" +REACT_APP_LOGIN_AUTHENTICATE_ON_BACKEND="no" +DENSER_SERVER_COOKIE_NAME_PREFIX="auth_" +DENSER_SERVER_SECRET_COOKIE_PASSWORD="SomeValueForTestingPurposesOnly" +DENSER_SERVER_OIDC_ENABLED="yes" +DENSER_SERVER_OIDC_COOKIES_KEYS="secret-devel-key" +REACT_APP_OPENHIVE_CHAT_CLIENT_ID="openhive_chat" +REACT_APP_OPENHIVE_CHAT_API_URI="https://your-chat/api/v1" +REACT_APP_OPENHIVE_CHAT_URI="https://your-chat" +REACT_APP_OPENHIVE_CHAT_IFRAME_INTEGRATION_ENABLE="no" +REACT_APP_OPENHIVE_CHAT_IFRAME_VISIBLE="yes" +REACT_APP_OPENHIVE_CHAT_ALLOW_NON_STRICT_LOGIN="no" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_ID="your-admin-user-id" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_TOKEN="your-admin-user-token" +ESLINT_USE_FLAT_CONFIG=false -- GitLab From ea04f17fbd824c9e875b8c84daa473c929d2f0f3 Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 17 Jun 2025 09:49:00 +0200 Subject: [PATCH 25/26] Added .env file specific to wallet mirrornet regression testing --- apps/wallet/.env.mirrornet-testing | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 apps/wallet/.env.mirrornet-testing diff --git a/apps/wallet/.env.mirrornet-testing b/apps/wallet/.env.mirrornet-testing new file mode 100644 index 000000000..13d921887 --- /dev/null +++ b/apps/wallet/.env.mirrornet-testing @@ -0,0 +1,27 @@ +DENSER_SERVER_ENV_DUMP=true +REACT_APP_APP_NAME="wallet" +REACT_APP_API_ENDPOINT="https://dind/" +REACT_APP_CHAIN_ID="44" +REACT_APP_IMAGES_ENDPOINT="https://images.hive.blog/" +REACT_APP_LOGGING_BROWSER_ENABLED="true" +REACT_APP_LOGGING_LOG_LEVEL="debug" +REACT_APP_WALLET_ENDPOINT="https://caddy-wallet" +REACT_APP_SITE_DOMAIN="https://caddy-wallet.local" +REACT_APP_BLOG_DOMAIN="https://caddy-blog" +REACT_APP_EXPLORER_DOMAIN='https://explore.openhive.network' +REACT_APP_AI_DOMAIN='https://api.dev.openhive.network' +REACT_APP_ALLOW_NON_STRICT_LOGIN="yes" +REACT_APP_LOGIN_AUTHENTICATE_ON_BACKEND="no" +DENSER_SERVER_COOKIE_NAME_PREFIX="auth_" +DENSER_SERVER_SECRET_COOKIE_PASSWORD="SomeValueForTestingPurposesOnly" +DENSER_SERVER_OIDC_ENABLED="yes" +DENSER_SERVER_OIDC_COOKIES_KEYS="secret-devel-key" +REACT_APP_OPENHIVE_CHAT_CLIENT_ID="openhive_chat" +REACT_APP_OPENHIVE_CHAT_API_URI="https://your-chat/api/v1" +REACT_APP_OPENHIVE_CHAT_URI="https://your-chat" +REACT_APP_OPENHIVE_CHAT_IFRAME_INTEGRATION_ENABLE="no" +REACT_APP_OPENHIVE_CHAT_IFRAME_VISIBLE="yes" +REACT_APP_OPENHIVE_CHAT_ALLOW_NON_STRICT_LOGIN="no" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_ID="your-admin-user-id" +DENSER_SERVER_OPENHIVE_CHAT_ADMIN_USER_TOKEN="your-admin-user-token" +ESLINT_USE_FLAT_CONFIG=false -- GitLab From e1fe09a4d93f2b80e042565cc1c3d3b2c9491cdd Mon Sep 17 00:00:00 2001 From: Bartek Wrona Date: Tue, 17 Jun 2025 15:12:23 +0200 Subject: [PATCH 26/26] Fixed path to report.xml generated during mirrornet tests --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e5d95b045..557a9e316 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -417,11 +417,11 @@ mirrornet-based-tests: - '*.log' - 'logs/' - '*.env' - - 'playwright-report/' - - 'test-results/' - - 'junit/' + - './apps/blog/playwright-report/' + - './apps/blog/test-results/' + - './apps/blog/junit/' reports: - junit: 'junit/results.xml' + junit: 'apps/blog/junit/results.xml' tags: - data-cache-storage -- GitLab