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
@@ -12,8 +12,8 @@
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
/public/assets/
|
||||
/public/envs.js
|
||||
/public/assets/envs.js
|
||||
/public/assets/configs
|
||||
/public/icons/sprite.svg
|
||||
/public/icons/README.md
|
||||
/analyze
|
||||
|
||||
@@ -34,11 +34,13 @@ RUN yarn --frozen-lockfile
|
||||
FROM node:20.11.0-alpine AS builder
|
||||
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
|
||||
ENV NEXT_PUBLIC_GIT_COMMIT_SHA=$GIT_COMMIT_SHA
|
||||
ARG 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
|
||||
|
||||
@@ -58,8 +60,8 @@ RUN ./collect_envs.sh ./docs/ENVS.md
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
# Build app for production
|
||||
RUN yarn build
|
||||
RUN yarn svg:build-sprite
|
||||
RUN yarn build
|
||||
|
||||
|
||||
### FEATURE REPORTER
|
||||
|
||||
@@ -41,7 +41,7 @@ export const buildExternalAssetFilePath = (name: string, value: string) => {
|
||||
const fileName = name.replace(/^NEXT_PUBLIC_/, '').replace(/_URL$/, '').toLowerCase();
|
||||
const url = new URL(value);
|
||||
const fileExtension = url.pathname.match(regexp.FILE_EXTENSION)?.[1];
|
||||
return `/assets/${ fileName }.${ fileExtension }`;
|
||||
return `/assets/configs/${ fileName }.${ fileExtension }`;
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export_envs_from_preset() {
|
||||
export_envs_from_preset
|
||||
|
||||
# Download external assets
|
||||
./download_assets.sh ./public/assets
|
||||
./download_assets.sh ./public/assets/configs
|
||||
|
||||
# Check run-time ENVs values
|
||||
./validate_envs.sh
|
||||
|
||||
@@ -10,7 +10,7 @@ if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
else
|
||||
cd ../../../
|
||||
favicon_folder="./public/favicon/"
|
||||
favicon_folder="./public/assets/favicon/"
|
||||
|
||||
echo "⏳ Replacing default favicons with freshly generated pack..."
|
||||
if [ -d "$favicon_folder" ]; then
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
echo "🌀 Creating client script with ENV values..."
|
||||
|
||||
# Define the output file name
|
||||
output_file="${1:-./public/envs.js}"
|
||||
output_file="${1:-./public/assets/envs.js}"
|
||||
|
||||
touch $output_file;
|
||||
truncate -s 0 $output_file;
|
||||
|
||||
@@ -9,7 +9,7 @@ export NEXT_PUBLIC_GIT_TAG=$(git describe --tags --abbrev=0)
|
||||
../../scripts/collect_envs.sh ../../../docs/ENVS.md
|
||||
|
||||
# Copy test assets
|
||||
mkdir -p "./public/assets"
|
||||
mkdir -p "./public/assets/configs"
|
||||
cp -r ${test_folder}/assets ./public/
|
||||
|
||||
# Build validator script
|
||||
|
||||
@@ -661,11 +661,11 @@ The feature enables the Validators page which provides detailed information abou
|
||||
|
||||
### 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 |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| 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({
|
||||
url.pathname.startsWith('/_next/static/') ||
|
||||
url.pathname.startsWith('/_next/data/') ||
|
||||
url.pathname.startsWith('/assets/') ||
|
||||
url.pathname.startsWith('/static/') ||
|
||||
url.pathname.startsWith('/favicon/') ||
|
||||
url.pathname.startsWith('/envs.js')
|
||||
url.pathname.startsWith('/static/')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ const moduleExports = {
|
||||
output: 'standalone',
|
||||
productionBrowserSourceMaps: true,
|
||||
experimental: {
|
||||
instrumentationHook: true,
|
||||
instrumentationHook: process.env.NEXT_OPEN_TELEMETRY_ENABLED === 'true',
|
||||
turbo: {
|
||||
rules: {
|
||||
'*.svg': {
|
||||
|
||||
@@ -44,14 +44,14 @@ class MyDocument extends Document {
|
||||
/>
|
||||
|
||||
{ /* eslint-disable-next-line @next/next/no-sync-scripts */ }
|
||||
<script src="/envs.js"/>
|
||||
<script src="/assets/envs.js"/>
|
||||
|
||||
{ /* FAVICON */ }
|
||||
<link rel="icon" href="/favicon/favicon.ico" sizes="48x48"/>
|
||||
<link rel="icon" sizes="32x32" type="image/png" href="/favicon/favicon-32x32.png"/>
|
||||
<link rel="icon" sizes="16x16" type="image/png"href="/favicon/favicon-16x16.png"/>
|
||||
<link rel="apple-touch-icon" href="/favicon/apple-touch-icon-180x180.png"/>
|
||||
<link rel="mask-icon" href="/favicon/safari-pinned-tab.svg"/>
|
||||
<link rel="icon" href="/assets/favicon/favicon.ico" sizes="48x48"/>
|
||||
<link rel="icon" sizes="32x32" type="image/png" href="/assets/favicon/favicon-32x32.png"/>
|
||||
<link rel="icon" sizes="16x16" type="image/png"href="/assets/favicon/favicon-16x16.png"/>
|
||||
<link rel="apple-touch-icon" href="/assets/favicon/apple-touch-icon-180x180.png"/>
|
||||
<link rel="mask-icon" href="/assets/favicon/safari-pinned-tab.svg"/>
|
||||
|
||||
<link rel="preload" as="image" href={ svgSprite.href }/>
|
||||
</Head>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
**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.
|
||||
|
Before Width: | Height: | Size: 736 B After Width: | Height: | Size: 736 B |
|
Before Width: | Height: | Size: 833 B After Width: | Height: | Size: 833 B |
|
Before Width: | Height: | Size: 791 B After Width: | Height: | Size: 791 B |
|
Before Width: | Height: | Size: 515 B After Width: | Height: | Size: 515 B |
|
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
|
Before Width: | Height: | Size: 791 B After Width: | Height: | Size: 791 B |
|
Before Width: | Height: | Size: 383 B After Width: | Height: | Size: 383 B |
|
Before Width: | Height: | Size: 439 B After Width: | Height: | Size: 439 B |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,3 @@
|
||||
<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.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>
|
||||
|
After Width: | Height: | Size: 881 B |
@@ -1,3 +0,0 @@
|
||||
<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"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 882 B |
@@ -17,7 +17,7 @@ fi
|
||||
# download assets for the running instance
|
||||
dotenv \
|
||||
-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
|
||||
echo ""
|
||||
|
||||
@@ -6,7 +6,7 @@ dotenv \
|
||||
-e .env.local \
|
||||
-e .env.development \
|
||||
-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
|
||||
echo ""
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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"
|
||||
|
||||
if [ ! -f "$secrets_file" ]; then
|
||||
|
||||