Skip to content

Commit

Permalink
Don't check in zstd compressed files
Browse files Browse the repository at this point in the history
Compress gui assets on startup to reduce git bloat.
  • Loading branch information
riptl committed Nov 16, 2024
1 parent 82822e4 commit 881a2ec
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 100 deletions.
41 changes: 3 additions & 38 deletions src/app/fdctl/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -187,63 +187,28 @@ frontend:
rm -rf src/app/fdctl/dist
mkdir -p src/app/fdctl/dist
cp -r frontend/dist/* src/app/fdctl/dist
> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "/* THIS FILE WAS GENERATED BY make frontend. DO NOT EDIT BY HAND! */" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "#ifndef HEADER_fd_src_app_fdctl_run_tiles_generated_http_import_dist_h" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "#define HEADER_fd_src_app_fdctl_run_tiles_generated_http_import_dist_h" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "#include \"../../../../../util/fd_util.h\"" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
counter=0; \
for file in $$(find src/app/fdctl/dist -type f); do \
counter=$$((counter + 1)); \
done; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "struct fd_http_static_file {" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo " char const * name;" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo " uchar const * data;" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo " ulong const * data_len;" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo " uchar const * zstd_data;" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo " ulong const * zstd_data_len;" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "};" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "typedef struct fd_http_static_file fd_http_static_file_t;" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "extern fd_http_static_file_t STATIC_FILES[$$counter];" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
echo "#endif" >> src/app/fdctl/run/tiles/generated/http_import_dist.h; \
> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo "/* THIS FILE WAS GENERATED BY make frontend. DO NOT EDIT BY HAND! */" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo "#include \"http_import_dist.h\"" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
counter=0; \
for file in $$(find src/app/fdctl/dist -type f); do \
if [[ "$$file" == *.svg || "$$file" == *.js || "$$file" == *.css ]]; then \
zstd -19 -o "$$file.zstd" "$$file"; \
echo "FD_IMPORT_BINARY( file$${counter}_zstd, \"$$file.zstd\" );" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
fi; \
for file in $$(find src/app/fdctl/dist -type f | sort); do \
echo "FD_IMPORT_BINARY( file$$counter, \"$$file\" );" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
counter=$$((counter + 1)); \
done; \
echo "" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo "fd_http_static_file_t STATIC_FILES[] = {" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
counter=0; \
for file in $$(find src/app/fdctl/dist -type f ! -name "*.zstd"); do \
for file in $$(find src/app/fdctl/dist -type f | sort); do \
stripped_file=$$(echo $$file | sed 's|^src/app/fdctl/dist/||'); \
echo " {" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo " .name = \"/$$stripped_file\"," >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo " .data = file$$counter," >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo " .data_len = &file$${counter}_sz," >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
if [[ "$$file" == *.svg || "$$file" == *.js || "$$file" == *.css ]]; then \
echo " .zstd_data = file$${counter}_zstd," >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo " .zstd_data_len = &file$${counter}_zstd_sz" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
else \
echo " .zstd_data = NULL," >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo " .zstd_data_len = 0UL" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
fi; \
echo " }," >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
counter=$$((counter + 1)); \
done; \
echo " {0}" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \
echo "};" >> src/app/fdctl/run/tiles/generated/http_import_dist.c; \

endif
Expand Down
Binary file not shown.
Binary file not shown.
Binary file removed src/app/fdctl/dist/assets/index-B5qDGMhj.css.zstd
Binary file not shown.
Binary file removed src/app/fdctl/dist/assets/index-DL5ZAE5v.js.zstd
Binary file not shown.
Binary file removed src/app/fdctl/dist/assets/index-DhI9vJrW.js.zstd
Binary file not shown.
Binary file removed src/app/fdctl/dist/assets/index-Dz6VwGqc.css.zstd
Binary file not shown.
Binary file not shown.
49 changes: 37 additions & 12 deletions src/app/fdctl/run/tiles/fd_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
#include "../../version.h"

#include "../../../../disco/keyguard/fd_keyload.h"
#include "../../../../disco/shred/fd_stake_ci.h"
#include "../../../../disco/gui/fd_gui.h"
#include "../../../../disco/plugin/fd_plugin.h"
#include "../../../../ballet/base58/fd_base58.h"
#include "../../../../ballet/http/fd_http_server.h"

#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <poll.h>
#include <stdio.h>

#if FD_HAS_ZSTD
#include <zstd.h>
#endif

FD_IMPORT_BINARY( firedancer_svg, "book/public/fire.svg" );

#define FD_HTTP_SERVER_GUI_MAX_CONNS 1024
Expand Down Expand Up @@ -177,12 +178,12 @@ gui_http_request( fd_http_server_request_t const * request ) {
!strcmp( request->path, "/leaderSchedule" ) ||
!strcmp( request->path, "/gossip" );

for( ulong i=0UL; i<sizeof(STATIC_FILES)/sizeof(STATIC_FILES[0]); i++ ) {
if( !strcmp( request->path, STATIC_FILES[ i ].name ) ||
(!strcmp( STATIC_FILES[ i ].name, "/index.html" ) && is_vite_page) ) {
for( fd_http_static_file_t * f = STATIC_FILES; f->name; f++ ) {
if( !strcmp( request->path, f->name ) ||
(!strcmp( f->name, "/index.html" ) && is_vite_page) ) {
char const * content_type = NULL;

char const * ext = strrchr( STATIC_FILES[ i ].name, '.' );
char const * ext = strrchr( f->name, '.' );
if( FD_LIKELY( ext ) ) {
if( !strcmp( ext, ".html" ) ) content_type = "text/html; charset=utf-8";
else if( !strcmp( ext, ".css" ) ) content_type = "text/css";
Expand All @@ -195,19 +196,19 @@ gui_http_request( fd_http_server_request_t const * request ) {
char const * cache_control = NULL;
if( FD_LIKELY( !strncmp( request->path, "/assets", 7 ) ) ) cache_control = "public, max-age=31536000, immutable";

const uchar * data = STATIC_FILES[ i ].data;
ulong data_len = *(STATIC_FILES[ i ].data_len);
const uchar * data = f->data;
ulong data_len = *(f->data_len);

int accepts_zstd = 0;
if( FD_LIKELY( request->headers.accept_encoding ) ) {
accepts_zstd = !!strstr( request->headers.accept_encoding, "zstd" );
}

char const * content_encoding = NULL;
if( FD_LIKELY( accepts_zstd && STATIC_FILES[ i ].zstd_data ) ) {
if( FD_LIKELY( accepts_zstd && f->zstd_data ) ) {
content_encoding = "zstd";
data = STATIC_FILES[ i ].zstd_data;
data_len = *(STATIC_FILES[ i ].zstd_data_len);
data = f->zstd_data;
data_len = f->zstd_data_len;
}

return (fd_http_server_response_t){
Expand Down Expand Up @@ -268,6 +269,30 @@ privileged_init( fd_topo_t * topo,
FD_LOG_ERR(( "identity_key_path not set" ));

ctx->identity_key = fd_keyload_load( tile->gui.identity_key_path, /* pubkey only: */ 1 );

# if FD_HAS_ZSTD
/* zstd compress files */
for( fd_http_static_file_t * f = STATIC_FILES; f->name; f++ ) {
char const * ext = strrchr( f->name, '.' );
if( !ext ) continue;
if( !strcmp( ext, ".html" ) ||
!strcmp( ext, ".css" ) ||
!strcmp( ext, ".js" ) ||
!strcmp( ext, ".svg" ) ) {}
else continue;

ulong zstd_bufsz = *f->data_len;
uchar * zstd_buf = malloc( zstd_bufsz );
if( FD_UNLIKELY( !zstd_buf ) ) FD_LOG_ERR(( "Out of memory" ));
ulong zstd_sz = ZSTD_compress( zstd_buf, zstd_bufsz, f->data, *f->data_len, 19 );
if( ZSTD_isError( zstd_sz ) ) {
free( zstd_buf );
continue;
}
f->zstd_data = zstd_buf;
f->zstd_data_len = zstd_sz;
}
# endif /* FD_HAS_ZSTD */
}

static void
Expand Down
62 changes: 17 additions & 45 deletions src/app/fdctl/run/tiles/generated/http_import_dist.c
Original file line number Diff line number Diff line change
@@ -1,101 +1,73 @@
/* THIS FILE WAS GENERATED BY make frontend. DO NOT EDIT BY HAND! */
#include "http_import_dist.h"

FD_IMPORT_BINARY( file0_zstd, "src/app/fdctl/dist/assets/firedancer_logo-CrgwxzPk.svg.zstd" );
FD_IMPORT_BINARY( file0, "src/app/fdctl/dist/assets/firedancer_logo-CrgwxzPk.svg" );
FD_IMPORT_BINARY( file1_zstd, "src/app/fdctl/dist/assets/firedancer-D_J0EzUc.svg.zstd" );
FD_IMPORT_BINARY( file1, "src/app/fdctl/dist/assets/firedancer-D_J0EzUc.svg" );
FD_IMPORT_BINARY( file2, "src/app/fdctl/dist/assets/inter-tight-latin-400-normal-BW_APOAv.woff" );
FD_IMPORT_BINARY( file3_zstd, "src/app/fdctl/dist/assets/privateYou-DxC3xn7b.svg.zstd" );
FD_IMPORT_BINARY( file3, "src/app/fdctl/dist/assets/privateYou-DxC3xn7b.svg" );
FD_IMPORT_BINARY( file4, "src/app/fdctl/dist/assets/inter-tight-latin-400-normal-CjmW70MP.woff2" );
FD_IMPORT_BINARY( file5_zstd, "src/app/fdctl/dist/assets/index-Dz6VwGqc.css.zstd" );
FD_IMPORT_BINARY( file0, "src/app/fdctl/dist/assets/firedancer-D_J0EzUc.svg" );
FD_IMPORT_BINARY( file1, "src/app/fdctl/dist/assets/firedancer_logo-CrgwxzPk.svg" );
FD_IMPORT_BINARY( file2, "src/app/fdctl/dist/assets/index-B5qDGMhj.css" );
FD_IMPORT_BINARY( file3, "src/app/fdctl/dist/assets/index-DhI9vJrW.js" );
FD_IMPORT_BINARY( file4, "src/app/fdctl/dist/assets/index-DL5ZAE5v.js" );
FD_IMPORT_BINARY( file5, "src/app/fdctl/dist/assets/index-Dz6VwGqc.css" );
FD_IMPORT_BINARY( file6_zstd, "src/app/fdctl/dist/assets/index-DL5ZAE5v.js.zstd" );
FD_IMPORT_BINARY( file6, "src/app/fdctl/dist/assets/index-DL5ZAE5v.js" );
FD_IMPORT_BINARY( file7_zstd, "src/app/fdctl/dist/assets/index-B5qDGMhj.css.zstd" );
FD_IMPORT_BINARY( file7, "src/app/fdctl/dist/assets/index-B5qDGMhj.css" );
FD_IMPORT_BINARY( file8_zstd, "src/app/fdctl/dist/assets/index-DhI9vJrW.js.zstd" );
FD_IMPORT_BINARY( file8, "src/app/fdctl/dist/assets/index-DhI9vJrW.js" );
FD_IMPORT_BINARY( file6, "src/app/fdctl/dist/assets/inter-tight-latin-400-normal-BW_APOAv.woff" );
FD_IMPORT_BINARY( file7, "src/app/fdctl/dist/assets/inter-tight-latin-400-normal-CjmW70MP.woff2" );
FD_IMPORT_BINARY( file8, "src/app/fdctl/dist/assets/privateYou-DxC3xn7b.svg" );
FD_IMPORT_BINARY( file9, "src/app/fdctl/dist/index.html" );
FD_IMPORT_BINARY( file10, "src/app/fdctl/dist/LICENSE_DEPENDENCIES" );

fd_http_static_file_t STATIC_FILES[] = {
{
.name = "/assets/firedancer_logo-CrgwxzPk.svg",
.name = "/assets/firedancer-D_J0EzUc.svg",
.data = file0,
.data_len = &file0_sz,
.zstd_data = file0_zstd,
.zstd_data_len = &file0_zstd_sz
},
{
.name = "/assets/firedancer-D_J0EzUc.svg",
.name = "/assets/firedancer_logo-CrgwxzPk.svg",
.data = file1,
.data_len = &file1_sz,
.zstd_data = file1_zstd,
.zstd_data_len = &file1_zstd_sz
},
{
.name = "/assets/inter-tight-latin-400-normal-BW_APOAv.woff",
.name = "/assets/index-B5qDGMhj.css",
.data = file2,
.data_len = &file2_sz,
.zstd_data = NULL,
.zstd_data_len = 0UL
},
{
.name = "/assets/privateYou-DxC3xn7b.svg",
.name = "/assets/index-DhI9vJrW.js",
.data = file3,
.data_len = &file3_sz,
.zstd_data = file3_zstd,
.zstd_data_len = &file3_zstd_sz
},
{
.name = "/assets/inter-tight-latin-400-normal-CjmW70MP.woff2",
.name = "/assets/index-DL5ZAE5v.js",
.data = file4,
.data_len = &file4_sz,
.zstd_data = NULL,
.zstd_data_len = 0UL
},
{
.name = "/assets/index-Dz6VwGqc.css",
.data = file5,
.data_len = &file5_sz,
.zstd_data = file5_zstd,
.zstd_data_len = &file5_zstd_sz
},
{
.name = "/assets/index-DL5ZAE5v.js",
.name = "/assets/inter-tight-latin-400-normal-BW_APOAv.woff",
.data = file6,
.data_len = &file6_sz,
.zstd_data = file6_zstd,
.zstd_data_len = &file6_zstd_sz
},
{
.name = "/assets/index-B5qDGMhj.css",
.name = "/assets/inter-tight-latin-400-normal-CjmW70MP.woff2",
.data = file7,
.data_len = &file7_sz,
.zstd_data = file7_zstd,
.zstd_data_len = &file7_zstd_sz
},
{
.name = "/assets/index-DhI9vJrW.js",
.name = "/assets/privateYou-DxC3xn7b.svg",
.data = file8,
.data_len = &file8_sz,
.zstd_data = file8_zstd,
.zstd_data_len = &file8_zstd_sz
},
{
.name = "/index.html",
.data = file9,
.data_len = &file9_sz,
.zstd_data = NULL,
.zstd_data_len = 0UL
},
{
.name = "/LICENSE_DEPENDENCIES",
.data = file10,
.data_len = &file10_sz,
.zstd_data = NULL,
.zstd_data_len = 0UL
},
{0}
};
8 changes: 3 additions & 5 deletions src/app/fdctl/run/tiles/generated/http_import_dist.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/* THIS FILE WAS GENERATED BY make frontend. DO NOT EDIT BY HAND! */
#ifndef HEADER_fd_src_app_fdctl_run_tiles_generated_http_import_dist_h
#define HEADER_fd_src_app_fdctl_run_tiles_generated_http_import_dist_h

#include "../../../../../util/fd_util.h"


struct fd_http_static_file {
char const * name;
char const * name;
uchar const * data;
ulong const * data_len;
uchar const * zstd_data;
ulong const * zstd_data_len;
ulong zstd_data_len;
};

typedef struct fd_http_static_file fd_http_static_file_t;

extern fd_http_static_file_t STATIC_FILES[11];
extern fd_http_static_file_t STATIC_FILES[]; /* null terminated */

#endif

0 comments on commit 881a2ec

Please sign in to comment.