From ca429ab8e7f1a4448c5e6de3c72cbedc30d90e69 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 6 Mar 2024 10:11:18 +0100 Subject: [PATCH] Fix CDN task assets discovery (#177985) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Plugin static assets were not being included in the CDN bundle due to the task looking in `/assets` only. This fix adds `/public/assets`. ## Output structure
tree ``` ❯ tree -dL 3 . . └── ├── bundles │   ├── core │   ├── kbn-monaco │   ├── kbn-ui-shared-deps-npm │   ├── kbn-ui-shared-deps-src │   └── plugin ├── plugins │   ├── apm │   ├── cloudDefend │   ├── cloudSecurityPosture │   ├── customIntegrations │   ├── dashboard │   ├── dataViewFieldEditor │   ├── discover │   ├── enterpriseSearch │   ├── fleet │   ├── globalSearchBar │   ├── home │   ├── indexManagement │   ├── kibanaOverview │   ├── kibanaReact │   ├── lens │   ├── maps │   ├── observability │   ├── observabilityAIAssistant │   ├── observabilityOnboarding │   ├── osquery │   ├── remoteClusters │   ├── serverlessSearch │   └── timelines └── ui ├── favicons └── fonts 35 directories ```
## Test 1. Build distributable using `node scripts/build.js` to get CDN assets 2. Untar `./target/kibana-8.14.0-SNAPSHOT-cdn-assets.tar.gz` 3. Add an entry to `/etc/hosts` to resolve to `127.0.0.1` 4. `cd` into the untarred folder and serve the assets, I used `npx http-server -p 1772 --cors --gzip --brotli` 5. Add `server.cdn.url: "http://my.cdn.test:1772"` to your Kibana config 6. Start Kibana and ES, see assets are loading for the home app from our "CDN" Screenshot 2024-03-05 at 11 14 45 --- src/dev/build/cli.ts | 1 + src/dev/build/tasks/create_cdn_assets_task.ts | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/dev/build/cli.ts b/src/dev/build/cli.ts index 9a967e1cc85c9..e9acd8245af02 100644 --- a/src/dev/build/cli.ts +++ b/src/dev/build/cli.ts @@ -43,6 +43,7 @@ if (showHelp) { --docker-cross-compile {dim Produce arm64 and amd64 Docker images} --docker-contexts {dim Only build the Docker build contexts} --skip-canvas-shareable-runtime {dim Don't build the Canvas shareable runtime} + --skip-cdn-assets {dim Don't build CDN assets} --skip-docker-ubi {dim Don't build the docker ubi image} --skip-docker-ubuntu {dim Don't build the docker ubuntu image} --skip-docker-fips {dim Don't build the docker fips image} diff --git a/src/dev/build/tasks/create_cdn_assets_task.ts b/src/dev/build/tasks/create_cdn_assets_task.ts index a9ec8beb0955c..2555795d50d80 100644 --- a/src/dev/build/tasks/create_cdn_assets_task.ts +++ b/src/dev/build/tasks/create_cdn_assets_task.ts @@ -38,16 +38,14 @@ export const CreateCdnAssets: Task = { const manifest = Jsonc.parse(readFileSync(path, 'utf8')) as any; if (manifest?.plugin?.id) { const pluginRoot = resolve(dirname(path)); - + // packages/core/apps/core-apps-server-internal/src/core_app.ts + const assetsSource = resolve(pluginRoot, 'public', 'assets'); + const assetsDest = resolve(assets, buildSha, 'plugins', manifest.plugin.id, 'assets'); try { - // packages/core/plugins/core-plugins-server-internal/src/plugins_service.ts - const assetsSource = resolve(pluginRoot, 'assets'); - const assetsDest = resolve('plugins', manifest.plugin.id, 'assets'); await access(assetsSource); await mkdirp(assetsDest); await copyAll(assetsSource, assetsDest); } catch (e) { - // assets are optional if (!(e.code === 'ENOENT' && e.syscall === 'access')) throw e; }