Browse Source

Merge branch 'rc'

pull/16827/head
Viacheslav Klimov 3 weeks ago
parent
commit
4f26aa074c
Failed to extract signature
  1. 2
      application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java
  2. 36
      msa/web-report/chromium.js
  3. 13
      msa/web-report/docker/Dockerfile
  4. 2
      msa/web-report/docker/start-web-report.sh
  5. 147
      msa/web-report/install.js
  6. 1
      msa/web-report/package.json
  7. 64
      msa/web-report/pom.xml
  8. 19
      msa/web-report/sbom-check.js
  9. 3
      msa/web-report/server.ts
  10. 9
      msa/web-report/yarn.lock
  11. 2
      tools/src/main/python/license-headers/curations.json

2
application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java

@ -467,6 +467,7 @@ class DefaultIotHubServiceTest {
profile.setDefaultDashboardId(dashboard.getId());
Integration integration = new Integration(new IntegrationId(UUID.randomUUID()));
Converter converter = new Converter(new ConverterId(UUID.randomUUID()));
converter.setTenantId(tenantId);
// The profile and the integration listed first: in reverse order of creation, the dashboard would go before the
// profile that refers to it, and the converter before the integration that uses it.
IotHubInstalledItem deleted = devicePackage(profile.getId(), dashboard.getId(), integration.getId(), converter.getId());
@ -604,6 +605,7 @@ class DefaultIotHubServiceTest {
mockTenant();
IntegrationId integrationId = new IntegrationId(UUID.randomUUID());
Converter converter = new Converter(new ConverterId(UUID.randomUUID()));
converter.setTenantId(tenantId);
when(converterService.findConverterById(tenantId, converter.getId())).thenReturn(converter);
IotHubInstalledItem deleted = devicePackage(converter.getId(), integrationId);
// The converter and the integration steps shared the name: the integration's state replaced the converter's

36
msa/web-report/chromium.js

@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
// The Chromium builds shipped with the packages. They must be the Chromium release that playwright-core is released with,
// which install.js checks, so a Playwright upgrade needs new builds here. The Docker image has the chromium package of
// Debian instead: see docker/Dockerfile.
//
// The Chromium project publishes builds of the main branch only, so these are the builds from where the release was
// branched off, without the fixes made on the release branch later. The Debian package of the image has those fixes.
//
// To update after a Playwright upgrade, for the version that the error of install.js names:
// 1. Find where the release was branched off: chromium_main_branch_position in
// https://chromiumdash.appspot.com/fetch_version?version=<version>
// 2. For Linux_x64 and for Win_x64, take the highest snapshot build that is not above that position. Builds are listed by
// the start of their number, so shorten the start until one appears:
// https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o?delimiter=/&fields=prefixes&prefix=Linux_x64/<start of the position>
// 3. Set the version (the release from the error, ending in .0) and the two paths, and build the module. It fails with
// the SHA-256 of an archive: put it in the sha256 of that platform and build again, until both pass.
// install.js also fails if an unpacked build is not the version set here.
module.exports = {
// The packages: snapshot builds of the open source code, published by the Chromium project.
// exclude: glob patterns of the files that are not packaged
// strip: glob patterns of the executables to strip of their symbols, when GNU strip is installed
snapshot: {
version: '156.0.8078.0',
baseUrl: 'https://commondatastorage.googleapis.com/chromium-browser-snapshots',
// The .pak.info files, 70 MB, are left from the build of the translations; the browser does not read them
linux: { path: 'Linux_x64/1706520/chrome-linux.zip', sha256: '6b62846a868ea3ee675f77600790877a428dfb2428c940f8eff99db1038f9815',
exclude: ['locales/*.pak.info'],
// The Linux builds come with their symbols, 180 MB
strip: ['chrome', 'chrome_crashpad_handler', 'chrome_sandbox', '*.so*'] },
// interactive_ui_tests.exe is a test program of 348 MB that the service does not need
windows: { path: 'Win_x64/1706509/chrome-win.zip', sha256: '6bdfecb33dbfa7159e5666798bdc28c76347bef913573e899cb43930b78d26cc',
exclude: ['interactive_ui_tests.exe'] }
}
};

13
msa/web-report/docker/Dockerfile

@ -10,7 +10,8 @@ ARG DEBIAN_FRONTEND=noninteractive
ENV NODE_ENV production
ENV DOCKER_MODE true
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
# The browser is the chromium package of Debian, installed below
ENV CHROME_EXECUTABLE=/usr/bin/chromium
COPY start-web-report.sh /tmp/
@ -26,17 +27,13 @@ COPY src/config ./config
COPY src/inspectorShim.js src/server.js ./
RUN apt-get update \
&& apt-get install -yq --no-install-recommends fonts-noto-cjk-extra fonts-roboto fonts-noto-color-emoji fonts-unifont libfreetype6 xfonts-scalable fonts-liberation \
fonts-ipafont-gothic fonts-wqy-zenhei fonts-tlwg-loma-otf fonts-freefont-ttf fontconfig libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 \
libcairo2 libcups2 libdbus-1-3 libdrm2 libgbm1 libglib2.0-0 libnspr4 libnss3 libpango-1.0-0 libwayland-client0 libx11-6 libxcb1 libxcomposite1 \
libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 \
&& apt-get install -yq --no-install-recommends chromium fontconfig fonts-noto-cjk-extra fonts-roboto fonts-noto-color-emoji fonts-unifont \
xfonts-scalable fonts-liberation fonts-ipafont-gothic fonts-wqy-zenhei fonts-tlwg-loma-otf fonts-freefont-ttf \
&& rm -rf /var/lib/apt/lists/* \
&& chmod a+x /tmp/*.sh \
&& mv /tmp/start-web-report.sh /usr/bin \
&& chown -R node:node ${pkg.installFolder} \
&& mkdir /ms-playwright \
&& yarn install --production --non-interactive --network-concurrency 4 --network-timeout 100000 --mutex network && yarn cache clean --all \
&& chmod -R 777 /ms-playwright
&& yarn install --production --non-interactive --network-concurrency 4 --network-timeout 100000 --mutex network && yarn cache clean --all
USER node

2
msa/web-report/docker/start-web-report.sh

@ -14,7 +14,5 @@ source "${CONF_FOLDER}/${configfile}"
cd ${pkg.installFolder}
export CHROME_EXECUTABLE=$(node -e "console.log(require('playwright-chromium').chromium.executablePath());")
# This will forward this PID 1 to the node.js and forward SIGTERM for graceful shutdown as well
exec node server.js

147
msa/web-report/install.js

@ -1,46 +1,149 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
const fs = require('fs');
const fse = require('fs-extra');
const path = require('path');
const { execFileSync } = require('child_process');
const crypto = require('crypto');
const { execFile, execFileSync } = require('child_process');
const { promisify } = require('util');
const { Transform } = require('stream');
const { pipeline } = require('stream/promises');
// The helpers that Playwright downloads its browsers with: httpRequest follows HTTPS_PROXY and redirects, extractZip needs no unzip tool
const { httpRequest, extractZip } = require('playwright-core/lib/coreBundle').utils;
const { snapshot } = require('./chromium');
const DOWNLOAD_ATTEMPTS = 3;
// Chromium builds packaged with the service, downloaded by the Playwright CLI as if it ran on the target platform.
const PLATFORMS = {
linux: { hostPlatform: 'ubuntu24.04-x64', downloadDir: 'chromiumLinux', chromeDir: 'chrome-linux64', binary: 'tb-web-report', pkgOutput: 'thingsboard-web-report-linux' },
windows: { hostPlatform: 'win64', downloadDir: 'chromiumWin', chromeDir: 'chrome-win64', binary: 'tb-web-report.exe', pkgOutput: 'thingsboard-web-report-win.exe' }
linux: {
...snapshot.linux, binary: 'tb-web-report', pkgOutput: 'thingsboard-web-report-linux',
// The version is written into the executable
hasVersion: dir => fileContains(path.join(dir, 'chrome'), snapshot.version)
},
windows: {
...snapshot.windows, binary: 'tb-web-report.exe', pkgOutput: 'thingsboard-web-report-win.exe',
hasVersion: dir => fse.pathExists(path.join(dir, `${snapshot.version}.manifest`))
}
};
(async() => {
for (const [targetDir, platform] of Object.entries(PLATFORMS)) {
const downloadDir = path.join(projectRoot(), 'target', platform.downloadDir);
installChromium(platform.hostPlatform, downloadDir);
const chromiumDir = path.join(targetPackageDir(targetDir), 'chromium');
await fse.emptyDir(chromiumDir);
await fse.copy(path.join(downloadDir, chromiumRevisionDir(), platform.chromeDir), chromiumDir);
checkPlaywrightVersion();
await Promise.all(Object.entries(PLATFORMS).map(async ([targetDir, platform]) => {
await installChromium(platform, path.join(projectRoot(), 'target', 'chromium-' + targetDir),
path.join(targetPackageDir(targetDir), 'chromium'));
await fse.move(path.join(projectRoot(), 'target', platform.pkgOutput),
path.join(targetPackageDir(targetDir), 'bin', platform.binary),
{overwrite: true});
}
}));
})().catch(e => {
console.error(e);
process.exit(1);
});
function installChromium(hostPlatform, downloadDir) {
execFileSync(process.execPath, [path.join(path.dirname(require.resolve('playwright-core/package.json')), 'cli.js'), 'install', '--no-shell', 'chromium'], {
stdio: 'inherit',
env: {
...process.env,
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE: hostPlatform,
PLAYWRIGHT_BROWSERS_PATH: downloadDir,
PLAYWRIGHT_SKIP_BROWSER_GC: '1'
function checkPlaywrightVersion() {
const browsers = fse.readJsonSync(path.join(path.dirname(require.resolve('playwright-core/package.json')), 'browsers.json')).browsers;
const chromium = browsers.find(browser => browser.name === 'chromium');
if (!chromium) {
throw new Error('playwright-core/browsers.json does not list chromium');
}
// The release is the first three numbers; the last one counts the fixes on its branch and differs between builds
const build = version => version.split('.').slice(0, 3).join('.');
if (build(chromium.browserVersion) !== build(snapshot.version)) {
throw new Error(`playwright-core expects Chromium ${chromium.browserVersion}, the snapshot build in chromium.js is ${snapshot.version}`);
}
}
async function installChromium(platform, downloadDir, chromiumDir) {
await fse.emptyDir(downloadDir);
const archive = path.join(downloadDir, 'chromium.zip');
await download(`${snapshot.baseUrl}/${platform.path}`, archive, platform.sha256);
await extractZip(archive, { dir: downloadDir });
const unpacked = path.join(downloadDir, path.basename(platform.path, '.zip'));
for await (const excluded of fs.promises.glob(platform.exclude || [], { cwd: unpacked })) {
await fse.remove(path.join(unpacked, excluded));
}
if (platform.strip) {
await stripExecutables(unpacked, platform.strip);
}
if (!await platform.hasVersion(unpacked)) {
throw new Error(`${platform.path} is not Chromium ${snapshot.version}; check the build number in chromium.js`);
}
await fse.move(unpacked, chromiumDir, { overwrite: true });
await fse.remove(downloadDir);
}
// Fails unless the SHA-256 of the downloaded file is the expected one. Tries again when the connection or the server
// fails, but not for an answer such as 404, which would be the same again.
async function download(url, file, sha256) {
let actual;
for (let attempt = 1; actual === undefined; attempt++) {
try {
actual = await downloadOnce(url, file);
} catch (e) {
if (e.statusCode < 500 || attempt === DOWNLOAD_ATTEMPTS) {
throw e;
}
console.warn(`${e.message}; trying again`);
}
}
if (actual !== sha256) {
throw new Error(`${url} has SHA-256 ${actual}, expected ${sha256}`);
}
}
// Writes the file while it is downloaded, and gives its SHA-256
function downloadOnce(url, file) {
return new Promise((resolve, reject) => {
const fail = (reason, statusCode) => reject(Object.assign(new Error(`Cannot download ${url}: ${reason}`), { statusCode }));
httpRequest({ url, socketTimeout: 60000 }, response => {
if (response.statusCode !== 200) {
response.resume();
fail(`HTTP ${response.statusCode}`, response.statusCode);
return;
}
const hash = crypto.createHash('sha256');
const hashing = new Transform({
transform(chunk, encoding, callback) {
hash.update(chunk);
callback(null, chunk);
}
});
pipeline(response, hashing, fs.createWriteStream(file)).then(() => resolve(hash.digest('hex')), e => fail(e.message));
}, e => fail(e.message));
});
}
function chromiumRevisionDir() {
const browsers = fse.readJsonSync(path.join(projectRoot(), 'node_modules', 'playwright-core', 'browsers.json')).browsers;
return 'chromium-' + browsers.find(b => b.name === 'chromium').revision;
// Strips the symbols with GNU strip, which reads the Linux executables on any build machine. Without it, as on macOS
// or where binutils is not installed, the executables are packaged as they are.
async function stripExecutables(dir, patterns) {
if (!hasGnuStrip()) {
console.warn('strip not found, Linux Chromium left unstripped (+~180 MB); install GNU binutils to strip it');
return;
}
for await (const file of fs.promises.glob(patterns, { cwd: dir })) {
await promisify(execFile)('strip', ['--strip-unneeded', path.join(dir, file)]);
}
}
function hasGnuStrip() {
try {
return execFileSync('strip', ['--version'], { encoding: 'utf8' }).includes('GNU strip');
} catch {
return false;
}
}
async function fileContains(file, text) {
const needle = Buffer.from(text);
let tail = Buffer.alloc(0);
for await (const chunk of fs.createReadStream(file)) {
const data = Buffer.concat([tail, chunk]);
if (data.includes(needle)) {
return true;
}
tail = data.subarray(data.length - needle.length + 1);
}
return false;
}
function projectRoot() {

1
msa/web-report/package.json

@ -18,7 +18,6 @@
"config": "~4.4.2",
"express": "~5.3.0",
"js-yaml": "^4.3.2",
"playwright-chromium": "~1.64.1",
"playwright-core": "~1.64.1",
"winston": "~3.19.0",
"winston-daily-rotate-file": "~5.0.0"

64
msa/web-report/pom.xml

@ -321,15 +321,16 @@
</component>
<component>
<type>application</type>
<name>chrome-for-testing</name>
<name>chromium</name>
<version>${chromium.version}</version>
<description>Chrome for Testing build downloaded by Playwright, used to render reports.</description>
<purl>pkg:generic/google/chrome-for-testing@${chromium.version}?os=linux</purl>
<description>Chromium snapshot build of the Chromium project, used to render reports.</description>
<purl>pkg:generic/chromium/chromium@${chromium.version}?os=linux</purl>
<cpe>cpe:2.3:a:google:chrome:${chromium.version}:*:*:*:*:*:*:*</cpe>
<license>BSD-3-Clause</license>
<supplier>
<name>Google LLC</name>
<name>The Chromium Authors</name>
<urls>
<url>https://googlechromelabs.github.io/chrome-for-testing/</url>
<url>https://www.chromium.org</url>
</urls>
</supplier>
<file>${pkg.linux.dist}/chromium/chrome</file>
@ -340,15 +341,16 @@
</component>
<component>
<type>application</type>
<name>chrome-for-testing</name>
<name>chromium</name>
<version>${chromium.version}</version>
<description>Chrome for Testing build downloaded by Playwright, used to render reports.</description>
<purl>pkg:generic/google/chrome-for-testing@${chromium.version}?os=windows</purl>
<description>Chromium snapshot build of the Chromium project, used to render reports.</description>
<purl>pkg:generic/chromium/chromium@${chromium.version}?os=windows</purl>
<cpe>cpe:2.3:a:google:chrome:${chromium.version}:*:*:*:*:*:*:*</cpe>
<license>BSD-3-Clause</license>
<supplier>
<name>Google LLC</name>
<name>The Chromium Authors</name>
<urls>
<url>https://googlechromelabs.github.io/chrome-for-testing/</url>
<url>https://www.chromium.org</url>
</urls>
</supplier>
<file>${pkg.win.dist}/chromium/chrome.exe</file>
@ -367,48 +369,6 @@
<sbom>${project.build.directory}/sbom/tb-web-report.cdx.json</sbom>
<installDir>${pkg.installFolder}</installDir>
</component>
<component>
<type>application</type>
<name>chrome-for-testing</name>
<version>${chromium.version}</version>
<description>Chrome for Testing build downloaded by Playwright to /ms-playwright, used to render reports.</description>
<purl>pkg:generic/google/chrome-for-testing@${chromium.version}?os=linux&amp;arch=@{architecture}</purl>
<cpe>cpe:2.3:a:google:chrome:${chromium.version}:*:*:*:*:*:*:*</cpe>
<supplier>
<name>Google LLC</name>
<urls>
<url>https://googlechromelabs.github.io/chrome-for-testing/</url>
</urls>
</supplier>
</component>
<component>
<type>application</type>
<name>chrome-headless-shell</name>
<version>${chromium-headless-shell.version}</version>
<description>Chrome Headless Shell build downloaded by Playwright to /ms-playwright.</description>
<purl>pkg:generic/google/chrome-headless-shell@${chromium-headless-shell.version}?os=linux&amp;arch=@{architecture}</purl>
<cpe>cpe:2.3:a:google:chrome:${chromium-headless-shell.version}:*:*:*:*:*:*:*</cpe>
<supplier>
<name>Google LLC</name>
<urls>
<url>https://googlechromelabs.github.io/chrome-for-testing/</url>
</urls>
</supplier>
</component>
<component>
<type>application</type>
<name>playwright-ffmpeg</name>
<version>${ffmpeg.revision}</version>
<description>FFmpeg build by Playwright (revision ${ffmpeg.revision}), downloaded to /ms-playwright.</description>
<purl>pkg:generic/microsoft/playwright-ffmpeg@${ffmpeg.revision}?os=linux&amp;arch=@{architecture}</purl>
<license>LGPL-2.1-or-later</license>
<supplier>
<name>Microsoft Corporation</name>
<urls>
<url>https://playwright.dev</url>
</urls>
</supplier>
</component>
</components>
</configuration>
</execution>

19
msa/web-report/sbom-check.js

@ -12,7 +12,7 @@ const BASE_BINARY = /fetched-v(\d+\.\d+\.\d+)-/;
(() => {
const listed = listedPackages(JSON.parse(fs.readFileSync(SBOM_FILE, 'utf8')));
const versions = playwrightVersions();
const versions = { 'chromium.version': require('./chromium').snapshot.version };
for (const [os, log] of Object.entries(PKG_LOGS)) {
const output = fs.readFileSync(path.join(TARGET_DIR, log), 'utf8').replace(/\x1b\[[0-9;]*m/g, '');
const baseBinary = BASE_BINARY.exec(output);
@ -74,20 +74,3 @@ function packageDir(file) {
}
return parts.slice(0, index + (scoped ? 3 : 2)).join(path.sep);
}
function playwrightVersions() {
const browsers = JSON.parse(fs.readFileSync(path.join(path.dirname(require.resolve('playwright-core/package.json')), 'browsers.json'), 'utf8')).browsers;
const browser = name => {
const found = browsers.find(candidate => candidate.name === name);
if (!found) {
throw new Error(`playwright-core/browsers.json does not list ${name}`);
}
return found;
};
return {
'chromium.version': browser('chromium').browserVersion,
'chromium-headless-shell.version': browser('chromium-headless-shell').browserVersion,
'ffmpeg.revision': browser('ffmpeg').revision
};
}

3
msa/web-report/server.ts

@ -5,8 +5,7 @@ import express from 'express';
import bodyParser from 'body-parser';
import config from 'config';
import { _logger } from './config/logger';
import { chromium } from 'playwright-chromium';
import { Browser, LaunchOptions } from 'playwright-core';
import { Browser, chromium, LaunchOptions } from 'playwright-core';
import { route } from './api/routes/tbWebReportRoutes';
import { TbWebReportPageQueue } from './api/controllers/tbWebReportPageQueue';

9
msa/web-report/yarn.lock

@ -1307,14 +1307,7 @@ picomatch@^4.0.2, picomatch@^4.0.4:
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-4.0.7.tgz#6313360034ccb36b3dc61ecbdff78121f90fe21f"
integrity sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==
playwright-chromium@~1.64.1:
version "1.64.1"
resolved "https://registry.yarnpkg.com/playwright-chromium/-/playwright-chromium-1.64.1.tgz#81aec8925514050c0ac5bc08fa231ed189ab0e86"
integrity sha512-lvAzvvIRtbHaeLwl7XoUkhSNuWHKshbrYv2sjqYgLQS4SsTTwgSTlg9BwU5LeGxYkHxBXTnKtNDEQdZSOj/01g==
dependencies:
playwright-core "1.64.1"
playwright-core@1.64.1, playwright-core@~1.64.1:
playwright-core@~1.64.1:
version "1.64.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.64.1.tgz#ca9ec82d7da6ced1b2326ec59ef097aaa9a29f94"
integrity sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==

2
tools/src/main/python/license-headers/curations.json

@ -1199,7 +1199,7 @@
"path": "msa/web-report/pom.xml",
"header": "busl",
"reason": "Build descriptor of the PE-only web-report module; CE has no web-report module. The only CE version is an empty file (blob e69de29bb2d) added by stray commit 2b1c5d92f3a, pushed to fix/maven-node-lts-4.3 after #16417 merged and carried into lts-4.4 via #16419; it never reached CE lts-4.3 and is not the origin of this file.",
"contentHash": "sha256:48ee3956937386c95ebb2b95a4981506203c00ce276aa6003fecfc0ddaf04218"
"contentHash": "sha256:9ddddeec7898c7232abc7b16c696fdad4f3825d15d3810369f621609f2678f65"
},
{
"path": "report/src/main/conf/logback.xml",

Loading…
Cancel
Save