Skip to content

Commit

Permalink
Improve upstream repo schema (#1932)
Browse files Browse the repository at this point in the history
* Improve upstream repo schema

* Add upstream field to types

* Set upstream fields as arrays

* Add tests to upstream settings
  • Loading branch information
dappnodedev authored Apr 18, 2024
1 parent 0ec95d4 commit 92801c2
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 18 deletions.
7 changes: 3 additions & 4 deletions packages/daemons/src/autoUpdates/formatNotificationBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function formatPackageUpdateNotification({
dnpName: string;
currentVersion: string;
newVersion: string;
upstreamVersion?: string;
upstreamVersion?: string | string[];
autoUpdatesEnabled: boolean;
}): string {
const prettyName = prettyDnpName(dnpName);
Expand All @@ -25,7 +25,7 @@ export function formatPackageUpdateNotification({
`New version ready to install for ${prettyName} (current version ${currentVersion})`,
upstreamVersion
? ` - package version: ${newVersion}\n` +
` - upstream version: ${upstreamVersion}`
` - upstream version: ${upstreamVersion}`
: ` - version: ${newVersion}`,

`Connect to your DAppNode to install this new version [install / ${prettyName}](${installUrl}).`,
Expand All @@ -46,8 +46,7 @@ export function formatSystemUpdateNotification({
"New system version ready to install",
packages.map(
(p) =>
` - ${prettyDnpName(p.name)}: ${p.to} ${
p.from ? `(current: ${p.from})` : ""
` - ${prettyDnpName(p.name)}: ${p.to} ${p.from ? `(current: ${p.from})` : ""
}`
),

Expand Down
46 changes: 46 additions & 0 deletions packages/schemas/src/schemas/manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
"title": "DAppNode Package (DNP) manifest",
"required": ["name", "version", "description", "type", "license"],
"description": "The DAppNode Package manifest defines all the necessary information for a DAppNode to understand this package:\n - IPFS of BZZ hashes to download its docker image \n - Docker related data to configure and run its container \n - Metadata to control how the package is shown in the admin UI.",
"dependencies": {
"upstream": {
"not": {
"required": ["upstreamRepo", "upstreamVersion", "upstreamArg"]
}
},
"upstreamRepo": {
"not": {
"required": ["upstream"]
}
},
"upstreamVersion": {
"not": {
"required": ["upstream"]
}
},
"upstreamArg": {
"not": {
"required": ["upstream"]
}
}
},
"properties": {
"name": {
"type": "string",
Expand Down Expand Up @@ -71,6 +93,30 @@
}
]
},
"upstream": {
"type": "array",
"items": {
"type": "object",
"required": ["repo", "version", "arg"],
"properties": {
"repo": {
"type": "string",
"description": "Repository of the upstream software.",
"examples": ["ethereum/go-ethereum", "NethermindEth/nethermind"]
},
"version": {
"type": "string",
"description": "Version of the upstream software.",
"examples": ["2.6.0", "v1.2.1"]
},
"arg": {
"type": "string",
"description": "Environment variable name for specifying the version.",
"examples": ["GETH_VERSION", "NETHERMIND_VERSION"]
}
}
}
},
"shortDescription": {
"type": "string",
"description": "Short DAppNode Package description, 6-8 words sentence briefly describing the purpose of this DAppNode Package. The purpose is to quickly grab users' attention and clearly define its purpose. Markdown is discouraged as it will NOT be rendered on the DAppNode Package store view.",
Expand Down
84 changes: 84 additions & 0 deletions packages/schemas/test/unit/validateSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,89 @@ volumes:

expect(() => validateSetupWizardSchema(invalidSetupWizard)).to.throw();
});

it("should allow a manifest with upstream settings defined as an array of objects", () => {
const manifest: Manifest = {
name: "example.dnp.dappnode.eth",
version: "1.0.0",
description: "A sample DAppNode package",
type: "service",
license: "MIT",
upstream: [
{
repo: "ethereum/go-ethereum",
version: "1.9.24",
arg: "GETH_VERSION"
}
]
};

expect(() => validateManifestSchema(manifest)).to.not.throw();
});

it("should allow a manifest with the upstream settings defined as separate strings", () => {
const manifest: Manifest = {
name: "example.dnp.dappnode.eth",
version: "1.0.0",
description: "A sample DAppNode package",
type: "service",
license: "MIT",
upstreamRepo: "ethereum/go-ethereum",
upstreamVersion: "1.9.24",
upstreamArg: "GETH_VERSION"
};

expect(() => validateManifestSchema(manifest)).to.not.throw();
});

it("should allow a manifest with the upstream settings defined as separate arrays", () => {
const manifest: Manifest = {
name: "example.dnp.dappnode.eth",
version: "1.0.0",
description: "A sample DAppNode package",
type: "service",
license: "MIT",
upstreamRepo: ["ethereum/go-ethereum", "NethermindEth/nethermind"],
upstreamVersion: ["1.9.24", "1.10.0"],
upstreamArg: ["GETH_VERSION", "NETHERMIND_VERSION"]
};

expect(() => validateManifestSchema(manifest)).to.not.throw();
});

it("should not allow a manifest with upstream settings defined in both possible ways", () => {
const manifest: Manifest = { // Using 'any' to bypass TypeScript checks for invalid schema
name: "example.dnp.dappnode.eth",
version: "1.0.0",
description: "A sample DAppNode package",
type: "service",
license: "MIT",
upstream: [
{
repo: "ethereum/go-ethereum",
version: "1.9.24",
arg: "GETH_VERSION"
}
],
upstreamRepo: "ethereum/go-ethereum",
upstreamVersion: "1.9.24",
upstreamArg: "GETH_VERSION"
};

expect(() => validateManifestSchema(manifest)).to.throw();
});

it("should allow a manifest without any upstream definitions", () => {
const manifest: Manifest = {
name: "example.dnp.dappnode.eth",
version: "1.0.0",
description: "A sample DAppNode package",
type: "service",
license: "MIT"
};

expect(() => validateManifestSchema(manifest)).to.not.throw();
});

});
});
8 changes: 4 additions & 4 deletions packages/types/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export type InstalledPackageData = Pick<

export interface UpdateAvailable {
newVersion: string;
upstreamVersion?: string;
upstreamVersion?: string | string[];
}

export interface InstalledPackageDetailData extends InstalledPackageData {
Expand Down Expand Up @@ -1034,9 +1034,9 @@ export type EthClientSyncedNotificationStatus = {

export type Eth2ClientTarget =
| {
execClient: ExecutionClientMainnet;
consClient: ConsensusClientMainnet;
}
execClient: ExecutionClientMainnet;
consClient: ConsensusClientMainnet;
}
| "remote";

/**
Expand Down
25 changes: 15 additions & 10 deletions packages/types/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ export interface Manifest {
// Package metadata
name: string;
version: string;
upstreamVersion?: string;
upstreamRepo?: string;
upstreamArg?: string;
upstreamVersion?: string | string[];
upstreamRepo?: string | string[];
upstreamArg?: string | string[];
upstream?: {
repo: string;
version: string;
arg: string;
}[];
shortDescription?: string;
description?: string;
author?: string;
Expand Down Expand Up @@ -49,13 +54,13 @@ export interface Manifest {
minimumDockerVersion?: string;
};
globalEnvs?:
| {
all?: boolean;
}
| {
envs: string[];
services: string[];
}[];
| {
all?: boolean;
}
| {
envs: string[];
services: string[];
}[];
architectures?: Architecture[];

// Safety properties to solve problematic updates
Expand Down

0 comments on commit 92801c2

Please sign in to comment.