Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions src/commands/build/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Listr from "listr";
import { Architecture, architectures } from "@dappnode/types";
import { buildAndUpload } from "../../tasks/buildAndUpload/index.js";
import { ListrContextBuild } from "../../types.js";
import {
Expand All @@ -23,6 +24,7 @@ export async function buildHandler({
variants_dir_name: variantsDirName = defaultVariantsDirName,
variants,
skip_compose_validation: skipComposeValidation,
arch,
// Global options
dir = defaultDir,
compose_file_name: composeFileName = defaultComposeFileName,
Expand All @@ -33,6 +35,27 @@ export async function buildHandler({

const variantsDirPath = path.join(dir, variantsDirName);

const architecture = arch ? normalizeArchitecture(arch) : undefined;

const packagesToBuildProps = getPackagesToBuildProps({
allVariants: Boolean(allVariants),
commaSeparatedVariants: variants,
rootDir: dir,
variantsDirPath,
composeFileName
});

// Filter architectures if --arch flag is provided
if (architecture) {
for (const pkg of packagesToBuildProps) {
if (!pkg.architectures.includes(architecture))
throw Error(
`Architecture '${architecture}' is not supported by package ${pkg.manifest.name}. Supported: ${pkg.architectures.join(", ")}`
);
pkg.architectures = [architecture];
}
}

const buildOptions: BuildAndUploadOptions = {
dir,
contentProvider,
Expand All @@ -45,13 +68,7 @@ export async function buildHandler({
deleteOldPins,
variantsDirPath,
skipComposeValidation,
packagesToBuildProps: getPackagesToBuildProps({
allVariants: Boolean(allVariants),
commaSeparatedVariants: variants,
rootDir: dir,
variantsDirPath,
composeFileName
})
packagesToBuildProps
};

const verbosityOptions: VerbosityOptions = {
Expand All @@ -62,3 +79,21 @@ export async function buildHandler({

return await buildTasks.run();
}

const archShorthands: Record<string, Architecture> = {
amd64: "linux/amd64",
x86_64: "linux/amd64",
x64: "linux/amd64",
arm64: "linux/arm64",
aarch64: "linux/arm64",
arm: "linux/arm64"
};

export function normalizeArchitecture(arch: string): Architecture {
const normalized = archShorthands[arch] ?? arch;
if (!architectures.includes(normalized as Architecture))
throw Error(
`Invalid architecture '${arch}', allowed values: ${architectures.join(", ")} (or shorthands: ${Object.keys(archShorthands).join(", ")})`
);
return normalized as Architecture;
}
4 changes: 4 additions & 0 deletions src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const build: CommandModule<CliGlobalOptions, BuildCommandOptions> = {
alias: "skip-compose-validation",
description: `Skip the Dappnode compose validation step`,
type: "boolean"
},
arch: {
description: `Specify the architecture to build for: "linux/amd64" or "linux/arm64"`,
type: "string"
}
},

Expand Down
1 change: 1 addition & 0 deletions src/commands/build/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface BuildCommandOptions extends CliGlobalOptions {
variants?: string;
all_variants?: boolean;
skip_compose_validation?: boolean;
arch?: string;
}

export interface VerbosityOptions {
Expand Down
Loading