Skip to content

Commit

Permalink
Fix CDN task assets discovery (#177985)
Browse files Browse the repository at this point in the history
## Summary

Plugin static assets were not being included in the CDN bundle due to
the task looking in `<plugin_root>/assets` only. This fix adds
`<plugin_root>/public/assets`.

## Output structure

<details>

<summary>tree</summary>

```
❯ tree -dL 3 .
.
└── <hash>
    ├── 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
```

</details>


## 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"

<img width="1813" alt="Screenshot 2024-03-05 at 11 14 45"
src="https://github.com/elastic/kibana/assets/8155004/e322c02b-2d42-4adc-9767-3a5b276b7be4">
  • Loading branch information
jloleysens authored Mar 6, 2024
1 parent 9262d96 commit ca429ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/dev/build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 3 additions & 5 deletions src/dev/build/tasks/create_cdn_assets_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ca429ab

Please sign in to comment.