prometheus/utility/embed-static.sh
Julius Volz 8cb2c802a0 Dramatically decrease resources for file embedding.
This dramatically decreases the needed time and memory for building the
blob files. The memory numbers are measured via the
memory.max_usage_in_bytes value from cgroups.

* generating files.go:
OLD: 466MB   19s
NEW:  80MB    1s

* building files.go:
OLD: 1210MB  2.25s
NEW:    7MB  0.05s
2015-02-13 17:16:44 +01:00

33 lines
796 B
Bash
Executable file

#!/bin/sh
set -e
cat <<EOF
package blob
var files = map [string] map [string] []byte {
EOF
ORIGINAL_PWD=${PWD}
for dir in $@
do
cd "${dir}"
echo "\"$(basename ${dir})\": {"
# Do not embed map files and the non-minified bootstrap files.
# TODO(beorn7): There should be a better solution than hardcoding the
# exclusion here. We might want to switch to a less makeshift way of
# embedding files into the binary anyway...
find . -type f \! -name \*.map \! -name bootstrap.js \! -name bootstrap-theme.css \! -name bootstrap.css | while read file
do
name=$(echo "${file}"|sed 's|\.\/||')
echo -n "\"$name\": []byte(\""
gzip -9 -c "${file}" | xxd -p | tr -d '\n' | sed 's/\(..\)/\\x\1/g'
echo "\"),"
echo
done
echo "},"
cd "${ORIGINAL_PWD}"
done
echo '}'