Commit 6cdaafc0 authored by tom goriunov's avatar tom goriunov Committed by GitHub

Move generated assets into separate folder inside the public folder (#1930)

* add build-time ENV to explicitly enable Open Telemetry

* generate svg-sprite before next build

* move envs.js to assets folder

* move favicon bundle to assets folder

* move external configs to configs folder

* fix envs validator
parent 601dca6a
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
# next.js # next.js
/.next/ /.next/
/out/ /out/
/public/assets/ /public/assets/envs.js
/public/envs.js /public/assets/configs
/public/icons/sprite.svg /public/icons/sprite.svg
/public/icons/README.md /public/icons/README.md
/analyze /analyze
......
...@@ -34,11 +34,13 @@ RUN yarn --frozen-lockfile ...@@ -34,11 +34,13 @@ RUN yarn --frozen-lockfile
FROM node:20.11.0-alpine AS builder FROM node:20.11.0-alpine AS builder
RUN apk add --no-cache --upgrade libc6-compat bash RUN apk add --no-cache --upgrade libc6-compat bash
# pass commit sha and git tag to the app image # pass build args to env variables
ARG GIT_COMMIT_SHA ARG GIT_COMMIT_SHA
ENV NEXT_PUBLIC_GIT_COMMIT_SHA=$GIT_COMMIT_SHA ENV NEXT_PUBLIC_GIT_COMMIT_SHA=$GIT_COMMIT_SHA
ARG GIT_TAG ARG GIT_TAG
ENV NEXT_PUBLIC_GIT_TAG=$GIT_TAG ENV NEXT_PUBLIC_GIT_TAG=$GIT_TAG
ARG NEXT_OPEN_TELEMETRY_ENABLED
ENV NEXT_OPEN_TELEMETRY_ENABLED=$NEXT_OPEN_TELEMETRY_ENABLED
ENV NODE_ENV production ENV NODE_ENV production
...@@ -58,8 +60,8 @@ RUN ./collect_envs.sh ./docs/ENVS.md ...@@ -58,8 +60,8 @@ RUN ./collect_envs.sh ./docs/ENVS.md
# ENV NEXT_TELEMETRY_DISABLED 1 # ENV NEXT_TELEMETRY_DISABLED 1
# Build app for production # Build app for production
RUN yarn build
RUN yarn svg:build-sprite RUN yarn svg:build-sprite
RUN yarn build
### FEATURE REPORTER ### FEATURE REPORTER
......
...@@ -41,7 +41,7 @@ export const buildExternalAssetFilePath = (name: string, value: string) => { ...@@ -41,7 +41,7 @@ export const buildExternalAssetFilePath = (name: string, value: string) => {
const fileName = name.replace(/^NEXT_PUBLIC_/, '').replace(/_URL$/, '').toLowerCase(); const fileName = name.replace(/^NEXT_PUBLIC_/, '').replace(/_URL$/, '').toLowerCase();
const url = new URL(value); const url = new URL(value);
const fileExtension = url.pathname.match(regexp.FILE_EXTENSION)?.[1]; const fileExtension = url.pathname.match(regexp.FILE_EXTENSION)?.[1];
return `/assets/${ fileName }.${ fileExtension }`; return `/assets/configs/${ fileName }.${ fileExtension }`;
} catch (error) { } catch (error) {
return; return;
} }
......
...@@ -36,7 +36,7 @@ export_envs_from_preset() { ...@@ -36,7 +36,7 @@ export_envs_from_preset() {
export_envs_from_preset export_envs_from_preset
# Download external assets # Download external assets
./download_assets.sh ./public/assets ./download_assets.sh ./public/assets/configs
# Check run-time ENVs values # Check run-time ENVs values
./validate_envs.sh ./validate_envs.sh
......
...@@ -10,7 +10,7 @@ if [ $? -ne 0 ]; then ...@@ -10,7 +10,7 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
else else
cd ../../../ cd ../../../
favicon_folder="./public/favicon/" favicon_folder="./public/assets/favicon/"
echo "⏳ Replacing default favicons with freshly generated pack..." echo "⏳ Replacing default favicons with freshly generated pack..."
if [ -d "$favicon_folder" ]; then if [ -d "$favicon_folder" ]; then
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
echo "🌀 Creating client script with ENV values..." echo "🌀 Creating client script with ENV values..."
# Define the output file name # Define the output file name
output_file="${1:-./public/envs.js}" output_file="${1:-./public/assets/envs.js}"
touch $output_file; touch $output_file;
truncate -s 0 $output_file; truncate -s 0 $output_file;
......
...@@ -9,7 +9,7 @@ export NEXT_PUBLIC_GIT_TAG=$(git describe --tags --abbrev=0) ...@@ -9,7 +9,7 @@ export NEXT_PUBLIC_GIT_TAG=$(git describe --tags --abbrev=0)
../../scripts/collect_envs.sh ../../../docs/ENVS.md ../../scripts/collect_envs.sh ../../../docs/ENVS.md
# Copy test assets # Copy test assets
mkdir -p "./public/assets" mkdir -p "./public/assets/configs"
cp -r ${test_folder}/assets ./public/ cp -r ${test_folder}/assets ./public/
# Build validator script # Build validator script
......
...@@ -661,11 +661,11 @@ The feature enables the Validators page which provides detailed information abou ...@@ -661,11 +661,11 @@ The feature enables the Validators page which provides detailed information abou
### OpenTelemetry ### OpenTelemetry
OpenTelemetry SDK for Node.js app could be enabled by passing `OTEL_SDK_ENABLED=true` variable. Configure the OpenTelemetry Protocol Exporter by using the generic environment variables described in the [OT docs](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#configuration-options). OpenTelemetry SDK for Node.js app could be enabled by passing `OTEL_SDK_ENABLED=true` variable. Configure the OpenTelemetry Protocol Exporter by using the generic environment variables described in the [OT docs](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#configuration-options). Note that this Next.js feature is currently experimental. The Docker image should be built with the `NEXT_OPEN_TELEMETRY_ENABLED=true` argument to enable it.
| Variable | Type| Description | Compulsoriness | Default value | Example value | | Variable | Type| Description | Compulsoriness | Default value | Example value |
| --- | --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- | --- |
| OTEL_SDK_ENABLED | `boolean` | Flag to enable the feature | Required | `false` | `true` | | OTEL_SDK_ENABLED | `boolean` | Run-time flag to enable the feature | Required | `false` | `true` |
   
......
...@@ -46,9 +46,7 @@ const sdk = new NodeSDK({ ...@@ -46,9 +46,7 @@ const sdk = new NodeSDK({
url.pathname.startsWith('/_next/static/') || url.pathname.startsWith('/_next/static/') ||
url.pathname.startsWith('/_next/data/') || url.pathname.startsWith('/_next/data/') ||
url.pathname.startsWith('/assets/') || url.pathname.startsWith('/assets/') ||
url.pathname.startsWith('/static/') || url.pathname.startsWith('/static/')
url.pathname.startsWith('/favicon/') ||
url.pathname.startsWith('/envs.js')
) { ) {
return true; return true;
} }
......
...@@ -46,7 +46,7 @@ const moduleExports = { ...@@ -46,7 +46,7 @@ const moduleExports = {
output: 'standalone', output: 'standalone',
productionBrowserSourceMaps: true, productionBrowserSourceMaps: true,
experimental: { experimental: {
instrumentationHook: true, instrumentationHook: process.env.NEXT_OPEN_TELEMETRY_ENABLED === 'true',
turbo: { turbo: {
rules: { rules: {
'*.svg': { '*.svg': {
......
...@@ -44,14 +44,14 @@ class MyDocument extends Document { ...@@ -44,14 +44,14 @@ class MyDocument extends Document {
/> />
{ /* eslint-disable-next-line @next/next/no-sync-scripts */ } { /* eslint-disable-next-line @next/next/no-sync-scripts */ }
<script src="/envs.js"/> <script src="/assets/envs.js"/>
{ /* FAVICON */ } { /* FAVICON */ }
<link rel="icon" href="/favicon/favicon.ico" sizes="48x48"/> <link rel="icon" href="/assets/favicon/favicon.ico" sizes="48x48"/>
<link rel="icon" sizes="32x32" type="image/png" href="/favicon/favicon-32x32.png"/> <link rel="icon" sizes="32x32" type="image/png" href="/assets/favicon/favicon-32x32.png"/>
<link rel="icon" sizes="16x16" type="image/png"href="/favicon/favicon-16x16.png"/> <link rel="icon" sizes="16x16" type="image/png"href="/assets/favicon/favicon-16x16.png"/>
<link rel="apple-touch-icon" href="/favicon/apple-touch-icon-180x180.png"/> <link rel="apple-touch-icon" href="/assets/favicon/apple-touch-icon-180x180.png"/>
<link rel="mask-icon" href="/favicon/safari-pinned-tab.svg"/> <link rel="mask-icon" href="/assets/favicon/safari-pinned-tab.svg"/>
<link rel="preload" as="image" href={ svgSprite.href }/> <link rel="preload" as="image" href={ svgSprite.href }/>
</Head> </Head>
......
**Directories**
- `/icons` - Folder for SVG-sprite assets, generated at build time.
- `/static` - Folder for static assets that are consistent between app re-runs but may differ from one build version to another.
- `/assets` - Folder for dynamically generated assets during the app start, such as the favicon bundle, ENV variables file, and external app configurations.
\ No newline at end of file
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 180"> <svg version="1.0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 180 180">
<path d="M34.9 2.9c-2.9 2.9-2.9 3-2.9 15 0 6.8-.5 13.1-1.1 14.5-1.9 4-6.6 5.6-16.6 5.6C4.7 38 1.7 39.4.5 44.3.2 45.5.1 75.4.2 110.7l.3 64.2 2.3 2.3c2.1 2.1 3.3 2.3 14.6 2.6 14.8.4 17.9-.6 19.5-6.6.7-2.4 1.1-26.2 1.1-66.9V43.1l2.4-2.8c2.3-2.7 2.9-2.8 13.6-3.3 15-.7 15-.6 15-18.2v-13l-2.9-2.9C63.2 0 63.2 0 50.5 0S37.8 0 34.9 2.9zM111.8 1.5c-3.9 2.2-5.1 7.8-4.6 20.4.5 9.8.6 10.6 3.2 12.8 2.3 2 3.8 2.3 10.5 2.3 4.3 0 9.2.5 11 1.1 6.3 2.2 6.1.3 6.1 71.4v64.7l2.9 2.9c2.9 2.9 3 2.9 15.4 2.9 12 0 12.7-.1 15.6-2.6l3.1-2.6V42.9l-2.5-2.4c-2.2-2.2-3.2-2.5-10.5-2.5-8.1 0-14-1.6-15.6-4.1-.5-.8-1.1-7.6-1.4-15.1C144.3.3 144.6.6 127.2.2c-9.8-.1-13.3.1-15.4 1.3zM72.3 74.4l-2.8 2.4-.3 30.6-.3 30.5 3 3.3 2.9 3.3h13.1c12.9 0 13.1 0 15.8-2.8l2.8-2.7V76.8l-2.8-2.4C101 72.1 100.2 72 88 72s-13 .1-15.7 2.4z"/> <path d="M34.9 2.9c-2.9 2.9-2.9 3-2.9 15 0 6.8-.5 13.1-1.1 14.5-1.9 4-6.6 5.6-16.6 5.6C4.7 38 1.7 39.4.5 44.3.2 45.5.1 75.4.2 110.7l.3 64.2 2.3 2.3c2.1 2.1 3.3 2.3 14.6 2.6 14.8.4 17.9-.6 19.5-6.6.7-2.4 1.1-26.2 1.1-66.9V43.1l2.4-2.8c2.3-2.7 2.9-2.8 13.6-3.3 15-.7 15-.6 15-18.2v-13l-2.9-2.9C63.2 0 63.2 0 50.5 0S37.8 0 34.9 2.9zm76.9-1.4c-3.9 2.2-5.1 7.8-4.6 20.4.5 9.8.6 10.6 3.2 12.8 2.3 2 3.8 2.3 10.5 2.3 4.3 0 9.2.5 11 1.1 6.3 2.2 6.1.3 6.1 71.4v64.7l2.9 2.9c2.9 2.9 3 2.9 15.4 2.9 12 0 12.7-.1 15.6-2.6l3.1-2.6V42.9l-2.5-2.4c-2.2-2.2-3.2-2.5-10.5-2.5-8.1 0-14-1.6-15.6-4.1-.5-.8-1.1-7.6-1.4-15.1C144.3.3 144.6.6 127.2.2c-9.8-.1-13.3.1-15.4 1.3zM72.3 74.4l-2.8 2.4-.3 30.6-.3 30.5 3 3.3 2.9 3.3h13.1c12.9 0 13.1 0 15.8-2.8l2.8-2.7V76.8l-2.8-2.4C101 72.1 100.2 72 88 72s-13 .1-15.7 2.4z"/>
</svg> </svg>
...@@ -17,7 +17,7 @@ fi ...@@ -17,7 +17,7 @@ fi
# download assets for the running instance # download assets for the running instance
dotenv \ dotenv \
-e $config_file \ -e $config_file \
-- bash -c './deploy/scripts/download_assets.sh ./public/assets' -- bash -c './deploy/scripts/download_assets.sh ./public/assets/configs'
yarn svg:build-sprite yarn svg:build-sprite
echo "" echo ""
......
...@@ -6,7 +6,7 @@ dotenv \ ...@@ -6,7 +6,7 @@ dotenv \
-e .env.local \ -e .env.local \
-e .env.development \ -e .env.development \
-e .env \ -e .env \
-- bash -c './deploy/scripts/download_assets.sh ./public/assets' -- bash -c './deploy/scripts/download_assets.sh ./public/assets/configs'
yarn svg:build-sprite yarn svg:build-sprite
echo "" echo ""
......
secrets_file="./configs/envs/.env.secrets" secrets_file="./configs/envs/.env.secrets"
favicon_folder="./public/favicon/" favicon_folder="./public/assets/favicon/"
master_url="https://raw.githubusercontent.com/blockscout/frontend/main/tools/scripts/favicon.svg" master_url="https://raw.githubusercontent.com/blockscout/frontend/main/tools/scripts/favicon.svg"
if [ ! -f "$secrets_file" ]; then if [ ! -f "$secrets_file" ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment