feat(generator): add local Linux package formats

Build local Linux clients once and package them as portable archives, Debian packages, RPMs, or Arch packages when the host toolchain supports the format. Keep artifact manifests and validation format-aware.

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow)
This commit is contained in:
UNITRONIX
2026-10-05 10:39:57 +02:00
parent e94d9a0c36
commit ecc77b784e
6 changed files with 269 additions and 37 deletions
+2 -2
View File
@@ -90,7 +90,7 @@ install_apt() {
libgl1-mesa-dev libx11-dev libxcursor-dev libxrandr-dev \
libxinerama-dev libxi-dev libxxf86vm-dev libxkbcommon-dev \
libwayland-dev libdecor-0-dev \
nsis dpkg-dev rpm fakeroot msitools p7zip-full \
nsis dpkg-dev rpm fakeroot msitools p7zip-full zstd \
libfuse2t64 \
mingw-w64 gcc-mingw-w64-x86-64
# Node.js: prefer existing install (NodeSource bundles npm; the Ubuntu npm
@@ -111,7 +111,7 @@ install_dnf() {
libXi-devel libXxf86vm-devel mesa-libGL-devel libxkbcommon-devel \
wayland-devel libdecor-devel \
mingw64-gcc mingw64-gcc-c++ \
nsis rpm-build dpkg fuse-libs msitools p7zip-full \
nsis rpm-build dpkg fuse-libs msitools p7zip-full zstd \
nodejs npm || true
}
@@ -24,7 +24,13 @@ const PLATFORMS = [
{ platform: 'windows', arch: 'x64', format: 'portable', label: 'Windows x64 portable (.zip + installer)' },
{ platform: 'windows', arch: 'arm64', format: 'portable', label: 'Windows ARM64 portable (.zip + installer)' },
{ platform: 'linux', arch: 'x64', format: 'portable', label: 'Linux x64 portable (.tar.gz)' },
{ platform: 'linux', arch: 'x64', format: 'deb', label: 'Debian/Ubuntu x64 package (.deb)' },
{ platform: 'linux', arch: 'x64', format: 'rpm', label: 'Fedora/RHEL/openSUSE x64 package (.rpm)' },
{ platform: 'linux', arch: 'x64', format: 'arch', label: 'Arch Linux x64 package (.pkg.tar.zst)' },
{ platform: 'linux', arch: 'arm64', format: 'portable', label: 'Linux ARM64 portable (.tar.gz)' },
{ platform: 'linux', arch: 'arm64', format: 'deb', label: 'Debian/Ubuntu ARM64 package (.deb)' },
{ platform: 'linux', arch: 'arm64', format: 'rpm', label: 'Fedora/RHEL/openSUSE ARM64 package (.rpm)' },
{ platform: 'linux', arch: 'arm64', format: 'arch', label: 'Arch Linux ARM64 package (.pkg.tar.zst)' },
{ platform: 'macos', arch: 'x64', format: 'portable', label: 'macOS Intel portable (.tar.gz)' },
{ platform: 'macos', arch: 'arm64', format: 'portable', label: 'macOS Apple Silicon portable (.tar.gz)' },
];
@@ -692,6 +692,7 @@ async function runGithubActionsBuild(request, requestPath, outputDir) {
generation_id: request.generationId,
config_b64: request.signed_config_b64,
client_commit: request.clientCommit || state.installedCommit,
targets_json: JSON.stringify(request.targets || []),
},
}
);
+27 -11
View File
@@ -648,15 +648,23 @@ async function _runOne(buildRow) {
}
}
function _findManifestArtifact(root, manifest, platform, arch) {
function _artifactExtension(platform, format) {
if (String(platform).toLowerCase() === 'windows') return '.zip';
if (format === 'deb') return '.deb';
if (format === 'rpm') return '.rpm';
if (format === 'arch') return '.pkg.tar.zst';
return '.tar.gz';
}
function _findManifestArtifact(root, manifest, platform, arch, format = 'portable') {
const providerArch = {
x64: 'x86_64',
amd64: 'x86_64',
arm64: 'aarch64',
}[String(arch).toLowerCase()] || String(arch).toLowerCase();
const target = `${String(platform).toLowerCase()}/${providerArch}`;
const target = `${String(platform).toLowerCase()}/${providerArch}/${format}`;
const assets = (manifest?.assets || []).filter((asset) => (
`${String(asset.platform || '').toLowerCase()}/${String(asset.arch || '').toLowerCase()}` === target
`${String(asset.platform || '').toLowerCase()}/${String(asset.arch || '').toLowerCase()}/${String(asset.format || 'portable').toLowerCase()}` === target
));
if (assets.length !== 1) {
throw new Error(`embedded_manifest_asset_target_count_invalid:${platform}/${arch}`);
@@ -664,7 +672,7 @@ function _findManifestArtifact(root, manifest, platform, arch) {
const assetName = assets[0].name;
const candidate = path.resolve(root, assetName);
const relative = path.relative(path.resolve(root), candidate);
const expectedExt = String(platform).toLowerCase() === 'windows' ? '.zip' : '.tar.gz';
const expectedExt = _artifactExtension(platform, format);
if (
!relative
|| relative.startsWith(`..${path.sep}`)
@@ -691,7 +699,7 @@ function _failedPlatformsForError(message, buildRow) {
: bundleService.PLATFORMS;
}
async function _assertEmbeddedArtifact(artifactPath) {
async function _assertEmbeddedArtifact(artifactPath, format = 'portable') {
if (artifactPath.endsWith('.zip')) {
const zip = new AdmZip(artifactPath);
for (const entry of zip.getEntries()) {
@@ -702,8 +710,15 @@ async function _assertEmbeddedArtifact(artifactPath) {
}
return;
}
const command = format === 'deb' ? 'dpkg-deb'
: format === 'rpm' ? 'rpm'
: 'tar';
const args = format === 'deb' ? ['-c', artifactPath]
: format === 'rpm' ? ['-qlp', artifactPath]
: format === 'arch' ? ['--zstd', '-tf', artifactPath]
: ['-tzf', artifactPath];
const listing = await new Promise((resolve, reject) => {
const child = spawn('tar', ['-tzf', artifactPath], {
const child = spawn(command, args, {
cwd: path.dirname(artifactPath),
stdio: ['ignore', 'pipe', 'pipe'],
windowsHide: true,
@@ -827,11 +842,11 @@ async function _runEmbeddedOne(buildRow) {
const manifest = await _validateEmbeddedManifest(result.outputDir, buildRow);
await fsp.mkdir(ARTIFACT_ROOT, { recursive: true });
const availableTargets = new Set((manifest.assets || []).map((asset) => (
`${asset.platform}/${asset.arch}`
`${asset.platform}/${asset.arch}/${asset.format || 'portable'}`
)));
const localProvider = manifest.builder === 'betterdesk-local';
for (const platform of buildPlatforms) {
const targetKey = `${platform.platform}/${platform.arch === 'x64' ? 'x86_64' : 'aarch64'}`;
const targetKey = `${platform.platform}/${platform.arch === 'x64' ? 'x86_64' : 'aarch64'}/${platform.format}`;
if (!availableTargets.has(targetKey)) {
if (!localProvider) {
throw new Error(`embedded_build_target_missing:${targetKey}`);
@@ -858,10 +873,11 @@ async function _runEmbeddedOne(buildRow) {
result.outputDir,
manifest,
platform.platform,
platform.arch
platform.arch,
platform.format
);
await _assertEmbeddedArtifact(sourceArtifact);
const ext = platform.platform === 'windows' ? 'zip' : 'tar.gz';
await _assertEmbeddedArtifact(sourceArtifact, platform.format);
const ext = _artifactExtension(platform.platform, platform.format).slice(1);
const artifactPath = path.join(
ARTIFACT_ROOT,
`betterdesk-support-${buildRow.branding_hash.slice(0, 12)}-${platform.platform}-${platform.arch}.${ext}`
+204 -24
View File
@@ -170,6 +170,29 @@ function providerArch(arch) {
return arch === 'x64' ? 'x86_64' : 'aarch64';
}
function commandAvailable(name) {
const candidates = [
...(process.env.PATH || '')
.split(path.delimiter)
.filter(Boolean)
.map((dir) => path.join(dir, name)),
`/usr/bin/${name}`,
`/usr/sbin/${name}`,
`/bin/${name}`,
`/usr/local/bin/${name}`,
];
return candidates.some((candidate) => fs.existsSync(candidate));
}
function linuxPackageFormats() {
if (process.platform !== 'linux') return [];
const formats = ['portable'];
if (commandAvailable('dpkg-deb')) formats.push('deb');
if (commandAvailable('rpmbuild')) formats.push('rpm');
if (commandAvailable('tar') && commandAvailable('zstd')) formats.push('arch');
return formats;
}
function localToolchainStatus() {
const missing = [];
if (!toolPath('cargo', process.env.BETTERDESK_CLIENT_CARGO)) missing.push('cargo');
@@ -180,21 +203,28 @@ function localToolchainStatus() {
} else if (!fs.existsSync(path.join(vcpkgRoot, process.platform === 'win32' ? 'vcpkg.exe' : 'vcpkg'))) {
missing.push('VCPKG_ROOT');
}
return { ready: missing.length === 0, missing };
return {
ready: missing.length === 0,
missing,
packageFormats: linuxPackageFormats(),
};
}
function getCapabilities() {
const host = hostTarget();
const toolchain = localToolchainStatus();
const formats = host.platform === 'linux'
? toolchain.packageFormats
: ['portable'];
return {
mode: 'local',
host,
toolchain,
targets: toolchain.ready ? [{
targets: toolchain.ready ? formats.map((format) => ({
platform: host.platform,
arch: host.arch,
format: 'portable',
}] : [],
format,
})) : [],
};
}
@@ -239,9 +269,140 @@ function assertNoExternalConfig(root) {
}
}
function packageVersion(request) {
const commit = String(request.clientCommit || '').toLowerCase();
return `0.0.0.${commit.slice(0, 12).replace(/[^a-f0-9]/g, '') || 'local'}`;
}
async function prepareLinuxBundle(source, target) {
const arch = providerArch(target.arch);
const targetName = `linux-${arch}-${target.format}`;
const stage = path.join(outputDir, 'stage', targetName);
await fsp.rm(stage, { recursive: true, force: true });
await fsp.mkdir(stage, { recursive: true });
await fsp.cp(source, path.join(stage, 'bundle'), { recursive: true });
assertNoExternalConfig(stage);
return { arch, targetName, stage };
}
async function packageLinuxDeb(request, target, bundle) {
const root = path.join(outputDir, 'packages', `${bundle.targetName}-deb`);
await fsp.rm(root, { recursive: true, force: true });
await fsp.mkdir(path.join(root, 'DEBIAN'), { recursive: true });
await fsp.mkdir(path.join(root, 'opt', 'betterdesk-support'), { recursive: true });
await fsp.cp(path.join(bundle.stage, 'bundle'), path.join(root, 'opt', 'betterdesk-support'), { recursive: true });
await fsp.mkdir(path.join(root, 'usr', 'bin'), { recursive: true });
await fsp.symlink('/opt/betterdesk-support/betterdesk', path.join(root, 'usr', 'bin', 'betterdesk'));
await fsp.writeFile(path.join(root, 'DEBIAN', 'control'), [
'Package: betterdesk-support',
`Version: ${packageVersion(request)}`,
`Architecture: ${target.arch === 'arm64' ? 'arm64' : 'amd64'}`,
'Section: net',
'Priority: optional',
'Maintainer: BetterDesk',
'Description: BetterDesk Support client',
' Embedded support client with signed server configuration.',
'',
].join('\n'));
const artifact = path.join(
outputDir,
`betterdesk-support-${request.generationId}-linux-${bundle.arch}.deb`
);
const result = await run('dpkg-deb', ['--build', root, artifact], { env: process.env });
if (result.code !== 0) throw new Error(`local_builder_deb_failed:${result.stderr.slice(-2000)}`);
return artifact;
}
async function packageLinuxRpm(request, target, bundle) {
const top = path.join(outputDir, 'packages', `${bundle.targetName}-rpm`);
const specDir = path.join(top, 'SPECS');
const sourceDirForRpm = path.join(top, 'SOURCES');
await fsp.rm(top, { recursive: true, force: true });
await fsp.mkdir(specDir, { recursive: true });
await fsp.mkdir(sourceDirForRpm, { recursive: true });
await fsp.cp(bundle.stage, path.join(sourceDirForRpm, 'bundle'), { recursive: true });
const version = packageVersion(request);
const spec = [
'Name: betterdesk-support',
`Version: ${version}`,
'Release: 1',
'Summary: BetterDesk Support client',
'License: AGPL-3.0',
`BuildArch: ${target.arch === 'arm64' ? 'aarch64' : 'x86_64'}`,
'%description',
'BetterDesk Support client with signed server configuration.',
'%prep',
'%build',
'%install',
'mkdir -p %{buildroot}/opt/betterdesk-support',
'cp -a %{_sourcedir}/bundle/bundle/. %{buildroot}/opt/betterdesk-support/',
'mkdir -p %{buildroot}/usr/bin',
'ln -s /opt/betterdesk-support/betterdesk %{buildroot}/usr/bin/betterdesk',
'%files',
'/opt/betterdesk-support',
'/usr/bin/betterdesk',
'%changelog',
'* Mon Oct 05 2026 BetterDesk <support@betterdesk.local> - 0.0.0-1',
'- Build signed BetterDesk Support client.',
'',
].join('\n');
const specPath = path.join(specDir, 'betterdesk-support.spec');
await fsp.writeFile(specPath, spec);
const result = await run('rpmbuild', [
'--define', `_topdir ${top}`,
'-bb',
specPath,
], { env: process.env });
if (result.code !== 0) throw new Error(`local_builder_rpm_failed:${result.stderr.slice(-2000)}`);
const rpmArch = target.arch === 'arm64' ? 'aarch64' : 'x86_64';
const artifact = path.join(
outputDir,
`betterdesk-support-${request.generationId}-linux-${bundle.arch}.rpm`
);
const built = path.join(top, 'RPMS', rpmArch, `betterdesk-support-${version}-1.${rpmArch}.rpm`);
if (!fs.existsSync(built)) throw new Error(`local_builder_rpm_output_missing:${built}`);
await fsp.rename(built, artifact);
return artifact;
}
async function packageLinuxArch(request, target, bundle) {
const root = path.join(outputDir, 'packages', `${bundle.targetName}-arch`);
await fsp.rm(root, { recursive: true, force: true });
await fsp.mkdir(path.join(root, 'opt', 'betterdesk-support'), { recursive: true });
await fsp.cp(
path.join(bundle.stage, 'bundle'),
path.join(root, 'opt', 'betterdesk-support'),
{ recursive: true }
);
await fsp.mkdir(path.join(root, 'usr', 'bin'), { recursive: true });
await fsp.symlink('/opt/betterdesk-support/betterdesk', path.join(root, 'usr', 'bin', 'betterdesk'));
const arch = target.arch === 'arm64' ? 'aarch64' : 'x86_64';
await fsp.writeFile(path.join(root, '.PKGINFO'), [
'pkgname = betterdesk-support',
'pkgbase = betterdesk-support',
'pkgver = 0.0.0-1',
'pkgdesc = BetterDesk Support client',
'url = https://betterdesk.eu',
'builddate = 1791158400',
'packager = BetterDesk',
`arch = ${arch}`,
'',
].join('\n'));
const artifact = path.join(
outputDir,
`betterdesk-support-${request.generationId}-linux-${bundle.arch}.pkg.tar.zst`
);
const result = await run('tar', ['--zstd', '-cf', artifact, '.'], {
cwd: root,
env: process.env,
});
if (result.code !== 0) throw new Error(`local_builder_arch_failed:${result.stderr.slice(-2000)}`);
return artifact;
}
async function packageTarget(request, target) {
const arch = providerArch(target.arch);
const targetName = `${target.platform}-${arch}`;
const targetName = `${target.platform}-${arch}-${target.format}`;
const stage = path.join(outputDir, 'stage', targetName);
await fsp.rm(stage, { recursive: true, force: true });
await fsp.mkdir(stage, { recursive: true });
@@ -271,15 +432,14 @@ async function packageTarget(request, target) {
let source;
if (target.platform === 'linux') {
source = path.join(
sourceDir,
'flutter',
'build',
'linux',
target.arch,
'release',
'bundle'
);
const linuxBundleCandidates = [
path.join(sourceDir, 'flutter', 'build', 'linux', target.arch, 'release', 'bundle'),
// BetterDesk-Client's build.py currently uses the Flutter x64
// directory name for Linux even when the native host is ARM64.
path.join(sourceDir, 'flutter', 'build', 'linux', 'x64', 'release', 'bundle'),
];
source = linuxBundleCandidates.find((candidate) => fs.existsSync(candidate))
|| linuxBundleCandidates[0];
} else {
source = path.join(
sourceDir,
@@ -293,6 +453,13 @@ async function packageTarget(request, target) {
);
}
if (!fs.existsSync(source)) throw new Error(`local_builder_output_missing:${source}`);
if (target.platform === 'linux' && target.format !== 'portable') {
const bundle = await prepareLinuxBundle(source, target);
if (target.format === 'deb') return packageLinuxDeb(request, target, bundle);
if (target.format === 'rpm') return packageLinuxRpm(request, target, bundle);
if (target.format === 'arch') return packageLinuxArch(request, target, bundle);
throw new Error(`local_builder_format_unsupported:${target.format}`);
}
await fsp.cp(source, path.join(stage, path.basename(source)), { recursive: true });
assertNoExternalConfig(stage);
const archivePath = path.join(
@@ -315,17 +482,26 @@ async function main() {
if (request.product_sku !== 'betterdesk-support' || !request.signed_config_b64) {
throw new Error('local_builder_support_payload_required');
}
if (!Array.isArray(request.targets) || request.targets.length !== 1) {
throw new Error('local_builder_single_target_required');
if (!Array.isArray(request.targets) || request.targets.length === 0) {
throw new Error('local_builder_targets_required');
}
const host = hostTarget();
const target = request.targets.find((candidate) => (
candidate.platform === host.platform && candidate.arch === host.arch
));
if (!target) {
const targets = request.targets
.filter((candidate) => (
candidate.platform === host.platform && candidate.arch === host.arch
))
.map((candidate) => ({ ...candidate, format: candidate.format || 'portable' }));
if (!targets.length) {
throw new Error(`local_builder_target_unsupported:${request.targets[0]?.platform || 'unknown'}/${request.targets[0]?.arch || 'unknown'}`);
}
const available = new Set(getCapabilities().targets.map((candidate) => (
`${candidate.platform}/${candidate.arch}/${candidate.format}`
)));
for (const target of targets) {
if (!available.has(`${target.platform}/${target.arch}/${target.format}`)) {
throw new Error(`local_builder_format_unsupported:${target.format || 'portable'}`);
}
}
await fsp.mkdir(outputDir, { recursive: true });
ensureBuildCapacity();
const toolchainEnv = buildEnvironment();
@@ -356,7 +532,10 @@ async function main() {
throw new Error(`local_builder_compile_failed:${build.stderr.slice(-4000)}`);
}
progress(78, 'packaging');
const artifact = await packageTarget(request, target);
const artifacts = [];
for (const target of targets) {
artifacts.push({ target, path: await packageTarget(request, target) });
}
progress(94, 'verifying');
const manifest = {
schema_version: 1,
@@ -364,13 +543,14 @@ async function main() {
generation_id: request.generationId,
client_commit: request.clientCommit || null,
external_config: false,
assets: [{
assets: await Promise.all(artifacts.map(async ({ target, path: artifact }) => ({
name: path.basename(artifact),
sha256: await sha256(artifact),
size: (await fsp.stat(artifact)).size,
platform: target.platform,
arch: providerArch(target.arch),
}],
format: target.format || 'portable',
}))),
builder: 'betterdesk-local',
};
await fsp.writeFile(
@@ -67,6 +67,35 @@ describe('clientTemplateWorker embedded artifacts', () => {
)).toBe(selected);
});
test('selects a package asset by target and format', () => {
const selected = path.join(root, 'betterdesk-support-linux-x86_64.deb');
fs.writeFileSync(selected, 'selected');
fs.writeFileSync(path.join(root, 'betterdesk-support-linux-x86_64.tar.gz'), 'portable');
expect(worker._internals.findManifestArtifact(
root,
{
assets: [
{
name: 'betterdesk-support-linux-x86_64.tar.gz',
platform: 'linux',
arch: 'x86_64',
format: 'portable',
},
{
name: 'betterdesk-support-linux-x86_64.deb',
platform: 'linux',
arch: 'x86_64',
format: 'deb',
},
],
},
'linux',
'x64',
'deb',
)).toBe(selected);
});
test('exposes only locally supported target platforms', () => {
expect(worker.getAvailablePlatforms()).toEqual([
{ platform: 'linux', arch: 'x64', format: 'portable', label: 'Linux x64' },