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
3 changes: 2 additions & 1 deletion src/commands/build/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
skip_save: skipSave,
skip_upload,
require_git_data: requireGitData,
delete_old_pins: deleteOldPins,

Check warning on line 22 in src/commands/build/handler.ts

View workflow job for this annotation

GitHub Actions / test (20)

'deleteOldPins' is defined but never used
all_variants: allVariants,
variants_dir_name: variantsDirName = defaultVariantsDirName,
variants,
skip_compose_validation: skipComposeValidation,
strip_compose_version: stripComposeVersion,
arch,
// Global options
dir = defaultDir,
Expand Down Expand Up @@ -65,9 +66,9 @@
skipUpload,
composeFileName,
requireGitData,
deleteOldPins,
variantsDirPath,
skipComposeValidation,
stripComposeVersion,
packagesToBuildProps
};

Expand Down
6 changes: 6 additions & 0 deletions src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export const build: CommandModule<CliGlobalOptions, BuildCommandOptions> = {
description: `Skip the Dappnode compose validation step`,
type: "boolean"
},
strip_compose_version: {
alias: "strip-compose-version",
description: `For testing only: strip the obsolete top-level Compose version`,
type: "boolean",
default: false
},
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;
strip_compose_version?: boolean;
arch?: string;
}

Expand Down
3 changes: 2 additions & 1 deletion src/commands/publish/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
github_release: githubRelease,
dappnode_team_preset: dappnode_team_preset,
require_git_data: requireGitData,
delete_old_pins: deleteOldPins,

Check warning on line 29 in src/commands/publish/handler.ts

View workflow job for this annotation

GitHub Actions / test (20)

'deleteOldPins' is defined but never used
skip_compose_validation: skipComposeValidation,
strip_compose_version: stripComposeVersion,
// Global options
dir = defaultDir,
compose_file_name: composeFileName = defaultComposeFileName,
Expand Down Expand Up @@ -76,12 +77,12 @@
uploadTo,
userTimeout,
requireGitData,
deleteOldPins,
developerAddress,
githubRelease,
verbosityOptions,
variantsDirPath,
skipComposeValidation,
stripComposeVersion,
packagesToBuildProps: getPackagesToBuildProps({
allVariants: Boolean(allVariants),
commaSeparatedVariants: variants,
Expand Down
6 changes: 6 additions & 0 deletions src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export const publish: CommandModule<CliGlobalOptions, PublishCommandOptions> = {
alias: "skip-compose-validation",
description: `Skip the Dappnode compose validation step`,
type: "boolean"
},
strip_compose_version: {
alias: "strip-compose-version",
description: `For testing only: strip the obsolete top-level Compose version`,
type: "boolean",
default: false
}
},

Expand Down
1 change: 1 addition & 0 deletions src/commands/publish/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface PublishCommandOptions extends CliGlobalOptions {
variants?: string;
all_variants?: boolean;
skip_compose_validation?: boolean;
strip_compose_version?: boolean;
}
1 change: 1 addition & 0 deletions src/files/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export { getComposePackageImages } from "./getComposePackageImages.js";
export { getComposePath } from "./getComposePath.js";
export { parseComposeUpstreamVersion } from "./parseComposeUpstreamVersion.js";
export { readCompose } from "./readCompose.js";
export { stripComposeVersion } from "./stripComposeVersion.js";
export { updateComposeImageTags } from "./updateComposeImageTags.js";
export { writeCompose } from "./writeCompose.js";
11 changes: 11 additions & 0 deletions src/files/compose/stripComposeVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Compose } from "@dappnode/types";

/**
* Remove the obsolete top-level version from a parsed Compose object.
*
* Compose still declares version as required in @dappnode/types, so use
* Reflect.deleteProperty until that shared type makes the property optional.
*/
export function stripComposeVersion(compose: Compose): void {
Reflect.deleteProperty(compose, "version");
}
30 changes: 22 additions & 8 deletions src/tasks/buildAndUpload/getFileValidationTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,64 @@
import {
validateComposeSchema,
validateManifestSchema,
validateSetupWizardSchema,

Check warning on line 6 in src/tasks/buildAndUpload/getFileValidationTask.ts

View workflow job for this annotation

GitHub Actions / test (20)

'validateSetupWizardSchema' is defined but never used
validateDappnodeCompose,
validateNotificationsSchema
} from "@dappnode/schemas";
import { getComposePath } from "../../files/index.js";
import {
getComposePath,
stripComposeVersion as removeComposeVersion
} from "../../files/index.js";
import { CliError } from "../../params.js";

export function getFileValidationTask({
packagesToBuildProps,
skipComposeValidation
skipComposeValidation,
stripComposeVersion
}: {
packagesToBuildProps: PackageToBuildProps[];
skipComposeValidation?: boolean;
stripComposeVersion?: boolean;
}): ListrTask<ListrContextBuild> {
return {
title: `Validate files`,
task: async () =>
await validatePackageFiles({
packagesToBuildProps,
skipComposeValidation
skipComposeValidation,
stripComposeVersion
})
};
}

async function validatePackageFiles({
packagesToBuildProps,
skipComposeValidation
skipComposeValidation,
stripComposeVersion
}: {
packagesToBuildProps: PackageToBuildProps[];
skipComposeValidation?: boolean;
stripComposeVersion?: boolean;
}): Promise<void> {
for (const pkgProps of packagesToBuildProps)
await validateVariantFiles(pkgProps, skipComposeValidation);
await validateVariantFiles(
pkgProps,
skipComposeValidation,
stripComposeVersion
);
}

async function validateVariantFiles(
pkgProps: PackageToBuildProps,
skipComposeValidation?: boolean
skipComposeValidation?: boolean,
stripComposeVersion?: boolean
): Promise<void> {
const {
manifest,
compose,
composePaths,
notifications,
setupWizard

Check warning on line 63 in src/tasks/buildAndUpload/getFileValidationTask.ts

View workflow job for this annotation

GitHub Actions / test (20)

'setupWizard' is assigned a value but never used
} = pkgProps;

console.log(
Expand Down Expand Up @@ -75,8 +88,9 @@
// Validate notifications schema
if (notifications) validateNotificationsSchema(notifications);

// Validate setup wizard schema
if (setupWizard) validateSetupWizardSchema(setupWizard);
// Keep version available for the Dappnode validation above. Stripping is
// opt-in while support for versionless Compose files is being tested.
if (stripComposeVersion) removeComposeVersion(compose);
}

function validatePackageName(name: string): void {
Expand Down
10 changes: 7 additions & 3 deletions src/tasks/buildAndUpload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ export function buildAndUpload({
dir,
variantsDirPath = defaultVariantsDirName,
packagesToBuildProps,
skipComposeValidation
skipComposeValidation,
stripComposeVersion
}: BuildAndUploadOptions): ListrTask<ListrContextBuild>[] {
const buildTimeout = parseTimeout(userTimeout);

// Release upload. Use function for return syntax
const releaseUploaderProvider = cliArgsToReleaseUploaderProvider({
uploadTo,
contentProvider
});
const releaseUploader = getReleaseUploader(releaseUploaderProvider);

return [
getFileValidationTask({ packagesToBuildProps, skipComposeValidation }),
getFileValidationTask({
packagesToBuildProps,
skipComposeValidation,
stripComposeVersion
}),
getVerifyConnectionTask({ releaseUploader, skipUpload }),
getReleaseDirCreationTask({ packagesToBuildProps }),
getFileCopyTask({
Expand Down
1 change: 1 addition & 0 deletions src/tasks/buildAndUpload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface BuildAndUploadOptions {
variantsDirPath?: string;
packagesToBuildProps: PackageToBuildProps[];
skipComposeValidation?: boolean;
stripComposeVersion?: boolean;
}
6 changes: 4 additions & 2 deletions src/tasks/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function publish({
variantsDirPath,
packagesToBuildProps,
isMultiVariant,
skipComposeValidation
skipComposeValidation,
stripComposeVersion
}: PublishOptions): ListrTask<ListrContextPublish>[] {
return [
getVerifyEthConnectionTask({ ethProvider }),
Expand All @@ -50,7 +51,8 @@ export function publish({
deleteOldPins,
packagesToBuildProps,
variantsDirPath,
skipComposeValidation
skipComposeValidation,
stripComposeVersion
},
verbosityOptions
}),
Expand Down
1 change: 1 addition & 0 deletions src/tasks/publish/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface PublishOptions {
packagesToBuildProps: PackageToBuildProps[];
isMultiVariant: boolean;
skipComposeValidation?: boolean;
stripComposeVersion?: boolean;
}
27 changes: 27 additions & 0 deletions test/commands/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
defaultVariantsEnvValues
} from "../../src/params.js";
import { normalizeIpfsProvider } from "../../src/releaseUploader/ipfsNode/ipfsProvider.js";
import { readCompose } from "../../src/files/index.js";

const contentProvider = normalizeIpfsProvider("remote");

Expand Down Expand Up @@ -51,6 +52,32 @@ describe("Init and build simple package", function () {
// Check returned hash is correct
expect(releaseHashes[0]).to.include("/ipfs/Qm");
});

it("Should only strip the Compose version when explicitly enabled", async () => {
const defaultBuild = await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
skip_save: true,
skip_upload: true
});
const [{ releaseDir }] = Object.values(defaultBuild);

expect(readCompose([{ dir: releaseDir }]).version).to.equal("3.5");

await buildHandler({
dir: testDir,
provider: contentProvider,
upload_to: "ipfs",
timeout: "5min",
skip_save: true,
skip_upload: true,
strip_compose_version: true
});

expect(readCompose([{ dir: releaseDir }]).version).to.be.undefined;
});
});

describe("Init and build package variants", function () {
Expand Down
22 changes: 22 additions & 0 deletions test/files/compose/stripComposeVersion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from "chai";
import { Compose } from "@dappnode/types";
import { stripComposeVersion } from "../../../src/files/index.js";

describe("files / compose / stripComposeVersion", () => {
it("Should strip the obsolete top-level version", () => {
const compose: Compose = {
version: "3.5",
services: {
service: { image: "service:1.0.0" }
}
};

stripComposeVersion(compose);

expect(compose).to.deep.equal({
services: {
service: { image: "service:1.0.0" }
}
});
});
});
Loading