2022-03-09 09:21:31 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2022-03-20 14:08:32 +00:00
|
|
|
# compress static assets
|
2022-03-09 09:21:31 +00:00
|
|
|
|
2022-03-20 14:08:32 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
makefile: Add support for skipping UI build when prebuilt assets are provided
This commit introduces the ability to skip the UI build in the Makefile by
providing prebuilt UI assets, addressing the needs of users who may not have npm
installed or who do not want to go through the front-end build process.
To achieve this, we added the `PREBUILT_ASSETS_STATIC_DIR` environment variable.
If this variable is set, the Makefile will skip the UI build and related tasks,
such as bundling npm licenses. Instead, it will use the prebuilt assets from
the specified directory.
We already publish prebuilt UI assets as part of our release artifacts
(e.g., `prometheus-web-ui-3.0.0-beta.0.tar.gz`). Users can download this tarball,
extract it, and point the `PREBUILT_ASSETS_STATIC_DIR` to the extracted folder.
This reduces build complexity, especially for users who don't have a development
environment for front-end builds.
For example, you can use the command:
`make PREBUILT_ASSETS_STATIC_DIR=static build`
where `static` refers to the directory containing the prebuilt UI files.
This change simplifies the build process while still allowing users to use a
prebuilt UI if desired.
This solution is particularly useful for users who don't need to modify the UI
and prefer to use the prebuilt version that we provide with each release.
Signed-off-by: Julien <roidelapluie@o11y.eu>
2024-09-12 10:20:24 +00:00
|
|
|
export STATIC_DIR=static
|
|
|
|
PREBUILT_ASSETS_STATIC_DIR=${PREBUILT_ASSETS_STATIC_DIR:-}
|
|
|
|
if [ -n "$PREBUILT_ASSETS_STATIC_DIR" ]; then
|
|
|
|
STATIC_DIR=$(realpath $PREBUILT_ASSETS_STATIC_DIR)
|
|
|
|
fi
|
|
|
|
|
2022-03-20 14:08:32 +00:00
|
|
|
cd web/ui
|
|
|
|
cp embed.go.tmpl embed.go
|
2022-09-06 12:24:06 +00:00
|
|
|
|
|
|
|
GZIP_OPTS="-fk"
|
|
|
|
# gzip option '-k' may not always exist in the latest gzip available on different distros.
|
|
|
|
if ! gzip -k -h &>/dev/null; then GZIP_OPTS="-f"; fi
|
|
|
|
|
makefile: Add support for skipping UI build when prebuilt assets are provided
This commit introduces the ability to skip the UI build in the Makefile by
providing prebuilt UI assets, addressing the needs of users who may not have npm
installed or who do not want to go through the front-end build process.
To achieve this, we added the `PREBUILT_ASSETS_STATIC_DIR` environment variable.
If this variable is set, the Makefile will skip the UI build and related tasks,
such as bundling npm licenses. Instead, it will use the prebuilt assets from
the specified directory.
We already publish prebuilt UI assets as part of our release artifacts
(e.g., `prometheus-web-ui-3.0.0-beta.0.tar.gz`). Users can download this tarball,
extract it, and point the `PREBUILT_ASSETS_STATIC_DIR` to the extracted folder.
This reduces build complexity, especially for users who don't have a development
environment for front-end builds.
For example, you can use the command:
`make PREBUILT_ASSETS_STATIC_DIR=static build`
where `static` refers to the directory containing the prebuilt UI files.
This change simplifies the build process while still allowing users to use a
prebuilt UI if desired.
This solution is particularly useful for users who don't need to modify the UI
and prefer to use the prebuilt version that we provide with each release.
Signed-off-by: Julien <roidelapluie@o11y.eu>
2024-09-12 10:20:24 +00:00
|
|
|
mkdir -p static
|
2022-03-20 14:08:32 +00:00
|
|
|
find static -type f -name '*.gz' -delete
|
makefile: Add support for skipping UI build when prebuilt assets are provided
This commit introduces the ability to skip the UI build in the Makefile by
providing prebuilt UI assets, addressing the needs of users who may not have npm
installed or who do not want to go through the front-end build process.
To achieve this, we added the `PREBUILT_ASSETS_STATIC_DIR` environment variable.
If this variable is set, the Makefile will skip the UI build and related tasks,
such as bundling npm licenses. Instead, it will use the prebuilt assets from
the specified directory.
We already publish prebuilt UI assets as part of our release artifacts
(e.g., `prometheus-web-ui-3.0.0-beta.0.tar.gz`). Users can download this tarball,
extract it, and point the `PREBUILT_ASSETS_STATIC_DIR` to the extracted folder.
This reduces build complexity, especially for users who don't have a development
environment for front-end builds.
For example, you can use the command:
`make PREBUILT_ASSETS_STATIC_DIR=static build`
where `static` refers to the directory containing the prebuilt UI files.
This change simplifies the build process while still allowing users to use a
prebuilt UI if desired.
This solution is particularly useful for users who don't need to modify the UI
and prefer to use the prebuilt version that we provide with each release.
Signed-off-by: Julien <roidelapluie@o11y.eu>
2024-09-12 10:20:24 +00:00
|
|
|
|
|
|
|
# Compress files from the prebuilt static directory and replicate the structure in the current static directory
|
|
|
|
find "${STATIC_DIR}" -type f ! -name '*.gz' -exec bash -c '
|
|
|
|
for file; do
|
|
|
|
dest="${file#${STATIC_DIR}}"
|
|
|
|
mkdir -p "static/$(dirname "$dest")"
|
|
|
|
gzip '"$GZIP_OPTS"' "$file" -c > "static/${dest}.gz"
|
|
|
|
done
|
|
|
|
' bash {} +
|
|
|
|
|
|
|
|
# Append the paths of gzipped files to embed.go
|
|
|
|
find static -type f -name '*.gz' -print0 | sort -z | xargs -0 echo //go:embed >> embed.go
|
|
|
|
|
2022-03-20 14:08:32 +00:00
|
|
|
echo var EmbedFS embed.FS >> embed.go
|